add project files
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit.Pooling;
|
||||
using OHM.UnityToolkit.UI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class UICoreGame : UIMenu
|
||||
{
|
||||
[SerializeField]
|
||||
private UIIncrementableCounter level;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("score")]
|
||||
private UIIncrementableCounter _score;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("poppingStatusPrefab")]
|
||||
private SizePrefabUI _poppingStatusPrefab;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("poppingGainPrefab")]
|
||||
private UIIncrementableCounter _poppingGainPrefab;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("poppingLosePrefab")]
|
||||
private UIIncrementableCounter _poppingLosePrefab;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("reuseSizeUpDelay")]
|
||||
private float _reuseSizeUpDelay;
|
||||
|
||||
[SerializeField]
|
||||
private Transform spawnCont;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("quitConfirmPopup")]
|
||||
private UIConfirmPopup _quitConfirmPopup;
|
||||
|
||||
private SizePrefabUI _sizeTxt;
|
||||
|
||||
private UIIncrementableCounter _poppingSizeUp;
|
||||
|
||||
private float _sizeUpTime;
|
||||
|
||||
private float _sizeUpValue;
|
||||
|
||||
private UIIncrementableCounter _poppingSizeDown;
|
||||
|
||||
private float _sizeDownTime;
|
||||
|
||||
private float _sizeDownValue;
|
||||
|
||||
public override void OnSetup()
|
||||
{
|
||||
appController.coreGame.scoreController.onScore.AddListener(OnScore);
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
CleanUI();
|
||||
level.SetTargetValue(appController.GetPlayerLevel() + 1);
|
||||
_score.Init(appController.coreGame.scoreController.Score);
|
||||
appController.coreGame.CurrentPlayer.richManagePlayer.VisualPlayerRichPoor.onChangeStatus += OnChangeStatus;
|
||||
appController.coreGame.CurrentPlayer.richManagePlayer.onChangeMoney += OnChangeMoney;
|
||||
}
|
||||
|
||||
private void OnScore(int s, Transform obj, ScoreController.ScoreType type)
|
||||
{
|
||||
_score.SetTargetValue(appController.coreGame.scoreController.Score);
|
||||
}
|
||||
|
||||
private void OnChangeStatus(TypeRich typeRich, Color color)
|
||||
{
|
||||
SizePrefabUI popup = UnityEngine.Object.Instantiate(_poppingStatusPrefab, spawnCont);
|
||||
if (popup != null)
|
||||
{
|
||||
popup.SetText(typeRich.locKey, color);
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanUI()
|
||||
{
|
||||
if (_sizeTxt != null)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(_sizeTxt.gameObject);
|
||||
}
|
||||
if (_poppingSizeUp != null)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(_poppingSizeUp.gameObject);
|
||||
}
|
||||
if (_poppingSizeDown != null)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(_poppingSizeDown.gameObject);
|
||||
}
|
||||
foreach (Transform child in spawnCont)
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChangeMoney(float value)
|
||||
{
|
||||
if (value > 0f)
|
||||
{
|
||||
if (Time.time > _sizeUpTime || _poppingSizeUp == null)
|
||||
{
|
||||
_sizeUpValue = 0f;
|
||||
_poppingSizeUp = PoolsManager.InstantiatePrefab(_poppingGainPrefab, spawnCont, spawnCont.position, Quaternion.identity);
|
||||
}
|
||||
_sizeUpValue += value;
|
||||
_poppingSizeUp.SetTargetValue((long)_sizeUpValue);
|
||||
_poppingSizeUp.gameObject.SetActive(value: true);
|
||||
_sizeUpTime = Time.time + _reuseSizeUpDelay;
|
||||
}
|
||||
else if (value < 0f)
|
||||
{
|
||||
if (Time.time > _sizeDownTime || _poppingSizeDown == null)
|
||||
{
|
||||
_sizeDownValue = 0f;
|
||||
_poppingSizeDown = PoolsManager.InstantiatePrefab(_poppingLosePrefab, spawnCont, spawnCont.position, Quaternion.identity);
|
||||
}
|
||||
_sizeDownValue += value;
|
||||
_poppingSizeDown.SetTargetValue((long)System.Math.Abs(_sizeDownValue));
|
||||
_poppingSizeDown.gameObject.SetActive(value: true);
|
||||
_sizeDownTime = Time.time + _reuseSizeUpDelay;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryQuit()
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
_quitConfirmPopup.Show(delegate
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
appController.Quit();
|
||||
}, delegate
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user