using UnityEngine;
|
using CnControls;
|
using System.Collections;
|
using vnxbqy.UI;
|
using UnityEngine.Events;
|
using UnityEngine.EventSystems;
|
|
public class UserInputHandler : MonoBehaviour
|
{
|
private float m_LastClickTime;
|
private Vector3 m_PrevClickPosition;
|
public static bool isTouched = false;
|
public static bool isClicked = false;
|
|
public static event UnityAction<Vector3> OnClickedFloor;
|
public static event UnityAction OnCirclePanelTouched;
|
|
private void OnEnable()
|
{
|
CnInputManager.Instance.FingerLeftedEvent += OnTouchLefted;
|
CnInputManager.Instance.FingerMovedEvent += OnMoved;
|
CnInputManager.Instance.FingerTouchedEvent += OnTouched;
|
}
|
|
private void OnDisable()
|
{
|
|
CnInputManager.Instance.FingerLeftedEvent -= OnTouchLefted;
|
CnInputManager.Instance.FingerMovedEvent -= OnMoved;
|
CnInputManager.Instance.FingerTouchedEvent -= OnTouched;
|
|
}
|
|
private void Update()
|
{
|
HandleMouseInput();
|
|
#if UNITY_EDITOR
|
HandleKeyBoardInput();
|
#endif
|
}
|
|
private void HandleKeyBoardInput()
|
{
|
if (WindowCenter.Instance.IsOpen<GMInputWin>())
|
{
|
return;
|
}
|
if (ArenaManager.isArenaPK)
|
return;
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return;
|
}
|
|
float KeyVertical = Input.GetAxis("Vertical");
|
float KeyHorizontal = Input.GetAxis("Horizontal");
|
|
if (Input.GetKeyUp(KeyCode.J))
|
{
|
_hero.ComAtk();
|
}
|
|
if (RuntimeLogUtility.s_UseKeyBoardCastSkill)
|
{
|
if (Input.GetKey(KeyCode.U))
|
{
|
_hero.CastSkill(PlayerDatas.Instance.skill.GetQuickSkillByPos(0).id);
|
}
|
else if (Input.GetKey(KeyCode.I))
|
{
|
_hero.CastSkill(PlayerDatas.Instance.skill.GetQuickSkillByPos(1).id);
|
}
|
else if (Input.GetKey(KeyCode.O))
|
{
|
_hero.CastSkill(PlayerDatas.Instance.skill.GetQuickSkillByPos(2).id);
|
}
|
else if (Input.GetKey(KeyCode.P))
|
{
|
_hero.CastSkill(PlayerDatas.Instance.skill.GetQuickSkillByPos(3).id);
|
}
|
else if (Input.GetKey(KeyCode.Space))
|
{
|
_hero.CastSkill(190);
|
}
|
else if (Input.GetKey(KeyCode.Alpha1))
|
{
|
_hero.Behaviour.DoAttack(_hero.SkillMgr.Get(100));
|
}
|
else if (Input.GetKey(KeyCode.Alpha2))
|
{
|
_hero.Behaviour.DoAttack(_hero.SkillMgr.Get(101));
|
}
|
else if (Input.GetKey(KeyCode.Alpha3))
|
{
|
_hero.Behaviour.DoAttack(_hero.SkillMgr.Get(102));
|
}
|
else if (Input.GetKey(KeyCode.Alpha4))
|
{
|
_hero.Behaviour.DoAttack(_hero.SkillMgr.Get(103));
|
}
|
}
|
|
if (Input.GetKey(KeyCode.W) ||
|
Input.GetKey(KeyCode.S) ||
|
Input.GetKey(KeyCode.A) ||
|
Input.GetKey(KeyCode.D))
|
{
|
Vector3 _direction = Vector3.zero;
|
|
if (KeyVertical < 0)
|
{
|
_direction.z = -1;
|
}
|
else if (KeyVertical > 0)
|
{
|
_direction.z = 1;
|
}
|
if (KeyHorizontal > 0)
|
{
|
_direction.x = 1;
|
}
|
else if (KeyHorizontal < 0)
|
{
|
_direction.x = -1;
|
}
|
|
if (OnCirclePanelTouched != null)
|
{
|
OnCirclePanelTouched();
|
}
|
|
MapTransferUtility.Instance.Clear();
|
|
// 是否是可以移动的状态
|
_direction = CameraController.Instance.transform.TransformDirection(_direction);
|
_direction.y = 0;
|
_hero.destForward = _direction;
|
|
if (IsMoveValid())
|
{
|
_hero.Run();
|
}
|
|
isTouched = true;
|
}
|
else
|
{
|
if (Input.GetKeyUp(KeyCode.W) ||
|
Input.GetKeyUp(KeyCode.S) ||
|
Input.GetKeyUp(KeyCode.A) ||
|
Input.GetKeyUp(KeyCode.D))
|
{
|
if (_hero.IsRun())
|
{
|
if ((StatusMgr.IsValid()
|
&& StatusMgr.Instance.CanMove(PlayerDatas.Instance.PlayerId)))
|
{
|
if (!_hero.IsRushing
|
&& !GA_Hero.s_MapSwitching)
|
{
|
float _distance = MathUtility.DistanceSqrtXZ(_hero.PrevPos, _hero.Pos);
|
if (_distance > 0.25f)
|
{
|
_hero.PrevPos = _hero.Pos;
|
}
|
Send_CB409_tagCMPyMove(0);
|
}
|
}
|
|
if (_hero.State == E_ActorState.AutoRun)
|
{
|
_hero.StopPathFind();
|
}
|
|
_hero.Idle();
|
}
|
isTouched = false;
|
}
|
}
|
}
|
|
private void HandleMouseInput()
|
{
|
if (CameraController.Instance == null)
|
{
|
return;
|
}
|
|
if (Input.GetMouseButtonDown(0) && !ArenaManager.isArenaPK)
|
{
|
if (UIUtility.IsPointerOverGameObject())
|
{
|
return;
|
}
|
|
Camera _mainCamera = CameraController.Instance.CameraObject;
|
RaycastHit _hitInfo;
|
Ray _ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
|
|
if (Physics.Raycast(_ray, out _hitInfo, 100, LayerUtility.WalkbleMask) == false)
|
{
|
return;
|
}
|
|
if (Time.realtimeSinceStartup - m_LastClickTime > 0.5f)
|
{
|
SFXPlayUtility.Instance.PlayEffectAsync(1060, _hitInfo.point, Vector3.forward);
|
m_LastClickTime = Time.realtimeSinceStartup;
|
}
|
|
MapTransferUtility.Instance.Clear();
|
|
Vector3 _destPosition = _hitInfo.point;
|
if (m_PrevClickPosition == _destPosition)
|
{
|
return;
|
}
|
|
float _clickDelta = Vector3.SqrMagnitude(_destPosition - m_PrevClickPosition);
|
|
if (_clickDelta < .05f)
|
{
|
return;
|
}
|
|
GA_Hero.startAutoHazyRegion = false;
|
|
isClicked = true;
|
|
if (OnClickedFloor != null)
|
{
|
OnClickedFloor(_destPosition);
|
}
|
|
if (!IsMoveValid())
|
{
|
return;
|
}
|
|
m_PrevClickPosition = _destPosition;
|
PlayerDatas.Instance.hero.MoveToPosition(_destPosition);
|
|
}
|
}
|
|
void OnMoved()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
GA_Hero.startAutoHazyRegion = false;
|
|
if (OnCirclePanelTouched != null)
|
{
|
OnCirclePanelTouched();
|
}
|
|
var inputVector = new Vector3(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
|
Vector3 _movementVector = Vector3.zero;
|
|
float _speedFactor = inputVector.magnitude;
|
|
if (_speedFactor > 0.001f)
|
{
|
if (_speedFactor > 1)
|
{
|
_speedFactor = 1;
|
}
|
|
_movementVector = CameraController.Instance.transform.TransformDirection(inputVector);
|
_movementVector.y = 0f;
|
_movementVector.Normalize();
|
if (_hero != null)
|
{
|
_hero.destForward = _movementVector;
|
if (IsMoveValid())
|
{
|
if (!_hero.SkillMgr.DoingPrepareSkill
|
&& (_hero.SkillMgr.CurCastSkill == null
|
|| _hero.SkillMgr.CurCastSkill.SkillCompelete))
|
{
|
_hero.Run();
|
|
_hero.State = E_ActorState.CtrlRun;
|
}
|
}
|
}
|
|
}
|
}
|
|
void OnTouched()
|
{
|
isTouched = true;
|
|
if (OnCirclePanelTouched != null)
|
{
|
OnCirclePanelTouched();
|
}
|
|
MapTransferUtility.Instance.Clear();
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero != null)
|
{
|
_hero.Behaviour.StopKillUntilDieAI();
|
|
if ((StatusMgr.IsValid()
|
&& StatusMgr.Instance.CanMove(PlayerDatas.Instance.PlayerId)))
|
{
|
if (_hero.State == E_ActorState.AutoRun)
|
{
|
_hero.StopPathFind();
|
}
|
}
|
}
|
}
|
|
void OnTouchLefted()
|
{
|
if (OnCirclePanelTouched != null)
|
{
|
OnCirclePanelTouched();
|
}
|
|
isTouched = false;
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero != null && (_hero.IsRun() || _hero.IsIdle()))
|
{
|
if (_hero.State == E_ActorState.AutoRun)
|
{
|
_hero.StopPathFind();
|
}
|
|
_hero.State = E_ActorState.Idle;
|
_hero.Idle();
|
|
if ((StatusMgr.IsValid()
|
&& StatusMgr.Instance.CanMove(PlayerDatas.Instance.PlayerId)))
|
{
|
if (!_hero.IsRushing
|
&& !GA_Hero.s_MapSwitching)
|
{
|
float _distance = MathUtility.DistanceSqrtXZ(_hero.PrevPos, _hero.Pos);
|
if (_distance > 0.25f)
|
{
|
_hero.PrevPos = _hero.Pos;
|
}
|
Send_CB409_tagCMPyMove(0);
|
}
|
}
|
}
|
|
//Send_TagCPlayerMove(_hero.Pos, _hero.Pos);
|
|
//DesignDebug.LogFormat("结束移动, 初始坐标:{0}, 当前坐标:{1}", m_StartPosition, _hero.Position);
|
//Send_TagCPlayerStopMove(_hero.Position);
|
}
|
|
//private static byte s_LastStatus = 0;
|
|
public static void Send_CB409_tagCMPyMove(byte moveOrStop = 1)
|
{
|
if (ArenaManager.IsArenaClientNotMirrorFight)
|
return;
|
|
//s_LastStatus = moveOrStop;
|
|
if (!PreFightMission.Instance.IsFinished()
|
|| AdventureStage.Instance.IsInAdventureStage)
|
{
|
return;
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return;
|
}
|
|
if (_hero.SkillMgr.DoingPrepareSkill)
|
{
|
return;
|
}
|
|
if (ClientDungeonStageUtility.isClientDungeon
|
#if UNITY_EDITOR
|
|| RuntimeLogUtility.TEST_CLIENT_PVP
|
#endif
|
)
|
{
|
return;
|
}
|
|
CB409_tagCMPyMove _b409 = new CB409_tagCMPyMove
|
{
|
ClientPosX = (ushort)(_hero.Pos.x * 100),
|
ClientPosY = (ushort)(_hero.Pos.z * 100),
|
SeverPosX = (ushort)(_hero.Pos.x * 2 + GA_Hero.MapOffset.x),
|
SeverPosY = (ushort)(_hero.Pos.z * 2 + GA_Hero.MapOffset.z),
|
WorldTick = PlayerDatas.Instance.GetWorldTick(),
|
MoveType = moveOrStop
|
};
|
if (_hero.Root.transform.eulerAngles.y < 0)
|
{
|
_b409.Dir = (ushort)((360 + _hero.Root.transform.eulerAngles.y) * 100);
|
}
|
else
|
{
|
_b409.Dir = (ushort)(_hero.Root.transform.eulerAngles.y * 100);
|
}
|
|
if (CrossServerUtility.IsCrossServer())
|
{
|
GameNetSystem.Instance.SendToCrossServer(_b409);
|
}
|
else
|
{
|
GameNetSystem.Instance.SendInfo(_b409);
|
}
|
|
|
#if UNITY_EDITOR
|
if (RuntimeLogUtility.s_MoveLog)
|
{
|
string _content = string.Format("{4} 与服务端同步坐标, 客户端:{0}, 服务端:{1}, 朝向:{2}, 地图: {3}",
|
new Vector2(_b409.ClientPosX, _b409.ClientPosY),
|
new Vector2(_b409.SeverPosX, _b409.SeverPosY),
|
_hero.Root.transform.eulerAngles.y,
|
PlayerDatas.Instance.baseData.MapID,
|
moveOrStop);
|
Debug.LogFormat("Content: {0}", _content);
|
}
|
#endif
|
}
|
|
// public static void Send_TagCPlayerMove(Vector3 start, Vector3 end)
|
// {
|
// if (PreFightMission.Instance.IsFinished() == false
|
// || (StatusMgr.IsValid() && !StatusMgr.Instance.CanMove(PlayerDatas.Instance.PlayerId)))
|
// {
|
// return;
|
// }
|
|
// ushort _startX = (ushort)(start.x * 2f);
|
// ushort _startY = (ushort)(start.z * 2f);
|
// ushort _endX = (ushort)(end.x * 2f);
|
// ushort _endY = (ushort)(end.z * 2f);
|
|
// C0501_tagCPlayerMove _tagCPlayerMove = new C0501_tagCPlayerMove();
|
|
// _tagCPlayerMove.StartX = _startX;
|
// _tagCPlayerMove.StartY = _startY;
|
// _tagCPlayerMove.DestX = _endX;
|
// _tagCPlayerMove.DestY = _endY;
|
// _tagCPlayerMove.WorldTick = PlayerDatas.Instance.GetWorldTick();
|
|
// GameNetSystem.Instance.SendInfo(_tagCPlayerMove);
|
//#if UNITY_EDITOR
|
// if (RuntimeLogUtility.s_MoveLog)
|
// {
|
// string _content = string.Format("与服务端同步坐标, 开始坐标: {0}, 结束坐标: {1}, 地图: {2}",
|
// new Vector2(_tagCPlayerMove.StartX, _tagCPlayerMove.StartY),
|
// new Vector2(_tagCPlayerMove.DestX, _tagCPlayerMove.DestY),
|
// PlayerDatas.Instance.baseData.MapID);
|
// Debug.LogFormat("Content: {0}", _content);
|
// }
|
//#endif
|
// //RuntimeLogUtility.AddLog_Black(_content, PlayerDatas.Inst.PlayerId);
|
// }
|
|
public static bool IsMoveValid()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return false;
|
}
|
|
if (GA_Hero.s_MapSwitching)
|
{
|
return false;
|
}
|
|
// 是否是可以移动的状态
|
if (!_hero.CanMove())
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
}
|