using Axibug;
using Axibug.Event;
using Axibug.Resources;
using Axibug.Runtime;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;
namespace Game
{
public class InputComponent : GameComponent
{
private Vector2 _clickPoint; //鼠标点击ui位置
private int RoleID;
private void Start()
{
//事件注册
//AppEntry.Event.Subscribe(A123EventArgs.EventId, OnA123EventArgs);
}
///
/// 检测是否点击UI
///
///
///
private GameObject GetPointerOverGameObject(Vector2 mousePosition, out bool hasUI)
{
hasUI = false;
//创建一个点击事件
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.position = mousePosition;
List raycastResults = new List();
//向点击位置发射一条射线,检测是否点击UI
EventSystem.current.RaycastAll(eventData, raycastResults);
if (raycastResults.Count == 0)
return null;
for(int i=0; i()) GamePlayEntry.UI.Hide();
GamePlayEntry.UI.OpenUI();
if (hasUI)
{
return;
}
if (ProcessRaycast(clickPos, out E_NODE_TYPE withNode, out int CharIndex))
return;
if (obj == null)
return;
//点击地面
if (obj.CompareTag(Tags.Terrain) || obj.CompareTag(Tags.DROP))
{
//TODO一些阻止移动的内容
/*
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(
TerrainParent.GetComponent(),
clickPos,
GamePlayEntry.MainPlayer.TerrainCam,
out _clickPoint))
return;*/
if (withNode == E_NODE_TYPE.N_NPC)
{
//TODO 选中NPC
}
//TODO 移动
}
}
#region 双指手势
protected readonly Transform m_zoom = null;
private float max = 300f;
private float min = -300;
protected static float current = 0;
private float last = -1;
public bool Update_DoubleTouch()
{
if (false)//有其他和双指互斥的操作则跳出,可补充
return false;
if (Input.touchCount == 2)
{
float dis = Vector2.Distance(Input.touches[0].position, Input.touches[1].position);//两指之间的距离
if (-1 == last) last = dis;
float result = dis - last;//与上一帧比较变化
if (result + current < min)//区间限制:最小
result = min - current;
else if (result + current > max)//区间限制:最大
result = max - current;
result *= 0.1f;//系数
//TODO 可根据Result结果处理
current += result;//累计当前
last = dis;//记录为上一帧的值
return true;
}
else
{
last = -1;//不触发逻辑时
return false;
}
}
#endregion
}
}