上海杨浦大连路地铁站单机版电子沙盘
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.
 
 
 
 

58 lines
1.6 KiB

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<Slider>();
tagPrefab = Resources.Load("UI/TagItem") as GameObject;
parentWidth = tagParent.GetComponent<RectTransform>().rect.width;
}
public void SetSlider(float maxValue,List<TagData> 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<RectTransform>().anchoredPosition = new Vector2(posX, 0);
item.GetComponent<TagItem>().SetTag(tag);
}
public void RemoveItem(TagData tag)
{
foreach (Transform item in tagParent)
{
var tagData=item.GetComponent<TagItem>().tagData;
if (tag.time== tagData.time)
{
Destroy(item.gameObject);
}
}
}
public void UpdateSlider(float value)
{
timeLine.value = value;
}
}