정보창, 에디트 구조 작성
This commit is contained in:
33
Assets/Scripts/UVC/Edit/DropZone.cs
Normal file
33
Assets/Scripts/UVC/Edit/DropZone.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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(...)
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/DropZone.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/DropZone.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea2b0e8422a022f4a9a6df278a857d4c
|
||||
19
Assets/Scripts/UVC/Edit/EditableObject.cs
Normal file
19
Assets/Scripts/UVC/Edit/EditableObject.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public abstract class EditableObject : MonoBehaviour, ISelectable
|
||||
{
|
||||
[field: SerializeField]
|
||||
public string ItemId { get; private set; }
|
||||
|
||||
public abstract void OnSelect();
|
||||
public abstract void OnDeselect();
|
||||
|
||||
public virtual void Initialize(string id)
|
||||
{
|
||||
this.ItemId = id;
|
||||
this.name = $"{GetType().Name}_{id}";
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/EditableObject.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/EditableObject.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ddfd4794affdf44fb5e8dadcd13284d
|
||||
22
Assets/Scripts/UVC/Edit/EditableObject3D.cs
Normal file
22
Assets/Scripts/UVC/Edit/EditableObject3D.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public class EditableObject3D : EditableObject
|
||||
{
|
||||
// 3D 객체 고유의 속성 및 로직
|
||||
// 예: Material, Mesh 등
|
||||
|
||||
public override void OnSelect()
|
||||
{
|
||||
// 외곽선 표시 로직 호출
|
||||
Debug.Log($"{name} selected.");
|
||||
}
|
||||
|
||||
public override void OnDeselect()
|
||||
{
|
||||
// 외곽선 숨김 로직 호출
|
||||
Debug.Log($"{name} deselected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/EditableObject3D.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/EditableObject3D.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bbff96f4152cac46a16c5343f40e5fa
|
||||
40
Assets/Scripts/UVC/Edit/GizmoController.cs
Normal file
40
Assets/Scripts/UVC/Edit/GizmoController.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public class GizmoController : MonoBehaviour
|
||||
{
|
||||
public Transform targetObject; // 선택된 객체의 Transform
|
||||
// private RuntimeTransformHandle _transformHandle;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
InteractionController.OnObjectSelected += OnObjectSelected;
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
InteractionController.OnObjectSelected -= OnObjectSelected;
|
||||
}
|
||||
|
||||
void OnObjectSelected(EditableObject obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
targetObject = obj.transform;
|
||||
// _transformHandle.target = targetObject;
|
||||
// _transformHandle.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObject = null;
|
||||
// _transformHandle.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 툴바에서 이동/회전/크기 툴 선택 시 아래와 같은 함수 호출
|
||||
public void SetMoveMode()
|
||||
{
|
||||
// _transformHandle.type = HandleType.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/GizmoController.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/GizmoController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8cd05d9b2d558f46aeeef881d1175e1
|
||||
8
Assets/Scripts/UVC/Edit/ISelectable.cs
Normal file
8
Assets/Scripts/UVC/Edit/ISelectable.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public interface ISelectable
|
||||
{
|
||||
void OnSelect();
|
||||
void OnDeselect();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/ISelectable.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/ISelectable.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 958cc5e553c04b7429a00214ce6a263a
|
||||
77
Assets/Scripts/UVC/Edit/InteractionController.cs
Normal file
77
Assets/Scripts/UVC/Edit/InteractionController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public class InteractionController : MonoBehaviour
|
||||
{
|
||||
public static event System.Action<EditableObject> OnObjectSelected;
|
||||
public static event System.Action OnBackgroundClicked;
|
||||
|
||||
private Camera _mainCamera;
|
||||
private EditableObject _selectedObject;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_mainCamera = Camera.main;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
// UI 위에서 클릭했는지 먼저 확인
|
||||
if (EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return; // UI 클릭 시 월드 객체 선택 방지
|
||||
}
|
||||
|
||||
HandleSelection();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleSelection()
|
||||
{
|
||||
Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
// 3D 객체 선택 (Physics Raycast)
|
||||
if (Physics.Raycast(ray, out RaycastHit hit))
|
||||
{
|
||||
// EditableObject 컴포넌트를 가진 객체인지 확인
|
||||
if (hit.collider.TryGetComponent<EditableObject>(out var target))
|
||||
{
|
||||
SetSelectedObject(target);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 2D 객체 선택 (Physics2D Raycast) - 필요 시 카메라 설정에 따라 추가
|
||||
// RaycastHit2D hit2D = Physics2D.GetRayIntersection(ray);
|
||||
// if (hit2D.collider != null && hit2D.collider.TryGetComponent<EditableObject>(out var target2D))
|
||||
// {
|
||||
// SetSelectedObject(target2D);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 아무것도 선택되지 않았을 경우
|
||||
SetSelectedObject(null);
|
||||
}
|
||||
|
||||
private void SetSelectedObject(EditableObject target)
|
||||
{
|
||||
if (_selectedObject == target) return;
|
||||
|
||||
_selectedObject?.OnDeselect();
|
||||
_selectedObject = target;
|
||||
_selectedObject?.OnSelect();
|
||||
|
||||
if (_selectedObject != null)
|
||||
{
|
||||
OnObjectSelected?.Invoke(_selectedObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnBackgroundClicked?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/InteractionController.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/InteractionController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce86abe153e9a8742b1643cc28166c16
|
||||
30
Assets/Scripts/UVC/Edit/LibraryItem.cs
Normal file
30
Assets/Scripts/UVC/Edit/LibraryItem.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public class LibraryItem : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public GameObject prefabToSpawn; // 이 아이템이 생성할 프리팹
|
||||
public static GameObject DraggedPrefab; // 현재 드래그 중인 프리팹 (static으로 공유)
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
DraggedPrefab = prefabToSpawn;
|
||||
// 드래그 시 시각적 효과 (예: 아이콘 반투명화)
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData) { } // 드래그 중 로직 (필요 시)
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
DraggedPrefab = null;
|
||||
// 드래그 종료 시 시각적 효과 원상복구
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/LibraryItem.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/LibraryItem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c02ea26fd607fed4aaa07ca57e73a451
|
||||
35
Assets/Scripts/UVC/Edit/OutlineEffect.cs
Normal file
35
Assets/Scripts/UVC/Edit/OutlineEffect.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class OutlineEffect : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Material _outlineMaterial;
|
||||
private Renderer _renderer;
|
||||
private bool _isOutlined = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_renderer = GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
public void SetOutline(bool visible)
|
||||
{
|
||||
if (_isOutlined == visible) return;
|
||||
|
||||
_isOutlined = visible;
|
||||
var materials = _renderer.sharedMaterials.ToList();
|
||||
if (_isOutlined)
|
||||
{
|
||||
materials.Add(_outlineMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
materials.Remove(_outlineMaterial);
|
||||
}
|
||||
_renderer.materials = materials.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/OutlineEffect.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/OutlineEffect.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2659b57b886087046bbf148a542a83d1
|
||||
49
Assets/Scripts/UVC/Edit/PropertyWindow.cs
Normal file
49
Assets/Scripts/UVC/Edit/PropertyWindow.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using SFB;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UVC.Edit
|
||||
{
|
||||
public class PropertyWindow : MonoBehaviour
|
||||
{
|
||||
public Image uiImageTarget; // UI 객체에 적용할 Image
|
||||
public SpriteRenderer spriteTarget; // 2D 객체에 적용할 SpriteRenderer
|
||||
|
||||
public void OpenImageFileBrowser()
|
||||
{
|
||||
var extensions = new[] {
|
||||
new ExtensionFilter("Image Files", "png", "jpg", "jpeg")
|
||||
};
|
||||
|
||||
// 비동기 방식으로 파일 브라우저 열기
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Select an Image", "", extensions, false, (string[] paths) =>
|
||||
{
|
||||
if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
|
||||
{
|
||||
LoadAndApplyTexture(paths[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadAndApplyTexture(string path)
|
||||
{
|
||||
byte[] fileData = File.ReadAllBytes(path);
|
||||
Texture2D texture = new Texture2D(2, 2);
|
||||
// 이미지 데이터로 텍스처 로드
|
||||
if (texture.LoadImage(fileData))
|
||||
{
|
||||
if (uiImageTarget != null)
|
||||
{
|
||||
Sprite newSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||
uiImageTarget.sprite = newSprite;
|
||||
}
|
||||
if (spriteTarget != null)
|
||||
{
|
||||
Sprite newSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||
spriteTarget.sprite = newSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/Edit/PropertyWindow.cs.meta
Normal file
2
Assets/Scripts/UVC/Edit/PropertyWindow.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 170fcace70e26454e80a7e0c972f1e6f
|
||||
Reference in New Issue
Block a user