using UnityEngine; using System.Collections; using UnityEngine.UI; public static class UIHelper { public static void AddScrollText(Text prefab, RectTransform contentRoot, string text, MScrollRect scrollRect) { if (contentRoot == null) return; var listItem = GameObject.Instantiate(prefab, contentRoot, false); listItem.text = text; if (scrollRect != null && scrollRect.isActiveAndEnabled) scrollRect.StartCoroutine(ScrollToBottom(scrollRect)); } public static IEnumerator ScrollToBottom(MScrollRect scrollRect) { yield return null; if (scrollRect != null && scrollRect.isActiveAndEnabled && !scrollRect.isDrag) scrollRect.normalizedPosition = new Vector2(0, 0); } }