138 lines
5.1 KiB
C#
138 lines
5.1 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
|
|||
|
|
namespace UVC.Factory.Component
|
|||
|
|
{
|
|||
|
|
[RequireComponent(typeof(Collider))]
|
|||
|
|
public class ClickTest : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
//void Start()
|
|||
|
|
//{
|
|||
|
|
// Collider col = GetComponent<Collider>();
|
|||
|
|
// if (col != null)
|
|||
|
|
// {
|
|||
|
|
// // 콜라이더의 중심과 크기 출력 (BoxCollider의 경우)
|
|||
|
|
// if (col is BoxCollider boxCollider)
|
|||
|
|
// {
|
|||
|
|
// Debug.Log($"BoxCollider - Center: {boxCollider.center}, Size: {boxCollider.size}");
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// // 콜라이더의 월드 바운드 출력
|
|||
|
|
// Debug.Log($"콜라이더의 월드 바운드: {col.bounds}");
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// Debug.LogError($"{gameObject.name}에 콜라이더가 없습니다!");
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//void Update()
|
|||
|
|
//{
|
|||
|
|
// if (Input.GetMouseButtonDown(0)) // 0 represents the left mouse button
|
|||
|
|
// {
|
|||
|
|
|
|||
|
|
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|||
|
|
// RaycastHit hit;
|
|||
|
|
|
|||
|
|
// // 레이 시작점과 방향 로깅
|
|||
|
|
// Debug.Log($"Ray 원점: {ray.origin}, 방향: {ray.direction}");
|
|||
|
|
|
|||
|
|
// // 디버그용 레이를 씬 뷰에 그립니다
|
|||
|
|
// Debug.DrawRay(ray.origin, ray.direction * 100, Color.red, 2f);
|
|||
|
|
|
|||
|
|
// bool hitSomething = Physics.Raycast(ray, out hit);
|
|||
|
|
// Debug.Log($"Mouse button clicked - hit something: {hitSomething}");
|
|||
|
|
|
|||
|
|
// if (hitSomething)
|
|||
|
|
// {
|
|||
|
|
// Debug.Log($"Hit object: {hit.collider.gameObject.name}, distance: {hit.distance}, point: {hit.point}");
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// // 모든 콜라이더 로깅
|
|||
|
|
// Collider[] allColliders = FindObjectsOfType<Collider>();
|
|||
|
|
// Debug.Log($"씬에 있는 콜라이더 수: {allColliders.Length}");
|
|||
|
|
|
|||
|
|
// foreach (var collider in allColliders)
|
|||
|
|
// {
|
|||
|
|
// if (collider.gameObject.activeInHierarchy && collider.enabled)
|
|||
|
|
// Debug.Log($"활성화된 콜라이더: {collider.gameObject.name}, 레이어: {LayerMask.LayerToName(collider.gameObject.layer)}");
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|||
|
|
// RaycastHit[] tempinfo = new RaycastHit[100];
|
|||
|
|
// var hitcount = Physics.RaycastNonAlloc(ray, tempinfo, Mathf.Infinity);
|
|||
|
|
// Debug.Log($"Mouse button clicked hitcount:{hitcount} {Physics.Raycast(ray, out hit)}");
|
|||
|
|
|
|||
|
|
// if (Physics.Raycast(ray, out hit))
|
|||
|
|
// {
|
|||
|
|
// // Check if the hit object has the ClickableObject script
|
|||
|
|
// ClickTest clickableObject = hit.collider.GetComponent<ClickTest>();
|
|||
|
|
// if (clickableObject != null)
|
|||
|
|
// {
|
|||
|
|
// // 수동으로 이벤트 호출
|
|||
|
|
// PointerEventData pointerData = new PointerEventData(EventSystem.current);
|
|||
|
|
// pointerData.position = Input.mousePosition;
|
|||
|
|
// OnPointerClick(pointerData);
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// Debug.Log("Clicked on: " + hit.collider.gameObject.name + ", but it's not clickable.");
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// //if (Mouse.current.leftButton.wasPressedThisFrame)
|
|||
|
|
// //{
|
|||
|
|
// // Debug.Log("마우스 클릭 감지");
|
|||
|
|
// //}
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
public void OnPointerClick(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnPointerClick1: {gameObject.name}");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 포인터가 이 객체 위로 들어왔을 때 호출됩니다. 하이라이트 효과 등에 사용할 수 있습니다.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="eventData">포인터 이벤트와 관련된 데이터입니다.</param>
|
|||
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnPointerEnter: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 포인터가 이 객체에서 벗어났을 때 호출됩니다.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="eventData">포인터 이벤트와 관련된 데이터입니다.</param>
|
|||
|
|
public void OnPointerExit(PointerEventData eventData)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnPointerExit: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnMouseClick()
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnClick: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
public void OnMouseEnter()
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnMouseEnter: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnMouseExit()
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnMouseExit: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnMouseWheel()
|
|||
|
|
{
|
|||
|
|
Debug.Log($"OnMouseWheel: {gameObject.name}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|