Files
Deroc_Virtual_3D/Assets/FPS/Scripts/UI/UITable.cs
T
Alex38Lyon 878ea46cac update
2025-06-03 12:00:47 +02:00

39 lines
1.3 KiB
C#

using UnityEngine;
namespace Unity.FPS.UI
{
// The component that is used to display the Objectives, the Notification and the game messages like a list
// When a new one is created, the previous ones move down to make room for the new one
public class UITable : MonoBehaviour
{
[Tooltip("How much space should there be between items?")]
public float Offset;
[Tooltip("Add new the new items below existing items.")]
public bool Down;
public void UpdateTable(GameObject newItem)
{
if (newItem != null)
newItem.GetComponent<RectTransform>().localScale = Vector3.one;
float height = 0;
for (int i = 0; i < transform.childCount; i++)
{
RectTransform child = transform.GetChild(i).GetComponent<RectTransform>();
Vector2 size = child.sizeDelta;
height += Down ? -(1 - child.pivot.y) * size.y : (1 - child.pivot.y) * size.y;
if (i != 0)
height += Down ? -Offset : Offset;
Vector2 newPos = Vector2.zero;
newPos.y = height;
newPos.x = 0;//-child.pivot.x * size.x * hi.localScale.x;
child.anchoredPosition = newPos;
}
}
}
}