Files
Simulation/Assets/Scripts/ClickHandler.cs
준학 노 0be41c12cd 카메라 이동범위 설정 -0.2(노준학)
기즈모 고정 -0.5(노준학) 완료
MQTT 재연결 로직 -0.2(노준학) - 작업중
2025-07-15 11:00:11 +09:00

76 lines
2.4 KiB
C#

using UnityEditor;
using UnityEngine;
using System;
public class ClickHandler : MonoBehaviour
{
public ClickHighlight highLight;
public ModelObjectStatus objStatus;
public float clickDurationThreshold = 0.2f;
public float clickDistanceThreshold = 0.5f;
public float doubleClickThreshold = 0.2f;
float clickStart = 0;
Vector3 clickStartPos;
public event Action onDeSelectObject;
public enum InputState
{
none, objectHandling, pathMaking,
}
// 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))
{
clickStart = Time.time;
clickStartPos = Input.mousePosition;
}
else if (Input.GetMouseButtonDown(1))
{
}
else if (Input.GetMouseButtonUp(0))
{
if (Time.time - clickStart > clickDurationThreshold)
return;
if (Vector3.Magnitude(Input.mousePosition - clickStartPos) > clickDistanceThreshold)
return;
if (UnityEngine.EventSystems.EventSystem.current?.IsPointerOverGameObject() == true)
return; // UI 클릭이면 무시
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
Debug.Log(hit.transform.name);
if (hit.collider.TryGetComponent<IClickable>(out var clickable))
{
highLight.ShowHighlight((BoxCollider)hit.collider);
//objStatus.gameObject.SetActive(true);
//objStatus.SetStatus(hit.transform.GetComponent<SimulationModel>());
RTGController.I.SetGizmoTargetObject(hit.transform.gameObject);
clickable.OnClick();
}
else
{
highLight.HideHighlight();
//objStatus.gameObject.SetActive(false);
RTGController.I.SetWorkGizmoId(RTGController.GizmoId.None);
RTGController.I.ClearGizmoTargetObjects();
onDeSelectObject?.Invoke();
}
return;
}
highLight.HideHighlight();
onDeSelectObject?.Invoke();
}
}
}