You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class LogicTrayUI : MonoBehaviour
{
[SerializeField]
protected List<LogicBlock> list;
[SerializeField]
protected GameObject Prefab;
[SerializeField]
protected int insertIndex = -1;
[SerializeField]
private Transform content;
public void Start()
{
UpdateDisplay();
}
public void OnHoverStart(BagItem item, RectTransform rect)
{
insertIndex = content.childCount;
UpdateDisplay();
}
public void OnHoverEnd(BagItem item, RectTransform rect)
{
insertIndex = -1;
UpdateDisplay();
}
public void OnHoverUpdate(BagItem item, RectTransform rect)
{
foreach(Transform child in content)
{
RectTransform childRect = child as RectTransform;
if (child == null)
continue;
if (rect.GlobalRect().Overlaps(childRect.GlobalRect()))
{
if (insertIndex != child.GetSiblingIndex())
{
insertIndex = child.GetSiblingIndex();
UpdateDisplay();
}
break;
}
}
}
[ContextMenu("Update Display")]
public void UpdateDisplay()
{
int destroyedCount = content.childCount;
foreach (Transform child in content)
Destroy(child.gameObject);
foreach(LogicBlock element in list)
{
GameObject elementObject = Instantiate(Prefab, content);
elementObject.GetComponentInChildren<TextMeshProUGUI>().text = element.name;
}
if (insertIndex != -1)
{
GameObject elementObject = Instantiate(Prefab, content);
elementObject.GetComponentInChildren<TextMeshProUGUI>().text = "insert";
elementObject.GetComponentInChildren<Image>().color = new Color(0.5f, 0.5f, 0.5f, 0.25f);
elementObject.transform.SetSiblingIndex(destroyedCount + insertIndex);
}
}
}