166 lines
3.9 KiB
C#
166 lines
3.9 KiB
C#
using RootMotion.FinalIK;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishNetItem : MonoBehaviour
|
|
{
|
|
public int indexOfList;
|
|
|
|
[HideInInspector]
|
|
public int uid;
|
|
|
|
public Text numberText;
|
|
|
|
public Image fishIconImage;
|
|
|
|
public Text fishNameText;
|
|
|
|
public Text fishWeightText;
|
|
|
|
public Text fishPriceText;
|
|
|
|
public FishNetStars fishNetStars;
|
|
|
|
public Button addAquariumButton;
|
|
|
|
public Button addTrophyButton;
|
|
|
|
public Transform canvasTransform;
|
|
|
|
[HideInInspector]
|
|
public GameManager.FishSpecies fishSpecies;
|
|
|
|
[HideInInspector]
|
|
public float fishWeight;
|
|
|
|
public float price;
|
|
|
|
public Sprite[] backgrounds;
|
|
|
|
private void Start()
|
|
{
|
|
fishNetStars.SetStarsByFishWeight(fishSpecies, fishWeight);
|
|
fishIconImage.sprite = GameManager.Instance.gameFish[(int)fishSpecies].GetFishIcon(fishWeight);
|
|
fishNameText.text = GameManager.Instance.gameFish[(int)fishSpecies].GetFishName();
|
|
fishWeightText.text = GameManager.Instance.ConvertWeight(fishWeight) + " / " + GameManager.Instance.ConvertWeightFishToLengthWithUnit(fishSpecies, fishWeight);
|
|
fishPriceText.text = "$ " + price;
|
|
SetBackground();
|
|
ValidateAddsOptions();
|
|
}
|
|
|
|
public void Show3D()
|
|
{
|
|
if (!GameManager.Instance.currentItemsViewer)
|
|
{
|
|
GameObject fishModel = GameManager.Instance.gameFish[(int)fishSpecies].GetFishModel(fishWeight);
|
|
fishModel.GetComponent<FFish>().enabled = false;
|
|
fishModel.GetComponent<FFishRagDoll>().enabled = false;
|
|
fishModel.GetComponent<Rigidbody>().isKinematic = true;
|
|
fishModel.GetComponent<CCDIK>().enabled = false;
|
|
fishModel.transform.localScale = Vector3.one * 0.2f;
|
|
string fishName = GameManager.Instance.gameFish[(int)fishSpecies].GetFishName();
|
|
GameManager.Instance.ShowItemViewer(fishModel, canvasTransform, fishName);
|
|
}
|
|
}
|
|
|
|
public void SellFish()
|
|
{
|
|
GameManager.Instance._playerData.AddSubPlayerCashValue(price);
|
|
DestroyFishItem();
|
|
}
|
|
|
|
public void SellFishNoSound()
|
|
{
|
|
GameManager.Instance._playerData.AddSubPlayerCashValue(price);
|
|
DestroyFishItem();
|
|
}
|
|
|
|
public void ReleaseFish()
|
|
{
|
|
DestroyFishItem();
|
|
}
|
|
|
|
public void AddToTrophy()
|
|
{
|
|
if (GameManager.Instance._playerData.AddFishToTrophy(fishSpecies, fishWeight))
|
|
{
|
|
DestroyFishItem();
|
|
}
|
|
}
|
|
|
|
public void AddToAquarium()
|
|
{
|
|
if (GameManager.Instance._playerData.AddFishToAquarium(fishSpecies, fishWeight))
|
|
{
|
|
DestroyFishItem();
|
|
}
|
|
}
|
|
|
|
public void ValidateAddsOptions()
|
|
{
|
|
if (GameManager.Instance._playerData.CheckFreeSpacesInAquariumAndGetIndex(fishWeight) == -1)
|
|
{
|
|
addAquariumButton.interactable = false;
|
|
addAquariumButton.GetComponent<Hover>().enabled = false;
|
|
}
|
|
else
|
|
{
|
|
addAquariumButton.interactable = true;
|
|
}
|
|
if (GameManager.Instance._playerData.CheckTrophyAndGetIndex(fishSpecies, fishWeight) == -2)
|
|
{
|
|
addTrophyButton.interactable = false;
|
|
addTrophyButton.GetComponent<Hover>().enabled = false;
|
|
}
|
|
else
|
|
{
|
|
addTrophyButton.interactable = true;
|
|
}
|
|
}
|
|
|
|
public void SetBackground()
|
|
{
|
|
int num = indexOfList;
|
|
numberText.text = (1 + num).ToString();
|
|
if (num % 2 == 0)
|
|
{
|
|
GetComponent<Image>().sprite = backgrounds[0];
|
|
}
|
|
else
|
|
{
|
|
GetComponent<Image>().sprite = backgrounds[1];
|
|
}
|
|
}
|
|
|
|
private void DestroyFishItem()
|
|
{
|
|
for (int i = 0; i < Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerFishNet.Count; i++)
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerFishNet[i].uid == uid)
|
|
{
|
|
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerFishNet.RemoveAt(i);
|
|
GetComponent<Animator>().SetTrigger("Destroy");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PlayOnClickSound()
|
|
{
|
|
GameManager.Instance.PlayOnClickSound();
|
|
}
|
|
|
|
public void DestroyEvent()
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
Object.FindObjectOfType<FishNetView>().BuildFishList();
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerFishNet.Count == 0)
|
|
{
|
|
Home home = Object.FindObjectOfType<Home>();
|
|
if ((bool)home)
|
|
{
|
|
home.ShowContent(1);
|
|
}
|
|
}
|
|
}
|
|
}
|