Files
Simulation/Assets/Scripts/ClickHandler.cs

76 lines
2.4 KiB
C#
Raw Normal View History

using UnityEditor;
2025-05-12 18:00:37 +09:00
using UnityEngine;
2025-06-11 17:40:10 +09:00
using System;
2025-05-12 18:00:37 +09:00
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-06-11 17:40:10 +09:00
public event Action onDeSelectObject;
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 클릭이면 무시
2025-05-12 18:00:37 +09:00
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
2025-07-07 09:57:13 +09:00
Debug.Log(hit.transform.name);
2025-05-12 18:00:37 +09:00
if (hit.collider.TryGetComponent<IClickable>(out var clickable))
{
highLight.ShowHighlight((BoxCollider)hit.collider);
2025-05-29 02:08:28 +09:00
//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();
2025-05-29 02:08:28 +09:00
//objStatus.gameObject.SetActive(false);
2025-05-13 12:19:46 +09:00
RTGController.I.SetWorkGizmoId(RTGController.GizmoId.None);
RTGController.I.ClearGizmoTargetObjects();
2025-06-11 17:40:10 +09:00
onDeSelectObject?.Invoke();
2025-05-12 18:00:37 +09:00
}
return;
}
highLight.HideHighlight();
2025-06-11 17:40:10 +09:00
onDeSelectObject?.Invoke();
2025-05-12 18:00:37 +09:00
}
}
}