64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
|
||
|
|
public class UIHover : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||
|
|
{
|
||
|
|
[SerializeField] private InputType inputType;
|
||
|
|
|
||
|
|
[SerializeField] private float maxLerpTimer = 1f;
|
||
|
|
|
||
|
|
[SerializeField] private float minInputVal;
|
||
|
|
[SerializeField] private float maxInputVal;
|
||
|
|
|
||
|
|
private InputManager inputManager;
|
||
|
|
|
||
|
|
private float lerpTimer = 0f;
|
||
|
|
private bool canDetectInput = false;
|
||
|
|
private float currInputVal, targetInputVal;
|
||
|
|
|
||
|
|
public void OnPointerDown(PointerEventData eventData)
|
||
|
|
{
|
||
|
|
inputManager = inputManager ?? InterfaceManager.Instance?.GetInterfaceInstance<InputManager>();
|
||
|
|
|
||
|
|
currInputVal = minInputVal;
|
||
|
|
targetInputVal = maxInputVal;
|
||
|
|
canDetectInput = true;
|
||
|
|
lerpTimer = 0f;
|
||
|
|
Debug.Log($"OnPointerEnter");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerUp(PointerEventData eventData)
|
||
|
|
{
|
||
|
|
lerpTimer = 0;
|
||
|
|
targetInputVal = minInputVal;
|
||
|
|
canDetectInput = true;
|
||
|
|
Debug.Log($"OnPointerExit");
|
||
|
|
|
||
|
|
// if (lerpTimer < maxLerpTimer)
|
||
|
|
// {
|
||
|
|
// lerpTimer = 0;
|
||
|
|
// canDetectInput = false;
|
||
|
|
// inputManager.OnInputProvided(inputType, targetInputVal);
|
||
|
|
// }
|
||
|
|
// else
|
||
|
|
// {
|
||
|
|
// lerpTimer = 0;
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Update()
|
||
|
|
{
|
||
|
|
if (!canDetectInput) return;
|
||
|
|
|
||
|
|
if (lerpTimer >= maxLerpTimer)
|
||
|
|
{
|
||
|
|
lerpTimer = 0;
|
||
|
|
canDetectInput = false;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
lerpTimer += Time.deltaTime;
|
||
|
|
currInputVal = Mathf.Lerp(currInputVal, targetInputVal, lerpTimer);
|
||
|
|
inputManager.OnInputProvided(inputType, currInputVal);
|
||
|
|
}
|
||
|
|
}
|