175 lines
4.2 KiB
C#
175 lines
4.2 KiB
C#
using RootMotion.FinalIK;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AquariumFishItem : MonoBehaviour
|
|
{
|
|
public int aquariumIndex;
|
|
|
|
public int indexOfList;
|
|
|
|
public int uid;
|
|
|
|
public float currentFeed;
|
|
|
|
public long dropTime;
|
|
|
|
public float lifetime;
|
|
|
|
public Text numberText;
|
|
|
|
public Image fishIconImage;
|
|
|
|
public Text fishNameText;
|
|
|
|
public Text fishWeightText;
|
|
|
|
public Text fishGrowthWeightText;
|
|
|
|
public Transform canvasTransform;
|
|
|
|
public Text fishPriceText;
|
|
|
|
public Button addTrophyButton;
|
|
|
|
public Image warningSignImage;
|
|
|
|
public Image feedImageProgress;
|
|
|
|
public Image lifetimeImageProgress;
|
|
|
|
[HideInInspector]
|
|
public GameManager.FishSpecies fishSpecies;
|
|
|
|
[HideInInspector]
|
|
public float fishWeight;
|
|
|
|
[HideInInspector]
|
|
public float growthWeight;
|
|
|
|
public Sprite[] backgrounds;
|
|
|
|
private PlayerResidence playerResidence;
|
|
|
|
private void Start()
|
|
{
|
|
playerResidence = Object.FindObjectOfType<PlayerResidence>();
|
|
Refresh();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
Mathf.FloorToInt((ServerManager.Instance.serverTime - dropTime) / 3600);
|
|
fishIconImage.sprite = GameManager.Instance.gameFish[(int)fishSpecies].GetFishIcon(fishWeight + growthWeight);
|
|
fishNameText.text = GameManager.Instance.gameFish[(int)fishSpecies].GetFishName();
|
|
fishWeightText.text = GameManager.Instance.ConvertWeight(fishWeight + growthWeight) + " / " + GameManager.Instance.ConvertWeightFishToLengthWithUnit(fishSpecies, fishWeight + growthWeight);
|
|
if (growthWeight > 0.01f)
|
|
{
|
|
fishGrowthWeightText.text = "+ " + GameManager.Instance.ConvertWeight(growthWeight);
|
|
}
|
|
else
|
|
{
|
|
fishGrowthWeightText.enabled = false;
|
|
}
|
|
fishPriceText.text = "$ " + GameManager.Instance.GetFishPrice((int)fishSpecies, fishWeight + growthWeight);
|
|
feedImageProgress.fillAmount = currentFeed;
|
|
lifetimeImageProgress.fillAmount = 1f - lifetime;
|
|
if (feedImageProgress.fillAmount < 0.2f)
|
|
{
|
|
feedImageProgress.color = Color.red;
|
|
warningSignImage.gameObject.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
feedImageProgress.color = Color.white;
|
|
warningSignImage.gameObject.SetActive(value: false);
|
|
}
|
|
if (lifetimeImageProgress.fillAmount < 0.2f)
|
|
{
|
|
lifetimeImageProgress.color = Color.red;
|
|
warningSignImage.gameObject.SetActive(value: true);
|
|
}
|
|
SetBackground();
|
|
ValidateAddsOptions();
|
|
}
|
|
|
|
public void SellFish()
|
|
{
|
|
float fishPrice = GameManager.Instance.GetFishPrice((int)fishSpecies, fishWeight);
|
|
GameManager.Instance._playerData.AddSubPlayerCashValue(fishPrice);
|
|
DestroyFishItem();
|
|
}
|
|
|
|
public void ReleaseFish()
|
|
{
|
|
DestroyFishItem();
|
|
}
|
|
|
|
public void Show3D()
|
|
{
|
|
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 AddToTrophy()
|
|
{
|
|
if (GameManager.Instance._playerData.AddFishToTrophy(fishSpecies, fishWeight))
|
|
{
|
|
DestroyFishItem();
|
|
}
|
|
}
|
|
|
|
public void ValidateAddsOptions()
|
|
{
|
|
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().PlayerAquarium[aquariumIndex].fish.Count; i++)
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerAquarium[aquariumIndex].fish[i].uid == uid)
|
|
{
|
|
GetComponent<Animator>().SetTrigger("Destroy");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DestroyEvent()
|
|
{
|
|
playerResidence.DestroyFishFromCurrentAquarium(uid);
|
|
}
|
|
}
|