diff options
| author | chai <215380520@qq.com> | 2024-05-19 16:46:27 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-19 16:46:27 +0800 |
| commit | 8b1fc7063b387542803c6bc214ccf8acb32870bd (patch) | |
| tree | d310eb99872c8215f1c1f67731ec21f0915cd778 /Thronefall_1_0/GameCode/TreasuryUI.cs | |
| parent | 8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (diff) | |
* rename
Diffstat (limited to 'Thronefall_1_0/GameCode/TreasuryUI.cs')
| -rw-r--r-- | Thronefall_1_0/GameCode/TreasuryUI.cs | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/Thronefall_1_0/GameCode/TreasuryUI.cs b/Thronefall_1_0/GameCode/TreasuryUI.cs deleted file mode 100644 index e86b87d..0000000 --- a/Thronefall_1_0/GameCode/TreasuryUI.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System.Collections.Generic; -using TMPro; -using UnityEngine; - -public class TreasuryUI : MonoBehaviour, DayNightCycle.IDaytimeSensitive -{ - public enum AnimationState - { - Off, - ScaleIn, - On, - ScaleOut, - WaitToScaleOut - } - - public Transform coinsParent; - - public GameObject renderCamera; - - public GameObject coinPrefab; - - public Transform spawn; - - public float removalInterval; - - public float addInterval = 0.35f; - - public float activationLifetime = 1f; - - public AnimationCurve scaleCurve; - - public float scaleAnimationSpeed; - - private Transform scaleTarget; - - public float waitTimeBeforeScaleOut = 0.3f; - - private TextMeshProUGUI displayText; - - public Animator treasureChestAnimator; - - private List<GameObject> instantiatedCoins = new List<GameObject>(); - - private PlayerInteraction targetPlayer; - - private int coinQeue; - - private float addCounter; - - private float removalCounter; - - private float activationCounter; - - private bool overrideActivation; - - private AnimationState currentState; - - private float scaleAnimationProgress; - - private float scaleOutWaitClock; - - private bool shouldBeActive - { - get - { - if (!(activationCounter > 0f)) - { - return overrideActivation; - } - return true; - } - } - - private void Start() - { - DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this); - scaleTarget = UIFrameManager.instance.TreasureChest.scaleTarget; - displayText = UIFrameManager.instance.TreasureChest.balanceNumber; - targetPlayer = TagManager.instance.Players[0].GetComponent<PlayerInteraction>(); - targetPlayer.onBalanceGain.AddListener(AddCoins); - targetPlayer.onBalanceSpend.AddListener(RemoveCoins); - targetPlayer.onFocusPaymentInteraction.AddListener(LockActivation); - targetPlayer.onUnfocusPaymentInteraction.AddListener(UnlockActivation); - AddCoins(targetPlayer.Balance); - SetState(currentState); - } - - private void SetState(AnimationState newState) - { - switch (newState) - { - case AnimationState.Off: - scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(0f); - scaleAnimationProgress = 0f; - break; - case AnimationState.On: - scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(1f); - scaleAnimationProgress = 1f; - treasureChestAnimator.SetBool("Open", value: true); - break; - case AnimationState.WaitToScaleOut: - treasureChestAnimator.SetBool("Open", value: false); - scaleOutWaitClock = 0f; - break; - } - currentState = newState; - } - - private void Update() - { - if (addCounter > 0f) - { - addCounter -= Time.deltaTime; - } - if (removalCounter > 0f) - { - removalCounter -= Time.deltaTime; - } - if (activationCounter > 0f) - { - activationCounter -= Time.deltaTime; - } - if (coinQeue > 0 && addCounter <= 0f) - { - GameObject item = Object.Instantiate(coinPrefab, spawn.position, Random.rotation, coinsParent); - instantiatedCoins.Add(item); - coinQeue--; - addCounter = addInterval; - activationCounter = activationLifetime; - } - if (coinQeue < 0 && addCounter <= 0f) - { - GameObject obj = instantiatedCoins[instantiatedCoins.Count - 1]; - instantiatedCoins.RemoveAt(instantiatedCoins.Count - 1); - Object.Destroy(obj); - coinQeue++; - removalCounter = removalInterval; - activationCounter = activationLifetime; - } - switch (currentState) - { - case AnimationState.Off: - if (shouldBeActive) - { - SetState(AnimationState.ScaleIn); - } - break; - case AnimationState.On: - if (!shouldBeActive) - { - SetState(AnimationState.WaitToScaleOut); - } - break; - case AnimationState.WaitToScaleOut: - scaleOutWaitClock += Time.deltaTime; - if (scaleOutWaitClock >= waitTimeBeforeScaleOut) - { - SetState(AnimationState.ScaleOut); - } - break; - case AnimationState.ScaleOut: - scaleAnimationProgress -= Time.deltaTime * scaleAnimationSpeed; - scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(scaleAnimationProgress); - if (scaleAnimationProgress <= 0f) - { - SetState(AnimationState.Off); - } - else if (shouldBeActive) - { - SetState(AnimationState.ScaleIn); - } - break; - case AnimationState.ScaleIn: - scaleAnimationProgress += Time.deltaTime * scaleAnimationSpeed; - scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(scaleAnimationProgress); - if (scaleAnimationProgress >= 1f) - { - SetState(AnimationState.On); - } - else if (!shouldBeActive) - { - SetState(AnimationState.ScaleIn); - } - break; - } - } - - private void AddCoins(int amount) - { - coinQeue += amount; - displayText.text = "<sprite name=\"coin\">" + targetPlayer.Balance; - } - - private void RemoveCoins(int amount) - { - coinQeue -= amount; - displayText.text = "<sprite name=\"coin\">" + targetPlayer.Balance; - } - - private void LockActivation() - { - overrideActivation = true; - } - - private void UnlockActivation() - { - overrideActivation = false; - activationCounter = activationLifetime; - } - - public void OnDusk() - { - renderCamera.SetActive(value: false); - } - - public void OnDawn_AfterSunrise() - { - } - - public void OnDawn_BeforeSunrise() - { - renderCamera.SetActive(value: true); - } -} |
