34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace UVC.Edit
|
|
{
|
|
public class DropZone : MonoBehaviour, IDropHandler
|
|
{
|
|
public void OnDrop(PointerEventData eventData)
|
|
{
|
|
if (LibraryItem.DraggedPrefab != null)
|
|
{
|
|
GameObject newObj = Instantiate(LibraryItem.DraggedPrefab, GetDropPosition(eventData), Quaternion.identity);
|
|
|
|
// 여기서 newObj의 EditableObject 컴포넌트를 찾아 초기화 로직을 실행할 수 있습니다.
|
|
// newObj.GetComponent<EditableObject>()?.Initialize(System.Guid.NewGuid().ToString());
|
|
}
|
|
}
|
|
|
|
private Vector3 GetDropPosition(PointerEventData eventData)
|
|
{
|
|
// 3D Stage의 경우, 화면 좌표를 월드 좌표로 변환해야 합니다.
|
|
Ray ray = Camera.main.ScreenPointToRay(eventData.position);
|
|
if (new Plane(Vector3.up, Vector3.zero).Raycast(ray, out float enter))
|
|
{
|
|
return ray.GetPoint(enter);
|
|
}
|
|
return Vector3.zero;
|
|
|
|
// UI Canvas의 경우, RectTransformUtility를 사용합니다.
|
|
// RectTransformUtility.ScreenPointToLocalPointInRectangle(...)
|
|
}
|
|
}
|
|
}
|