add project files
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class InputController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("core")]
|
||||
private CoreController _core;
|
||||
|
||||
private bool _downValid;
|
||||
|
||||
private Vector2 GetTouchPos()
|
||||
{
|
||||
if (Input.touchCount >= 1)
|
||||
{
|
||||
return Input.GetTouch(0).position;
|
||||
}
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
return Input.mousePosition;
|
||||
#else
|
||||
return Vector2.zero;
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool TouchDown()
|
||||
{
|
||||
if (Input.touchCount >= 1)
|
||||
{
|
||||
return Input.GetTouch(0).phase == TouchPhase.Began;
|
||||
}
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
return Input.GetMouseButtonDown(0);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool TouchHold()
|
||||
{
|
||||
if (Input.touchCount >= 1)
|
||||
{
|
||||
TouchPhase phase = Input.GetTouch(0).phase;
|
||||
return phase == TouchPhase.Moved || phase == TouchPhase.Stationary;
|
||||
}
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
return Input.GetMouseButton(0);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool TouchUp()
|
||||
{
|
||||
if (Input.touchCount >= 1)
|
||||
{
|
||||
return Input.GetTouch(0).phase == TouchPhase.Ended;
|
||||
}
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
return Input.GetMouseButtonUp(0);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector2 touchPos = GetTouchPos();
|
||||
if (!UIUtils.IsInputBlocked(touchPos) && TouchDown())
|
||||
{
|
||||
IInputsListener listener = _core.GetCurrentInputsListener();
|
||||
if (listener != null)
|
||||
{
|
||||
listener.InputDown(touchPos);
|
||||
}
|
||||
_downValid = true;
|
||||
}
|
||||
else if (_downValid)
|
||||
{
|
||||
if (TouchHold())
|
||||
{
|
||||
IInputsListener listener2 = _core.GetCurrentInputsListener();
|
||||
if (listener2 != null)
|
||||
{
|
||||
listener2.InputMove(touchPos);
|
||||
}
|
||||
}
|
||||
else if (TouchUp())
|
||||
{
|
||||
_downValid = false;
|
||||
IInputsListener listener3 = _core.GetCurrentInputsListener();
|
||||
if (listener3 != null)
|
||||
{
|
||||
listener3.InputUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user