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

102 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using cfg.FunctionLockCfg;
using Cysharp.Threading.Tasks;
using dnlib.DotNet.MD;
using Framework;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Gameplay.FunctionLock
{
public sealed class FunctionLock : MonoBehaviour
{
/// <summary>
/// 动画时长
/// </summary>
private const float ANIM_TIME = 1.4f;
/// <summary>
/// 功能锁id
/// </summary>
public int FunctionLockId;
/// <summary>
/// 功能按钮
/// </summary>
public Button ButtonFunction;
/// <summary>
/// 功能锁根节点
/// </summary>
private GameObject Root;
/// <summary>
/// 解锁动画
/// </summary>
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>();
}
private void Start()
{
cfg = TableManager.Instance.Tables.FunctionLockConfig.Get(FunctionLockId);
if (null == cfg)
{
DebugUtil.LogError($"功能锁配置获取错误id{FunctionLockId}");
return;
}
SetState(false); // 设置状态
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.E))
PlayUnlockAnim();
}
/// <summary>
/// 播放解锁动画
/// </summary>
public async void PlayUnlockAnim()
{
animator.SetTrigger("Unlock");
//FunctionLockManager.Instance.SaveServer(cfg.ServerFlag);
await UniTask.WaitForSeconds(ANIM_TIME);
SetState(true);
}
/// <summary>
/// 设置状态
/// </summary>
/// <param name="isUnlock"></param>
private void SetState(bool isUnlock)
{
if (isUnlock)//FunctionLockManager.Instance.IsUnlock(cfg.ServerFlag))
{
Root.IsScaleShow(false);
ButtonFunction.interactable = true;
}
else
{
textContent.text = cfg.Desc;
Root.IsScaleShow(true);
ButtonFunction.interactable = false;
}
}
}
}