Files
Simulation/Assets/Scripts/ClickHandler.cs

71 lines
2.2 KiB
C#
Raw Normal View History

2025-05-12 18:00:37 +09:00
using UnityEditor;
using UnityEngine;
public class ClickHandler : MonoBehaviour
{
public ClickHighlight highLight;
public ModelObjectStatus objStatus;
2025-05-13 12:19:46 +09:00
public float clickDurationThreshold = 0.2f;
public float clickDistanceThreshold = 0.5f;
2025-05-28 10:56:57 +09:00
public float doubleClickThreshold = 0.2f;
2025-05-13 12:19:46 +09:00
float clickStart = 0;
Vector3 clickStartPos;
2025-05-26 12:53:54 +09:00
public enum InputState
{
none, objectHandling, pathMaking,
}
2025-05-12 18:00:37 +09:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
2025-05-13 12:19:46 +09:00
clickStart = Time.time;
clickStartPos = Input.mousePosition;
2025-05-28 10:56:57 +09:00
}
else if (Input.GetMouseButtonDown(1))
{
2025-05-13 12:19:46 +09:00
}
else if (Input.GetMouseButtonUp(0))
{
if (Time.time - clickStart > clickDurationThreshold)
return;
if (Vector3.Magnitude(Input.mousePosition - clickStartPos) > clickDistanceThreshold)
return;
2025-05-12 18:00:37 +09:00
if (UnityEngine.EventSystems.EventSystem.current?.IsPointerOverGameObject() == true)
return; // UI Ŭ<><C5AC><EFBFBD≯<EFBFBD> <20><><EFBFBD><EFBFBD>
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
if (hit.collider.TryGetComponent<IClickable>(out var clickable))
{
highLight.ShowHighlight((BoxCollider)hit.collider);
objStatus.gameObject.SetActive(true);
objStatus.SetStatus(hit.transform.GetComponent<SimulationModel>());
2025-05-13 12:19:46 +09:00
RTGController.I.SetGizmoTargetObject(hit.transform.gameObject);
2025-05-12 18:00:37 +09:00
clickable.OnClick();
}
else
{
highLight.HideHighlight();
objStatus.gameObject.SetActive(false);
2025-05-13 12:19:46 +09:00
RTGController.I.SetWorkGizmoId(RTGController.GizmoId.None);
RTGController.I.ClearGizmoTargetObjects();
2025-05-12 18:00:37 +09:00
}
return;
}
highLight.HideHighlight();
}
}
}