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.

50 lines
1.2 KiB

using UnityEngine;
using UnityEngine.UI;
public class AutoScrollTest : MonoBehaviour
{
public Text textPrefab;
public RectTransform contentRoot;
public MScrollRect scrollRect;
private float interval = 1;
private float time = 0;
public int currentChiCount;
public int lastChiCount;
private void Start()
{
currentChiCount = contentRoot.transform.childCount;
lastChiCount= contentRoot.transform.childCount;
}
private void Update()
{
//time += Time.deltaTime;
//if (time >= interval)
//{
// AddText();
// time = 0;
//}
currentChiCount = contentRoot.transform.childCount;
if (currentChiCount != lastChiCount)
{
float height = contentRoot.rect.height;
height += 25;
contentRoot.sizeDelta = new Vector2 (contentRoot.sizeDelta.x, height);
StartCoroutine(UIHelper.ScrollToBottom(scrollRect));
lastChiCount = currentChiCount;
}
}
public void AddText()
{
UIHelper.AddScrollText(textPrefab, contentRoot, time.ToString(), scrollRect);
}
}