191 lines
5.2 KiB
C#
191 lines
5.2 KiB
C#
using System;
|
|
using cfg.ActorCfg;
|
|
using cfg.SkillCfg;
|
|
using Framework;
|
|
using Gameplay.Common;
|
|
using Gameplay.Level;
|
|
using Gameplay.Net;
|
|
using Gameplay.Skill;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UICommandSkillNode: UINode
|
|
{
|
|
public Image Image_CMSkillNormal;
|
|
public Image Image_SkillProgress;
|
|
public ButtonEx Button_CMSkillPress;
|
|
public Image Image_CMSkillReady;
|
|
|
|
private UIWindow _bindWindow;
|
|
|
|
public static bool IsDraggingSkill => _isDraggingSkill;
|
|
private float _curCdProgress;
|
|
private bool _isInCd;
|
|
private int _skillID;
|
|
|
|
private static bool _isDraggingSkill;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
Button_CMSkillPress.AddBeginDrag(OnOutDrag);
|
|
InputManager.Instance.OnFingerUpUI += OnPointUp;
|
|
_isDraggingSkill = false;
|
|
//Button_CMSkillPress.AddPointUpListener(OnPointUp);
|
|
}
|
|
|
|
// private void OnEnable()
|
|
// {
|
|
// InputManager.Instance.OnFingerUpUI += OnPointUp;
|
|
// }
|
|
//
|
|
// private void OnDisable()
|
|
// {
|
|
// InputManager.Instance.OnFingerUpUI -= OnPointUp;
|
|
// }
|
|
|
|
public void OnDestroy()
|
|
{
|
|
if (InputManager.Instance)
|
|
{
|
|
InputManager.Instance.OnFingerUpUI -= OnPointUp;
|
|
}
|
|
|
|
_isDraggingSkill = false;
|
|
}
|
|
|
|
public override void SetData(object data)
|
|
{
|
|
_skillID = (int)data;
|
|
Init();
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
if (LevelManager.Instance.CurrentLevel == null)
|
|
{
|
|
return;
|
|
}
|
|
_curCdProgress = SkillManager.instance.playerSkillManager.GetCDProgress(_skillID);
|
|
if (!_isInCd)
|
|
{
|
|
if (_curCdProgress > 0.001f)
|
|
{
|
|
ChangeState(true);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (_isInCd)
|
|
{
|
|
if (_curCdProgress <= 0.001f)
|
|
{
|
|
ChangeState(false);
|
|
return;
|
|
}
|
|
RefreshNode();
|
|
}
|
|
}
|
|
|
|
public void BindWindow(UIWindow window)
|
|
{
|
|
_bindWindow = window;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
_Init();
|
|
}
|
|
|
|
|
|
private async void _Init()
|
|
{
|
|
if (_skillID == 0)
|
|
{
|
|
return;
|
|
}
|
|
Button_CMSkillPress.gameObject.SetActive(true);
|
|
Image_CMSkillNormal.gameObject.SetActive(false);
|
|
|
|
//int skillLevel = Actor.Instance.PlayerSkill.GetLevel(_skillID);
|
|
// DataPlayerSkillUpgrade PlayerSkillUpgrade = TableManager.Instance.Tables.PlayerSkillUpgrade.Get(_skillID, skillLevel);
|
|
// if (null == PlayerSkillUpgrade)
|
|
// {
|
|
// DebugUtil.LogError($"未获取到id为{_skillID},等级为{skillLevel},的玩家技能养成数据");
|
|
// return;
|
|
// }
|
|
|
|
DataPlayerSkill dataPlayerSkill = TableManager.Instance.Tables.PlayerSkillConfig.Get(_skillID);
|
|
if (dataPlayerSkill == null)
|
|
{
|
|
DebugUtil.LogError($"指挥官技能表ID:{_skillID}不存在!");
|
|
return;
|
|
}
|
|
string iconPath = $"{Framework.Constants.UI_PlaySkill_IconPathFolder}{dataPlayerSkill.IconPath}.png";
|
|
Image_CMSkillNormal.sprite = await LoadAssetAsync<Sprite>(iconPath);
|
|
Button_CMSkillPress.GetComponent<Image>().sprite = await LoadAssetAsync<Sprite>(iconPath);
|
|
}
|
|
|
|
private void RefreshNode()
|
|
{
|
|
var playerSkillData = TableManager.Instance.Tables.PlayerSkillConfig.GetOrDefault(_skillID);
|
|
if (playerSkillData != null)
|
|
{
|
|
var fill = (1 - _curCdProgress) * UI_StartBtn_CMSBtnController.PROGRESS_FULL;
|
|
Image_SkillProgress.fillAmount = fill;
|
|
}
|
|
}
|
|
|
|
private void ChangeState(bool state)
|
|
{
|
|
_isInCd = state;
|
|
Image_CMSkillNormal.gameObject.SetActive(state);
|
|
Button_CMSkillPress.gameObject.SetActive(!state);
|
|
}
|
|
|
|
private void OnOutDrag(PointerEventData eventData)
|
|
{
|
|
try
|
|
{
|
|
//InputManager.Instance.enabled = false;
|
|
CameraController.FingerMoveEnable = false;
|
|
var data = new EDReadyPlayerSkill{playerSkillId = _skillID};
|
|
EventManager.Instance.Send(EventManager.EventName.Guide_PreparaPlayerSkill);
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_PLAYER_SKILL_READYUSE, data);
|
|
var window = (UI_StartBtn_CMSBtnController)_bindWindow;
|
|
if (!TeamManager.IsHideAllUI)
|
|
{
|
|
TeamManager.IsHideAllUI = true;
|
|
}
|
|
|
|
_isDraggingSkill = true;
|
|
TeamManager.Instance.OpenFightPosterUI();
|
|
window.OnOutDragNode();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
DebugUtil.LogError(e);
|
|
//InputManager.Instance.enabled = true;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private void OnPointUp(Vector2 pos)
|
|
{
|
|
if (_isDraggingSkill)
|
|
{
|
|
CameraController.FingerMoveEnable = true;
|
|
var window = (UI_StartBtn_CMSBtnController)_bindWindow;
|
|
TeamManager.Instance.CloseFightPosterUI();
|
|
if (window != null)
|
|
{
|
|
window.OnPointUp();
|
|
}
|
|
|
|
_isDraggingSkill = false;
|
|
}
|
|
|
|
}
|
|
} |