56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UVC.Extention;
|
|
using UVC.UI.Info;
|
|
|
|
namespace UVC.Object3d
|
|
{
|
|
/// <summary>
|
|
/// 사용자의 마우스 클릭 입력을 감지하고 3D 객체와 상호작용합니다.
|
|
/// </summary>
|
|
public class InteractionController : InteractiveObject
|
|
{
|
|
// InfoWindow 인스턴스에 대한 참조
|
|
private InfoWindow infoWindow;
|
|
|
|
private Camera mainCamera;
|
|
|
|
private Dictionary<string, object>? infoData;
|
|
|
|
private void Awake()
|
|
{
|
|
mainCamera = Camera.main;
|
|
|
|
// 씬에 있는 InfoWindow 인스턴스를 동적으로 찾습니다.
|
|
// FindObjectOfType은 씬에서 해당 타입의 활성화된 첫 번째 객체를 반환합니다.
|
|
infoWindow = InfoWindow.Create();
|
|
|
|
if (infoWindow == null)
|
|
{
|
|
Debug.LogError("씬에서 InfoWindow 컴포넌트를 찾을 수 없습니다. InfoWindow가 씬에 존재하고 활성화되어 있는지 확인해주세요.");
|
|
enabled = false; // infoWindow가 없으면 이 스크립트를 비활성화합니다.
|
|
}
|
|
}
|
|
|
|
public override void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
Dictionary<string, object> info = new Dictionary<string, object>
|
|
{
|
|
{ "objectName", gameObject.name },
|
|
{ "objectPosition", transform.position },
|
|
{ "objectRotation", transform.rotation },
|
|
{ "objectScale", transform.localScale }
|
|
};
|
|
// 변경 된 정보가 있을 때 클릭된 객체의 정보를 InfoWindow에 전달합니다.
|
|
if (!infoWindow.IsVisible && (infoData != null && !infoData.IsSame(info)))
|
|
{
|
|
infoWindow.Show(transform, info);
|
|
infoData = info;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|