43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class ClickHandler : MonoBehaviour
|
|
{
|
|
public ClickHighlight highLight;
|
|
public ModelObjectStatus objStatus;
|
|
// 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))
|
|
{
|
|
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>());
|
|
clickable.OnClick();
|
|
}
|
|
else
|
|
{
|
|
highLight.HideHighlight();
|
|
objStatus.gameObject.SetActive(false);
|
|
}
|
|
return;
|
|
}
|
|
highLight.HideHighlight();
|
|
}
|
|
}
|
|
}
|