75 lines
2.4 KiB
C#
75 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))
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|