216 lines
6.1 KiB
C#
216 lines
6.1 KiB
C#
|
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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>uiλ<69><CEBB>
|
|||
|
|
|||
|
private int RoleID;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
//<2F>¼<EFBFBD>ע<EFBFBD><D7A2>
|
|||
|
//AppEntry.Event.Subscribe(A123EventArgs.EventId, OnA123EventArgs);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>UI
|
|||
|
/// </summary>
|
|||
|
/// <param name="mousePosition"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private GameObject GetPointerOverGameObject(Vector2 mousePosition, out bool hasUI)
|
|||
|
{
|
|||
|
hasUI = false;
|
|||
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
PointerEventData eventData = new PointerEventData(EventSystem.current);
|
|||
|
eventData.position = mousePosition;
|
|||
|
List<RaycastResult> raycastResults = new List<RaycastResult>();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>UI
|
|||
|
EventSystem.current.RaycastAll(eventData, raycastResults);
|
|||
|
|
|||
|
if (raycastResults.Count == 0)
|
|||
|
return null;
|
|||
|
|
|||
|
for(int i=0; i<raycastResults.Count; i++)
|
|||
|
{
|
|||
|
if (raycastResults[i].gameObject.layer == LayerMask.NameToLayer("UI"))
|
|||
|
{
|
|||
|
hasUI = true;
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
return raycastResults[i].gameObject;
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
private Vector2 GetClickScreenPos()
|
|||
|
{
|
|||
|
//<2F>ƶ<EFBFBD><C6B6><EFBFBD>
|
|||
|
if (Application.platform == RuntimePlatform.Android ||
|
|||
|
Application.platform == RuntimePlatform.IPhonePlayer)
|
|||
|
{
|
|||
|
if (Input.touchCount == 0)
|
|||
|
return Vector2.zero;
|
|||
|
|
|||
|
// <20><>ָ<EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>ʱ<EFBFBD><CAB1> <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ƶ<EFBFBD>
|
|||
|
if (Input.GetTouch(0).phase != TouchPhase.Began
|
|||
|
&& Input.GetTouch(0).phase != TouchPhase.Moved)
|
|||
|
return Vector2.zero;
|
|||
|
|
|||
|
return Input.GetTouch(0).position;
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD>ƽ̨
|
|||
|
else
|
|||
|
{
|
|||
|
if (!Input.GetMouseButtonDown(0))
|
|||
|
return Vector2.zero;
|
|||
|
|
|||
|
return Input.mousePosition;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
//private bool ProcessRaycast(Vector2 point, out GameObject obj,out E_NODE_TYPE withNode,out int CharIndex)
|
|||
|
private bool ProcessRaycast(Vector2 point, out E_NODE_TYPE withNode,out int RoleID)
|
|||
|
{
|
|||
|
withNode = E_NODE_TYPE.N_FREE;
|
|||
|
RoleID = 0;
|
|||
|
|
|||
|
RaycastHit hit;
|
|||
|
Ray ray = Camera.main.ScreenPointToRay(point);
|
|||
|
|
|||
|
if (!Physics.Raycast(ray, out hit))
|
|||
|
return false;
|
|||
|
|
|||
|
GameObject obj = hit.collider.gameObject;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ѡ<><D1A1>ֻ<EFBFBD><D6BB>ѡ<EFBFBD><D1A1>
|
|||
|
if (obj.CompareTag(Tags.Monster))
|
|||
|
{
|
|||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if(obj.CompareTag(Tags.NPC))
|
|||
|
{
|
|||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC
|
|||
|
}
|
|||
|
else if (obj.CompareTag(Tags.Players))
|
|||
|
{
|
|||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
//˫ָ<CBAB><D6B8><EFBFBD><EFBFBD>
|
|||
|
if (Update_DoubleTouch())
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˫ָ<CBAB><D6B8><EFBFBD><EFBFBD>
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
Vector2 clickPos = GetClickScreenPos();
|
|||
|
if (clickPos.Equals(Vector2.zero))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>UI<55><49><EFBFBD>˳<EFBFBD>
|
|||
|
GameObject obj = GetPointerOverGameObject(clickPos, out bool hasUI);
|
|||
|
|
|||
|
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|||
|
if(GamePlayEntry.UI.IsOpen<TouchButtonEffectUI>()) GamePlayEntry.UI.Hide<TouchButtonEffectUI>();
|
|||
|
GamePlayEntry.UI.OpenUI<TouchButtonEffectUI>();
|
|||
|
|
|||
|
if (hasUI)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (ProcessRaycast(clickPos, out E_NODE_TYPE withNode, out int CharIndex))
|
|||
|
return;
|
|||
|
|
|||
|
if (obj == null)
|
|||
|
return;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (obj.CompareTag(Tags.Terrain) || obj.CompareTag(Tags.DROP))
|
|||
|
{
|
|||
|
//TODOһЩ<D2BB><D0A9>ֹ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/*
|
|||
|
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
|||
|
TerrainParent.GetComponent<RectTransform>(),
|
|||
|
clickPos,
|
|||
|
GamePlayEntry.MainPlayer.TerrainCam,
|
|||
|
out _clickPoint))
|
|||
|
return;*/
|
|||
|
|
|||
|
if (withNode == E_NODE_TYPE.N_NPC)
|
|||
|
{
|
|||
|
//TODO ѡ<><D1A1>NPC
|
|||
|
}
|
|||
|
|
|||
|
//TODO <20>ƶ<EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region ˫ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
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)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˫ָ<CBAB><D6B8><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD>
|
|||
|
return false;
|
|||
|
|
|||
|
if (Input.touchCount == 2)
|
|||
|
{
|
|||
|
float dis = Vector2.Distance(Input.touches[0].position, Input.touches[1].position);//<2F><>ָ֮<D6B8><D6AE><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>
|
|||
|
if (-1 == last) last = dis;
|
|||
|
float result = dis - last;//<2F><><EFBFBD><EFBFBD>һ֡<D2BB>Ƚϱ仯
|
|||
|
if (result + current < min)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>С
|
|||
|
result = min - current;
|
|||
|
else if (result + current > max)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
result = max - current;
|
|||
|
result *= 0.1f;//ϵ<><CFB5>
|
|||
|
|
|||
|
//TODO <20>ɸ<EFBFBD><C9B8><EFBFBD>Result<6C><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
current += result;//<2F>ۼƵ<DBBC>ǰ
|
|||
|
last = dis;//<2F><>¼Ϊ<C2BC><CEAA>һ֡<D2BB><D6A1>ֵ
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
last = -1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|