NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/FunctionLock/FunctionLock.cs

102 lines
2.6 KiB
C#
Raw Normal View History

2025-04-10 13:36:39 +08:00
using cfg.FunctionLockCfg;
2025-04-10 15:19:01 +08:00
using Cysharp.Threading.Tasks;
2025-04-10 13:36:39 +08:00
using dnlib.DotNet.MD;
using Framework;
using System.Collections;
using System.Collections.Generic;
2025-04-10 15:19:01 +08:00
using TMPro;
2025-04-10 13:36:39 +08:00
using UnityEngine;
using UnityEngine.UI;
namespace Gameplay.FunctionLock
{
public sealed class FunctionLock : MonoBehaviour
{
2025-04-10 15:19:01 +08:00
/// <summary>
/// 动画时长
/// </summary>
private const float ANIM_TIME = 1.4f;
2025-04-10 13:36:39 +08:00
/// <summary>
/// 功能锁id
/// </summary>
public int FunctionLockId;
2025-04-10 15:19:01 +08:00
/// <summary>
/// 功能按钮
/// </summary>
public Button ButtonFunction;
2025-04-10 13:36:39 +08:00
/// <summary>
/// 功能锁根节点
/// </summary>
2025-04-10 15:19:01 +08:00
private GameObject Root;
2025-04-10 13:36:39 +08:00
/// <summary>
2025-04-10 15:19:01 +08:00
/// 解锁动画
2025-04-10 13:36:39 +08:00
/// </summary>
2025-04-10 15:19:01 +08:00
private Animator animator;
/// <summary>
/// 解锁描述
/// </summary>
private TMP_Text textContent;
/// <summary>
/// 解锁配置
/// </summary>
private DataFunctionLock cfg;
private void Awake()
{
Root = gameObject;
animator = Root.transform.Find("Lock").GetComponent<Animator>();
textContent = Root.transform.Find("Lock/TextContent")?.GetComponent<TMP_Text>();
}
2025-04-10 13:36:39 +08:00
private void Start()
{
2025-04-10 15:19:01 +08:00
cfg = TableManager.Instance.Tables.FunctionLockConfig.Get(FunctionLockId);
2025-04-10 13:36:39 +08:00
if (null == cfg)
{
DebugUtil.LogError($"功能锁配置获取错误id{FunctionLockId}");
return;
}
2025-04-10 15:19:01 +08:00
SetState(false); // 设置状态
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.E))
PlayUnlockAnim();
2025-04-10 13:36:39 +08:00
}
/// <summary>
/// 播放解锁动画
/// </summary>
2025-04-10 15:19:01 +08:00
public async void PlayUnlockAnim()
2025-04-10 13:36:39 +08:00
{
2025-04-10 15:19:01 +08:00
animator.SetTrigger("Unlock");
//FunctionLockManager.Instance.SaveServer(cfg.ServerFlag);
await UniTask.WaitForSeconds(ANIM_TIME);
SetState(true);
2025-04-10 13:36:39 +08:00
}
/// <summary>
/// 设置状态
/// </summary>
/// <param name="isUnlock"></param>
private void SetState(bool isUnlock)
{
2025-04-10 15:19:01 +08:00
if (isUnlock)//FunctionLockManager.Instance.IsUnlock(cfg.ServerFlag))
2025-04-10 13:36:39 +08:00
{
Root.IsScaleShow(false);
ButtonFunction.interactable = true;
}
else
{
2025-04-10 15:19:01 +08:00
textContent.text = cfg.Desc;
2025-04-10 13:36:39 +08:00
Root.IsScaleShow(true);
ButtonFunction.interactable = false;
}
}
}
}