public void Initialize(GlobalTimeData data) { while (SegmentsHolder.childCount > 0) { DestroyImmediate(SegmentsHolder.GetChild(0).gameObject); } Segments = new TimelineSegmentData[10]; for (int i = 0; i < Segments.Length; i++) { Segments[i] = new TimelineSegmentData() { Position = (float)i / (Segments.Length - 1), Text = "" }; } Segments[0].Text = data.StartTime.ToString("F2"); Segments[Segments.Length - 1].Text = data.EndTime.ToString("F2"); foreach (var segment in Segments) { var go = Instantiate <GameObject>(SegmentPrefab); go.transform.parent = SegmentsHolder; go.GetComponent <TimelineSegment>().SetData(segment); } }
public void SetData(TimelineSegmentData data) { RectTransform rTransform = transform as RectTransform; rTransform.localPosition = new Vector3((data.Position - .5f) * (SliderWidth - 22), 1); Text.text = data.Text; }