ComponentList 완료, Context 메뉴 추가
This commit is contained in:
@@ -15,39 +15,58 @@ namespace UVC.Factory
|
||||
{
|
||||
[Header("Panning Speed")]
|
||||
[Tooltip("카메라 높이가 임계값보다 낮을 때의 평행 이동 속도")]
|
||||
public float lowAltitudePanSpeed = 0.5f;
|
||||
[SerializeField]
|
||||
private float lowAltitudePanSpeed = 0.5f;
|
||||
|
||||
[Tooltip("카메라 높이가 임계값보다 높을 때의 평행 이동 속도")]
|
||||
public float highAltitudePanSpeed = 10f;
|
||||
[SerializeField]
|
||||
private float highAltitudePanSpeed = 10f;
|
||||
|
||||
[Tooltip("카메라 회전 속도")]
|
||||
public float rotationSpeed = 300f;
|
||||
[SerializeField]
|
||||
private float rotationSpeed = 300f;
|
||||
|
||||
[Tooltip("카메라 줌 속도")]
|
||||
public float zoomSpeed = 10f;
|
||||
[SerializeField]
|
||||
private float zoomSpeed = 10f;
|
||||
|
||||
[Header("Movement Smoothing")]
|
||||
[Tooltip("패닝 시 마우스 이동량의 최대값을 제한하여, 프레임 드랍 시 카메라가 급격하게 튀는 현상을 방지합니다.")]
|
||||
public float maxPanDelta = 50f;
|
||||
[SerializeField]
|
||||
private float maxPanDelta = 50f;
|
||||
|
||||
[Header("Camera")]
|
||||
[Tooltip("카메라 최소 높이")]
|
||||
public float minCameraY = 2f;
|
||||
[SerializeField]
|
||||
private float minCameraY = 2f;
|
||||
|
||||
[Tooltip("카메라 최대 높이")]
|
||||
public float maxCameraY = 50f;
|
||||
[SerializeField]
|
||||
private float maxCameraY = 50f;
|
||||
|
||||
[Tooltip("카메라의 최소 수직 회전 각도 (X축)")]
|
||||
public float minPitch = 20f;
|
||||
[SerializeField]
|
||||
private float minPitch = 20f;
|
||||
|
||||
[Tooltip("카메라의 최대 수직 회전 각도 (X축)")]
|
||||
public float maxPitch = 85f;
|
||||
[SerializeField]
|
||||
private float maxPitch = 85f;
|
||||
|
||||
[Tooltip("카메라의 최소 수평 회전 각도 (y축)")]
|
||||
public float minYaw = -45f;
|
||||
[SerializeField]
|
||||
private float minYaw = -45f;
|
||||
|
||||
[Tooltip("카메라의 최대 수평 회전 각도 (y축)")]
|
||||
public float maxYaw = 45f;
|
||||
[SerializeField]
|
||||
private float maxYaw = 45f;
|
||||
|
||||
[Tooltip("마우스를 이용 한 회전 사용 여부")]
|
||||
[SerializeField]
|
||||
public bool EnabledRotation = true;
|
||||
|
||||
[Tooltip("마우스를 이용 한 확대/축소 사용 여부")]
|
||||
[SerializeField]
|
||||
public bool EnabledZoom = true;
|
||||
|
||||
/// <summary>
|
||||
/// 카메라의 변형이 변경될 때 발생합니다.
|
||||
@@ -211,8 +230,8 @@ namespace UVC.Factory
|
||||
{
|
||||
if (!Enable) return; // 카메라 컨트롤이 비활성화된 경우, 업데이트를 건너뜁니다.
|
||||
HandlePanning();
|
||||
HandleRotation();
|
||||
HandleZoom();
|
||||
if (EnabledRotation) HandleRotation();
|
||||
if (EnabledZoom) HandleZoom();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -407,7 +426,7 @@ namespace UVC.Factory
|
||||
/// <param name="equipmentPosition">포커스할 대상의 Transform</param>
|
||||
/// <param name="distance">대상과의 거리</param>
|
||||
/// <param name="duration">이동에 걸리는 시간(초), 기본값 1초</param>
|
||||
public void FocusOnTarget(Vector3 equipmentPosition, float distance, float duration = 1.0f)
|
||||
public void FocusOnTarget(Vector3 equipmentPosition, float distance, float duration = 1.0f, bool keepYRotation = true)
|
||||
{
|
||||
if (equipmentPosition == null) return;
|
||||
|
||||
@@ -424,7 +443,7 @@ namespace UVC.Factory
|
||||
}
|
||||
|
||||
// 코루틴을 사용하여 부드러운 이동 구현
|
||||
focusCoroutine = StartCoroutine(SmoothFocusOnTarget(position, distance, duration));
|
||||
focusCoroutine = StartCoroutine(SmoothFocusOnTarget(position, distance, duration, keepYRotation));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -452,7 +471,7 @@ namespace UVC.Factory
|
||||
/// <summary>
|
||||
/// 부드럽게 타겟까지 이동하는 코루틴
|
||||
/// </summary>
|
||||
private IEnumerator SmoothFocusOnTarget(Vector3 targetTransform, float distance, float duration)
|
||||
private IEnumerator SmoothFocusOnTarget(Vector3 targetTransform, float distance, float duration, bool keepYRotation = true)
|
||||
{
|
||||
// 카메라가 바라볼 대상의 중심점
|
||||
Vector3 targetPosition = targetTransform;
|
||||
@@ -467,6 +486,14 @@ namespace UVC.Factory
|
||||
|
||||
// 최종 회전값 계산
|
||||
Quaternion endRotation = Quaternion.LookRotation(targetPosition - endPosition);
|
||||
|
||||
if (keepYRotation)
|
||||
{
|
||||
Vector3 euler = endRotation.eulerAngles;
|
||||
euler.y = 0; // Y축 회전각을 0으로 설정
|
||||
endRotation = Quaternion.Euler(euler);
|
||||
}
|
||||
|
||||
endRotation = ValidateRotation(endRotation); // 회전값 검증 및 수정
|
||||
|
||||
// 이동 시간 계산을 위한 변수
|
||||
@@ -493,6 +520,13 @@ namespace UVC.Factory
|
||||
transform.position = endPosition;
|
||||
transform.LookAt(targetPosition);
|
||||
|
||||
if (keepYRotation)
|
||||
{
|
||||
Vector3 finalEuler = transform.eulerAngles;
|
||||
finalEuler.y = 0;
|
||||
transform.rotation = Quaternion.Euler(finalEuler);
|
||||
}
|
||||
|
||||
// 회전 피봇 포인트 업데이트
|
||||
rotationPivot = targetPosition;
|
||||
|
||||
|
||||
@@ -3,11 +3,14 @@ using Gpm.Ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UVC.Core;
|
||||
using UVC.Factory.Component;
|
||||
using UVC.UI.Commands;
|
||||
using UVC.UI.Menu;
|
||||
using UVC.UI.Modal;
|
||||
using static UnityEngine.Rendering.DebugUI;
|
||||
|
||||
@@ -44,8 +47,8 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
}
|
||||
|
||||
|
||||
inputField.onEndEdit.AddListener(OnInputFieldChanged);
|
||||
//inputField.onSubmit.AddListener(OnInputFieldChanged);
|
||||
//inputField.onEndEdit.AddListener(OnInputFieldChanged);
|
||||
inputField.onSubmit.AddListener(OnInputFieldChanged);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
@@ -54,8 +57,8 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
{
|
||||
if (inputField != null)
|
||||
{
|
||||
inputField.onEndEdit.RemoveListener(OnInputFieldChanged);
|
||||
//inputField.onSubmit.RemoveListener(OnInputFieldChanged);
|
||||
//inputField.onEndEdit.RemoveListener(OnInputFieldChanged);
|
||||
inputField.onSubmit.RemoveListener(OnInputFieldChanged);
|
||||
}
|
||||
base.OnDestroy();
|
||||
}
|
||||
@@ -71,17 +74,15 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
Toast.Show("검색어는 3글자 이상 입력해주세요.", 2f);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"Input field changed: {text}");
|
||||
|
||||
|
||||
Predicate<InfiniteScrollData> func = (data) =>
|
||||
{
|
||||
if (data is ComponentListItemData itemData)
|
||||
{
|
||||
Debug.Log($"Filtering isCategory:{itemData.isCategory}, Contains:{itemData.generalName.Contains(text)}");
|
||||
return !itemData.isCategory && itemData.generalName.Contains(text);
|
||||
//원하는 조건일때 false를 반환해야 됨
|
||||
return !(!itemData.isCategory && itemData.generalName.Contains(text));
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
scrollList.SetFilter(func);
|
||||
@@ -95,7 +96,7 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
return;
|
||||
}
|
||||
|
||||
transform.SetAsFirstSibling();
|
||||
//transform.SetAsFirstSibling();
|
||||
|
||||
data?.Clear();
|
||||
|
||||
@@ -126,9 +127,22 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
scrollList.InsertData(data.ToArray());
|
||||
}
|
||||
|
||||
|
||||
public void OnClickFilter()
|
||||
{
|
||||
Debug.Log("Filter button clicked.");
|
||||
|
||||
var menuItems = new List<ContextMenuItemData>
|
||||
{
|
||||
// ContextMenuItemData 생성자를 사용하여 각 메뉴 항목을 정의합니다.
|
||||
// 생성자: (itemId, displayName, command, commandParameter)
|
||||
new ContextMenuItemData("Menu1", "Menu1", new DebugLogCommand("Menu1 click")),
|
||||
new ContextMenuItemData("Menu2", "Menu2", new DebugLogCommand("Menu2 click")),
|
||||
new ContextMenuItemData("Menu3", "Menu3", new DebugLogCommand("Menu3 click"))
|
||||
};
|
||||
|
||||
// 5. ContextMenuManager 싱글톤 인스턴스를 통해 메뉴를 표시합니다.
|
||||
ContextMenuManager.Instance.ShowMenu(menuItems, Input.mousePosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +158,17 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
public void OnClickClose()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
FactoryCameraController.Instance.Enable = true; // 카메라 컨트롤러 활성화
|
||||
}
|
||||
|
||||
public void OnClickClearText()
|
||||
{
|
||||
if (inputField != null)
|
||||
{
|
||||
inputField.text = string.Empty; // 입력 필드 초기화
|
||||
inputField.ActivateInputField(); // 입력 필드에 다시 포커스 설정
|
||||
if(scrollList != null) scrollList.SetFilter(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
|
||||
@@ -137,6 +137,11 @@ namespace UVC.Factory.Modal.ComponentList
|
||||
if (itemData.factoryObjectInfo != null)
|
||||
{
|
||||
FactoryObject? obj = FactoryObjectManager.Instance.FindById(itemData.factoryObjectInfo.Id);
|
||||
if(obj == null)
|
||||
{
|
||||
Toast.Show($"{itemData.factoryObjectInfo.Name} 객체를 찾을 수 없습니다.", 2f);
|
||||
return;
|
||||
}
|
||||
if (obj != null && obj.gameObject.activeSelf)
|
||||
{
|
||||
//객체로 이동
|
||||
|
||||
@@ -254,18 +254,19 @@ namespace UVC.Pool
|
||||
/// <summary>
|
||||
/// 현재 사용 중인 모든 아이템을 풀에 반환합니다.
|
||||
/// </summary>
|
||||
/// <param name="clearParent">true일 경우, 아이템의 부모를 RecycledItemContainer로 설정합니다.</param>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // 스테이지가 끝날 때 모든 적을 한번에 제거(반환)합니다.
|
||||
/// enemyPool.ReturnAll();
|
||||
/// </code>
|
||||
/// </example>
|
||||
public void ReturnAll()
|
||||
public void ReturnAll(bool clearParent = false)
|
||||
{
|
||||
int i, len = _activeItems.Count;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
ReturnItem(_activeItems[0]);
|
||||
ReturnItem(_activeItems[0], clearParent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
46
Assets/Scripts/UVC/UI/Menu/ContextMenuItemData.cs
Normal file
46
Assets/Scripts/UVC/UI/Menu/ContextMenuItemData.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using UVC.UI.Commands;
|
||||
|
||||
namespace UVC.UI.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// 컨텍스트 메뉴의 각 항목에 대한 정보를 담는 데이터 구조체입니다.
|
||||
/// 인스펙터에서 메뉴 항목을 쉽게 설정할 수 있도록 Serializable 특성을 가집니다.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ContextMenuItemData
|
||||
{
|
||||
/// <summary>
|
||||
/// 메뉴 아이템의 고유 식별자입니다.
|
||||
/// </summary>
|
||||
public string ItemId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// UI에 표시될 메뉴 아이템의 이름입니다. 다국어 키도 가능합니다.
|
||||
/// 이 키를 사용하여 실제 표시될 텍스트를 가져옵니다.
|
||||
/// </summary>
|
||||
public string DisplayName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 메뉴 아이템이 선택되었을 때 실행될 명령입니다.
|
||||
/// `ICommand` 인터페이스를 구현하는 객체여야 합니다.
|
||||
/// 실행할 동작이 없는 경우 null일 수 있습니다.
|
||||
/// </summary>
|
||||
public ICommand Command { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Command"/> 실행 시 전달될 파라미터입니다.
|
||||
/// 이 파라미터는 <see cref="ICommand.Execute"/> 호출 시 사용됩니다.
|
||||
/// </summary>
|
||||
public object? CommandParameter { get; set; }
|
||||
|
||||
public ContextMenuItemData(string ItemId, string DisplayName, ICommand Command, string CommandParameter = null)
|
||||
{
|
||||
this.ItemId = ItemId;
|
||||
this.DisplayName = DisplayName;
|
||||
this.Command = Command;
|
||||
this.CommandParameter = CommandParameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/Menu/ContextMenuItemData.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/Menu/ContextMenuItemData.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26a2492ee29d41140ac2268b2cd2195b
|
||||
259
Assets/Scripts/UVC/UI/Menu/ContextMenuManager.cs
Normal file
259
Assets/Scripts/UVC/UI/Menu/ContextMenuManager.cs
Normal file
@@ -0,0 +1,259 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UVC.Core; // SingletonScene을 사용하기 위함
|
||||
using UVC.Locale;
|
||||
using UVC.Pool; // GameObjectPool을 사용하기 위함
|
||||
|
||||
namespace UVC.UI.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// 컨텍스트 메뉴의 표시와 관리를 총괄하는 싱글톤 클래스입니다.
|
||||
/// SingletonScene을 상속받아 해당 씬 내에서 유일한 인스턴스를 보장합니다.
|
||||
/// 이 매니저는 코드 기반으로 동적으로 메뉴를 생성하고 표시하는 데 사용됩니다.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <b>사용 예시: 플레이어 캐릭터를 클릭했을 때 상호작용 메뉴를 표시하는 경우</b>
|
||||
/// <code>
|
||||
/// // 1. 메뉴 항목을 클릭했을 때 실행될 동작을 정의하는 Command 클래스를 구현합니다.
|
||||
/// public class LogCommand : ICommand
|
||||
/// {
|
||||
/// public void Execute(object parameter)
|
||||
/// {
|
||||
/// if (parameter != null)
|
||||
/// {
|
||||
/// Debug.Log("명령 실행: " + parameter.ToString());
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// Debug.Log("명령이 파라미터 없이 실행되었습니다.");
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // 2. 메뉴를 표시할 스크립트(예: PlayerInteraction.cs)를 작성합니다.
|
||||
/// public class PlayerInteraction : MonoBehaviour
|
||||
/// {
|
||||
/// void Update()
|
||||
/// {
|
||||
/// // 이 게임 오브젝트가 마우스 오른쪽 버튼으로 클릭되면 메뉴를 표시합니다.
|
||||
/// if (Input.GetMouseButtonDown(1))
|
||||
/// {
|
||||
/// // Raycast 등으로 이 오브젝트가 클릭되었는지 확인하는 로직이 필요합니다.
|
||||
/// // 여기서는 설명을 위해 바로 호출합니다.
|
||||
/// ShowPlayerMenu(Input.mousePosition);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// public void ShowPlayerMenu(Vector2 screenPosition)
|
||||
/// {
|
||||
/// // 3. 메뉴에 표시할 항목 리스트를 동적으로 생성합니다.
|
||||
/// var menuItems = new List<ContextMenuItemData>
|
||||
/// {
|
||||
/// // ContextMenuItemData 생성자를 사용하여 각 메뉴 항목을 정의합니다.
|
||||
/// // 생성자: (itemId, displayName, command, commandParameter)
|
||||
/// new ContextMenuItemData("player_attack", "공격", new LogCommand(), "플레이어가 '공격'을 선택했습니다."),
|
||||
/// new ContextMenuItemData("player_talk", "대화", new LogCommand(), "플레이어가 '대화'를 선택했습니다."),
|
||||
/// new ContextMenuItemData("player_inspect", "조사", new LogCommand(), "플레이어가 '조사'를 선택했습니다.")
|
||||
/// };
|
||||
///
|
||||
/// // 4. ContextMenuManager 싱글톤 인스턴스를 통해 메뉴를 표시합니다.
|
||||
/// ContextMenuManager.Instance.ShowMenu(menuItems, screenPosition);
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
/// <b>참고:</b>
|
||||
/// - `ContextMenuTrigger` 컴포넌트를 사용하면 Inspector에서 정적으로 메뉴를 설정할 수도 있습니다.
|
||||
/// - `DisplayName`에는 다국어 처리를 위한 키 값을 사용할 수 있습니다. (예: "menu_attack")
|
||||
/// </example>
|
||||
public class ContextMenuManager : SingletonScene<ContextMenuManager>
|
||||
{
|
||||
[Header("프리팹 설정")]
|
||||
[SerializeField]
|
||||
[Tooltip("컨텍스트 메뉴의 배경이 되는 Panel 프리팹입니다.")]
|
||||
private GameObject contextMenuPrefab;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("컨텍스트 메뉴의 각 항목으로 사용될 Button 프리팹입니다.")]
|
||||
private GameObject contextMenuItemPrefab;
|
||||
|
||||
[Header("캔버스 설정")]
|
||||
[SerializeField]
|
||||
[Tooltip("UI가 그려질 최상위 Canvas입니다. 메뉴가 다른 UI 위에 그려지도록 합니다.")]
|
||||
private Canvas mainCanvas;
|
||||
|
||||
// 현재 활성화된 컨텍스트 메뉴의 RectTransform
|
||||
private RectTransform _activeMenuRect;
|
||||
// 메뉴 항목들을 담을 부모 객체
|
||||
private Transform _menuItemContainer;
|
||||
|
||||
// 메뉴 항목 버튼들을 관리하기 위한 오브젝트 풀
|
||||
private ItemPool<Button> _menuItemPool;
|
||||
|
||||
private LocalizationManager _locManager; // 다국어 처리를 위한 LocalizationManager 인스턴스
|
||||
|
||||
/// <summary>
|
||||
/// 싱글톤이 초기화될 때 호출됩니다.
|
||||
/// </summary>
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
_locManager = LocalizationManager.Instance;
|
||||
if (_locManager == null)
|
||||
{
|
||||
// LocalizationManager가 필수적인 경우, 여기서 에러를 발생시키거나 게임을 중단시킬 수 있습니다.
|
||||
// 여기서는 경고만 기록하고 진행합니다.
|
||||
Debug.LogWarning("LocalizationManager 인스턴스를 찾을 수 없습니다. 메뉴 텍스트가 제대로 표시되지 않을 수 있습니다.");
|
||||
}
|
||||
|
||||
// 메뉴 항목을 담을 컨테이너를 생성하고 비활성화해 둡니다.
|
||||
var itemContainerGo = new GameObject("ContextMenuItemContainer");
|
||||
itemContainerGo.transform.SetParent(transform);
|
||||
_menuItemContainer = itemContainerGo.transform;
|
||||
itemContainerGo.SetActive(false);
|
||||
|
||||
// 메뉴 항목 프리팹을 사용하여 오브젝트 풀을 초기화합니다.
|
||||
// [성능 최적화]
|
||||
// 메뉴 항목을 반복적으로 생성/파괴하는 대신 풀을 사용하여 재활용합니다.
|
||||
// 이는 가비지 컬렉션을 줄여 성능을 향상시킵니다.
|
||||
_menuItemPool = new ItemPool<Button>(contextMenuItemPrefab, _menuItemContainer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 컨텍스트 메뉴를 화면에 표시합니다.
|
||||
/// </summary>
|
||||
/// <param name="items">표시할 메뉴 항목 데이터 리스트입니다.</param>
|
||||
/// <param name="position">메뉴가 표시될 화면 좌표입니다.</param>
|
||||
public void ShowMenu(List<ContextMenuItemData> items, Vector2 position)
|
||||
{
|
||||
// 기존 메뉴가 열려있으면 닫습니다.
|
||||
HideMenu();
|
||||
|
||||
// 메뉴 프리팹으로부터 인스턴스를 생성하고 Canvas 자식으로 설정합니다.
|
||||
var menuObject = Instantiate(contextMenuPrefab, mainCanvas.transform);
|
||||
_activeMenuRect = menuObject.GetComponent<RectTransform>();
|
||||
|
||||
// 메뉴 위치 설정
|
||||
_activeMenuRect.position = position;
|
||||
|
||||
// 메뉴 항목 채우기
|
||||
PopulateMenu(items);
|
||||
|
||||
// 메뉴가 화면 밖으로 나가지 않도록 위치를 조정합니다.
|
||||
AdjustMenuPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 열려있는 컨텍스트 메뉴를 닫습니다.
|
||||
/// </summary>
|
||||
public void HideMenu()
|
||||
{
|
||||
if (_activeMenuRect != null)
|
||||
{
|
||||
// 사용했던 모든 메뉴 항목 버튼을 풀에 반환합니다.
|
||||
_menuItemPool.ReturnAll(true);
|
||||
|
||||
// 활성화된 메뉴 오브젝트를 파괴합니다.
|
||||
Destroy(_activeMenuRect.gameObject);
|
||||
_activeMenuRect = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 전달받은 데이터로 메뉴 항목들을 생성합니다.
|
||||
/// </summary>
|
||||
/// <param name="items">메뉴 항목 데이터 리스트</param>
|
||||
private void PopulateMenu(List<ContextMenuItemData> items)
|
||||
{
|
||||
foreach (var itemData in items)
|
||||
{
|
||||
// 풀에서 메뉴 항목 버튼을 가져옵니다.
|
||||
Button menuItemButton = _menuItemPool.GetItem(true, _activeMenuRect);
|
||||
|
||||
// 버튼의 텍스트를 설정합니다.
|
||||
TMP_Text buttonText = menuItemButton.GetComponentInChildren<TMP_Text>();
|
||||
if (buttonText != null)
|
||||
{
|
||||
if (_locManager != null)
|
||||
{
|
||||
buttonText.text = _locManager.GetString(itemData.DisplayName);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonText.text = itemData.DisplayName;
|
||||
}
|
||||
}
|
||||
|
||||
// 버튼 클릭 이벤트를 설정합니다.
|
||||
// 기존 리스너를 모두 제거한 후 새로 추가하여 중복 호출을 방지합니다.
|
||||
menuItemButton.onClick.RemoveAllListeners();
|
||||
menuItemButton.onClick.AddListener(() =>
|
||||
{
|
||||
// 항목을 클릭하면 메뉴를 닫고, 설정된 액션을 실행합니다.
|
||||
HideMenu();
|
||||
itemData.Command.Execute(itemData.CommandParameter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 메뉴가 화면 경계를 벗어나지 않도록 위치를 조정합니다.
|
||||
/// </summary>
|
||||
private void AdjustMenuPosition()
|
||||
{
|
||||
// 레이아웃이 업데이트되도록 한 프레임 강제로 기다립니다.
|
||||
Canvas.ForceUpdateCanvases();
|
||||
|
||||
Vector3[] corners = new Vector3[4];
|
||||
_activeMenuRect.GetWorldCorners(corners);
|
||||
|
||||
float menuWidth = corners[2].x - corners[0].x;
|
||||
float menuHeight = corners[1].y - corners[3].y;
|
||||
|
||||
Vector2 anchoredPosition = _activeMenuRect.anchoredPosition;
|
||||
|
||||
// 오른쪽 경계 확인
|
||||
if (_activeMenuRect.position.x + menuWidth > Screen.width)
|
||||
{
|
||||
anchoredPosition.x -= menuWidth;
|
||||
}
|
||||
|
||||
// 아래쪽 경계 확인
|
||||
if (_activeMenuRect.position.y - menuHeight < 0)
|
||||
{
|
||||
anchoredPosition.y += menuHeight;
|
||||
}
|
||||
|
||||
_activeMenuRect.anchoredPosition = anchoredPosition;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 메뉴가 열려있지 않으면 아무 작업도 수행하지 않습니다.
|
||||
if (_activeMenuRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ESC 키를 누르면 메뉴를 닫습니다.
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
HideMenu();
|
||||
return; // 메뉴가 닫혔으므로 아래 로직은 실행할 필요가 없습니다.
|
||||
}
|
||||
|
||||
// 메뉴가 열려있고, 마우스 왼쪽/오른쪽 버튼이 눌렸을 때
|
||||
// 커서가 메뉴 위에 있지 않다면 메뉴를 닫습니다.
|
||||
if (_activeMenuRect != null && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)))
|
||||
{
|
||||
if (!RectTransformUtility.RectangleContainsScreenPoint(_activeMenuRect, Input.mousePosition, mainCanvas.worldCamera))
|
||||
{
|
||||
HideMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/Menu/ContextMenuManager.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/Menu/ContextMenuManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b5b3bd4b972b154d97b0d27797d1dd3
|
||||
35
Assets/Scripts/UVC/UI/Menu/ContextMenuTrigger.cs
Normal file
35
Assets/Scripts/UVC/UI/Menu/ContextMenuTrigger.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UVC.UI.Menu
|
||||
{
|
||||
/// <summary>
|
||||
/// UI 요소에 붙여서 왼쪽 또는 오른쪽 클릭 시 컨텍스트 메뉴를 표시하는 역할을 합니다.
|
||||
/// IPointerClickHandler 인터페이스를 구현하여 클릭 이벤트를 감지합니다.
|
||||
/// </summary>
|
||||
public class ContextMenuTrigger : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 인스펙터에서 이 트리거에 연결할 메뉴 항목들을 설정합니다.
|
||||
/// </summary>
|
||||
[Tooltip("이 트리거가 표시할 컨텍스트 메뉴 항목 리스트입니다.")]
|
||||
public List<ContextMenuItemData> menuItems = new List<ContextMenuItemData>();
|
||||
|
||||
/// <summary>
|
||||
/// 포인터(마우스/터치)가 이 UI 요소 위에서 클릭되었을 때 호출됩니다.
|
||||
/// </summary>
|
||||
/// <param name="eventData">클릭 이벤트에 대한 데이터입니다.</param>
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// 왼쪽 클릭 또는 오른쪽 클릭 시 메뉴를 표시합니다.
|
||||
if (eventData.button == PointerEventData.InputButton.Left || eventData.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
// ContextMenuManager 싱글톤 인스턴스를 통해 메뉴를 표시하도록 요청합니다.
|
||||
// 메뉴 항목 데이터와 현재 마우스 위치를 전달합니다.
|
||||
ContextMenuManager.Instance.ShowMenu(menuItems, eventData.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/Menu/ContextMenuTrigger.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/Menu/ContextMenuTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3207fc8fdfbc11542a55f86e3f66ab51
|
||||
@@ -120,17 +120,17 @@ namespace UVC.UI.Menu
|
||||
{
|
||||
// LocalizationManager가 필수적인 경우, 여기서 에러를 발생시키거나 게임을 중단시킬 수 있습니다.
|
||||
// 여기서는 경고만 기록하고 진행합니다.
|
||||
Debug.LogError("LocalizationManager 인스턴스를 찾을 수 없습니다. 메뉴 텍스트가 제대로 표시되지 않을 수 있습니다.");
|
||||
Debug.LogWarning("LocalizationManager 인스턴스를 찾을 수 없습니다. 메뉴 텍스트가 제대로 표시되지 않을 수 있습니다.");
|
||||
}
|
||||
|
||||
// Inspector에서 할당된 참조 확인
|
||||
if (menuItemPrefab == null)
|
||||
{
|
||||
Debug.LogError("menuItemPrefab이 Inspector에서 할당되지 않았습니다.", this);
|
||||
Debug.LogWarning("menuItemPrefab이 Inspector에서 할당되지 않았습니다.", this);
|
||||
}
|
||||
if (subMenuItemPrefab == null)
|
||||
{
|
||||
Debug.LogError("subMenuItemPrefab이 Inspector에서 할당되지 않았습니다.", this);
|
||||
Debug.LogWarning("subMenuItemPrefab이 Inspector에서 할당되지 않았습니다.", this);
|
||||
}
|
||||
if (menuSeparatorPrefab == null)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ namespace UVC.UI.Menu
|
||||
// 메뉴 컨테이너 확인
|
||||
if (menuContainer == null)
|
||||
{
|
||||
Debug.LogError("menuContainer가 Inspector에서 할당되지 않았습니다. Inspector에서 참조를 설정해주세요.", this);
|
||||
Debug.LogWarning("menuContainer가 Inspector에서 할당되지 않았습니다. Inspector에서 참조를 설정해주세요.", this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user