Files
JJBB/Assets/Project/Script/GUI/SkillBar/SimpleSkillButton.cs
2024-08-23 15:49:34 +08:00

94 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Games.Events;
using Games.LogicObj;
using GCGame.Table;
using Module.Log;
using UnityEngine;
using UnityEngine.EventSystems;
public class SimpleSkillButton : SkillButtonBase, IPointerDownHandler, IPointerUpHandler
{
//public GameObject PressShowImage; //增加按着时显示的图片
// 当前操作技能按钮的手指Id
public int? CurrentFingerId { get; private set; }
public bool AllowInput { get; private set; }
public void OnPointerDown(PointerEventData eventData)
{
if (CurrentFingerId == null && ProcessInput.Instance != null && !ProcessInput.Instance.isBlocked && AllowInput)
{
var mainPlayer = ObjManager.Instance.MainPlayer;
if (mainPlayer == null)
LogModule.ErrorLog("MainPlayer is Null");
else if (mainPlayer.IsDisableControl())
{
//组队跟随,不响应技能报错
if (GameManager.gameManager.PlayerDataPool.IsFollowTeam)
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5128}"));
// 暂时没有混乱中报错的机制
}
else
{
// 不确定这个事件同Update的周期因此发送一次操作
// 特殊处理场景不可使用技能的情况 - 这种情况不允许用户一直按着报错
var useSkillResult = UseSkill();
if (useSkillResult != SkillCastableCheckResult.FailScene
&& useSkillResult != SkillCastableCheckResult.FailMission)
{
CurrentFingerId = eventData.pointerId;
//if (PressShowImage != null)
// PressShowImage.SetActive(true);
}
}
}
}
public void OnPointerUp(PointerEventData eventData)
{
if (CurrentFingerId == eventData.pointerId)
Clear();
}
private void Clear()
{
//if (PressShowImage != null && CurrentFingerId != null)
// PressShowImage.SetActive(false);
CurrentFingerId = null;
}
private void Start()
{
EventDispatcher.Instance.Add(Games.Events.EventId.LockSkillInput, OnSkillInputUpdate);
EventDispatcher.Instance.Add(Games.Events.EventId.ProcessInputBlock, OnProcessInputBlock);
OnSkillInputUpdate(null);
}
private void OnDestroy()
{
EventDispatcher.Instance.Remove(Games.Events.EventId.LockSkillInput, OnSkillInputUpdate);
EventDispatcher.Instance.Remove(Games.Events.EventId.ProcessInputBlock, OnProcessInputBlock);
}
private void OnProcessInputBlock(object args)
{
var block = (bool) args;
if (block)
Clear();
}
private void OnSkillInputUpdate(object args)
{
AllowInput = GameManager.gameManager.PlayerDataPool.AllowSimpleInput;
if (!AllowInput)
Clear();
}
private void Update()
{
if (CurrentFingerId != null)
if (ProcessInput.Instance == null || !ProcessInput.Instance.isBlocked)
UseSkill();
else
Clear();
}
}