using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TimeLineManager : MonoBehaviour { private Slider timeLine; public Transform tagParent; private GameObject tagPrefab; private float parentWidth; // Use this for initialization void Awake () { timeLine = GetComponent(); tagPrefab = Resources.Load("UI/TagItem") as GameObject; parentWidth = tagParent.GetComponent().rect.width; } public void SetSlider(float maxValue,List list) { //设置时间轴 timeLine.maxValue = maxValue; timeLine.value = 0; //设置标签 foreach (Transform item in tagParent) { Destroy(item.gameObject); } foreach (var tag in list) { AddItem(tag); } } public void AddItem(TagData tag) { GameObject item = Instantiate(tagPrefab, tagParent) as GameObject; var posX = (tag.time / timeLine.maxValue) * parentWidth; item.GetComponent().anchoredPosition = new Vector2(posX, 0); item.GetComponent().SetTag(tag); } public void RemoveItem(TagData tag) { foreach (Transform item in tagParent) { var tagData=item.GetComponent().tagData; if (tag.time== tagData.time) { Destroy(item.gameObject); } } } public void UpdateSlider(float value) { timeLine.value = value; } }