using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class FairyTreasureCollect : MonoBehaviour { protected int treasureId = 0; [SerializeField] protected Text m_TreasureStory; [SerializeField] protected Button m_GotoGet; [SerializeField] protected Text m_GotoBtnText; [SerializeField] protected RectTransform m_ContainerFight; [SerializeField] protected Text m_FightPower; [SerializeField] protected RectTransform m_ContainerLocked; [SerializeField] protected Text m_LockedDescription; [SerializeField] protected PositionTween m_StoryTween; protected TreasureEffectModel treasureEffect { get { return ModelCenter.Instance.GetModel(); } } protected TreasureModel model { get { return ModelCenter.Instance.GetModel(); } } protected Treasure treasure; protected virtual void Awake() { } protected virtual void GotoGet() { } public virtual void Display(int _treasureId, bool _tween = false) { treasureId = _treasureId; m_GotoGet.onClick.RemoveAllListeners(); m_GotoGet.onClick.AddListener(GotoGet); if (!model.TryGetTreasure(_treasureId, out treasure)) { return; } if (_tween && m_StoryTween.gameObject.activeInHierarchy) { m_StoryTween.Play(); } else { m_StoryTween.SetEndState(); } m_GotoGet.gameObject.SetActive(treasure.state == TreasureState.Locked); m_ContainerFight.gameObject.SetActive(treasure.state == TreasureState.Collected); m_ContainerLocked.gameObject.SetActive(treasure.state == TreasureState.Locked); var config = Config.Instance.Get(_treasureId); m_TreasureStory.text = config.Story; model.treasureStateChangeEvent += OnTreasureStateChange; } protected virtual void OnTreasureStateChange(int _id) { if (_id != treasureId) { return; } m_GotoGet.gameObject.SetActive(treasure.state == TreasureState.Locked); m_ContainerFight.gameObject.SetActive(treasure.state == TreasureState.Collected); m_ContainerLocked.gameObject.SetActive(treasure.state == TreasureState.Locked); } public virtual void Dispose() { m_GotoGet.onClick.RemoveAllListeners(); model.treasureStateChangeEvent -= OnTreasureStateChange; } } }