Files
Studio/Assets/Scripts/Studio/UI/TreeView/HierarchyPopupScrollViewItem.cs
2025-05-29 15:56:38 +09:00

43 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using TMPro;
namespace Studio.HierarchyTree
{
public class HierarchyPopupScrollViewItem : UnityEngine.MonoBehaviour
{
private HierarchyScrollRect scrollRect;
private TMP_Text text;
private Canvas canvas;
// Start is called before the first frame update
void Awake()
{
canvas = GetComponentInParent<Canvas>();
text = GetComponentInChildren<TMP_Text>();
scrollRect = GetComponentInParent<HierarchyScrollRect>();
//scrollRect.itemPopup = gameObject;
gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (scrollRect.sourceItem != null)
{
text.text = scrollRect.sourceItem.name;
}
// Position popup at the mouse position (convert screen point to UI point)
RectTransformUtility.ScreenPointToLocalPointInRectangle(
canvas.transform as RectTransform,
Input.mousePosition,
canvas.worldCamera,
out Vector2 pos
);
transform.position = canvas.transform.TransformPoint(pos);
}
}
}