2026-04-03 미니맵 추가중
This commit is contained in:
52
Assets/02_Scripts/UI/Minimap/MinimapMarker.cs
Normal file
52
Assets/02_Scripts/UI/Minimap/MinimapMarker.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MinimapMarker : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Sprite _iconSprite;
|
||||
[SerializeField] private Color _iconColor = Color.red;
|
||||
[SerializeField] private Vector2 _iconSize = new Vector2(10f, 10f);
|
||||
[SerializeField] private bool _rotateWithTarget = false;
|
||||
|
||||
private RectTransform _iconRect;
|
||||
private Transform _target; // 추적할 월드 오브젝트
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_target = transform;
|
||||
}
|
||||
|
||||
public void Initialize(MinimapManager manager)
|
||||
{
|
||||
// 마커 아이콘 UI 생성
|
||||
GameObject iconObj = new GameObject($"Marker_{gameObject.name}");
|
||||
iconObj.transform.SetParent(manager.MarkerContainer, false);
|
||||
|
||||
Image img = iconObj.AddComponent<Image>();
|
||||
img.sprite = _iconSprite;
|
||||
img.color = _iconColor;
|
||||
|
||||
_iconRect = iconObj.GetComponent<RectTransform>();
|
||||
_iconRect.sizeDelta = _iconSize;
|
||||
|
||||
manager.RegisterMarker(this);
|
||||
}
|
||||
|
||||
public void UpdatePosition(MinimapManager manager)
|
||||
{
|
||||
if (_iconRect == null || _target == null) return;
|
||||
|
||||
_iconRect.anchoredPosition = manager.WorldToMapPos(_target.position);
|
||||
|
||||
if (_rotateWithTarget)
|
||||
{
|
||||
_iconRect.localRotation = Quaternion.Euler(0, 0, -_target.eulerAngles.y);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_iconRect != null)
|
||||
Destroy(_iconRect.gameObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user