using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using WIFramework.UI; public class Panel_MessageList : PanelBase { public GameObject uEntryPrefab; private RectTransform mOwnTransform; private int mMaxMessages = 50; private int mCounter = 0; private void Awake() { mOwnTransform = this.GetComponent(); } private void Start() { foreach (var v in mOwnTransform.GetComponentsInChildren()) { if (v != mOwnTransform) { v.name = "Element " + mCounter; mCounter++; } } } public void AddTextEntry(string text) { GameObject ngp = Instantiate(uEntryPrefab); Text t = ngp.GetComponentInChildren(); t.text = text; RectTransform transform = ngp.GetComponent(); transform.SetParent(mOwnTransform, false); GameObject go = transform.gameObject; go.name = "Element " + mCounter; mCounter++; } /// /// Destroys old messages if needed and repositions the existing messages. /// private void Update() { int destroy = mOwnTransform.childCount - mMaxMessages; for (int i = 0; i < destroy; i++) { var child = mOwnTransform.GetChild(i).gameObject; Destroy(child); } } }