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 string ANIM_TRIGGER_NAME = "Unlock"; /// /// 动画时长 /// 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; /// /// 是否正在播放解锁动画 /// public bool IsPlayingAnim { get; private set; } private void Awake() { Root = gameObject; animator = Root.transform.Find("Lock").GetComponent(); textContent = Root.transform.Find("Lock/TextContent")?.GetComponent(); IsPlayingAnim = false; } private void Start() { cfg = TableManager.Instance.Tables.FunctionLockConfig.Get(FunctionLockId); if (null == cfg) { DebugUtil.LogError($"功能锁配置获取错误id;{FunctionLockId}"); return; } SetState(); // 设置状态 } /// /// 播放解锁动画 /// public async void PlayUnlockAnim() { if (IsPlayingAnim) return; if (IsUnlock()) return; IsPlayingAnim = true; animator.SetTrigger(ANIM_TRIGGER_NAME); FunctionLockManager.Instance.SaveServer(cfg.ServerFlag); // 服务器保存解锁状态 await UniTask.WaitForSeconds(ANIM_TIME); SetState(); IsPlayingAnim = false; } /// /// 设置状态 /// /// private void SetState() { if (IsUnlock()) // 已解锁 { Root.IsScaleShow(false); ButtonFunction.interactable = true; } else // 未解锁 { textContent.text = cfg.Desc; Root.IsScaleShow(true); ButtonFunction.interactable = false; } } /// /// 是否解锁 /// /// private bool IsUnlock() { if (null == cfg) return false; return FunctionLockManager.Instance.IsUnlock(cfg.ServerFlag); } } }