using cfg.FunctionLockCfg; using Cysharp.Threading.Tasks; using Framework; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace Gameplay.FunctionLock { public sealed class FunctionLock : MonoBehaviour { /// /// 动画时长 /// private const float ANIM_TIME = 1.4f; /// /// 功能锁id /// public int FunctionLockId; /// /// 功能按钮 /// public Button ButtonFunction; #region UI /// /// 功能锁根节点 /// private GameObject Root; /// /// 解锁动画 /// private Animator animator; /// /// 解锁描述 /// private TMP_Text textContent; #endregion /// /// 解锁配置 /// private DataFunctionLock cfg; private void Awake() { Root = gameObject; animator = Root.transform.Find("Lock").GetComponent(); textContent = Root.transform.Find("Lock/TextContent")?.GetComponent(); } private void Start() { cfg = TableManager.Instance.Tables.FunctionLockConfig.Get(FunctionLockId); if (null == cfg) { DebugUtil.LogError($"功能锁配置获取错误id;{FunctionLockId}"); return; } SetState(); // 设置状态 } /// /// 播放解锁动画 /// public async void PlayUnlockAnim() { animator.SetTrigger("Unlock"); FunctionLockManager.Instance.SaveServer(cfg.ServerFlag); await UniTask.WaitForSeconds(ANIM_TIME); SetState(); } /// /// 设置状态 /// /// private void SetState() { if (FunctionLockManager.Instance.IsUnlock(cfg.ServerFlag)) { Root.IsScaleShow(false); ButtonFunction.interactable = true; } else { textContent.text = cfg.Desc; Root.IsScaleShow(true); ButtonFunction.interactable = false; } } } }