TimelineSwimlane.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using TMPro;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. namespace TimelineViewer
  8. {
  9. public class TimelineSwimlane : MonoBehaviour
  10. {
  11. [HideInInspector][SerializeField] GameObject swimLaneContent;
  12. [HideInInspector][SerializeField] GameObject swimLaneContentItemPrefab;
  13. [HideInInspector][SerializeField] GameObject swimLaneContentItemLabelPrefab;
  14. [HideInInspector][SerializeField] GameObject swimLaneRulePrefab;
  15. [HideInInspector][SerializeField] List<GameObject> swimlaneItems;
  16. public List<GameObject> rulerSections = new List<GameObject>();
  17. public SwimlaneItemLabel SetupSwimlane(string laneName, Transform parent, int timeCount)
  18. {
  19. var go = Instantiate(swimLaneContentItemLabelPrefab, parent, false);
  20. var swimlaneLabel = go.GetComponentInChildren<TextMeshProUGUI>();
  21. swimlaneLabel.text = laneName;
  22. for (int i = 0; i < timeCount; i++)
  23. {
  24. Instantiate(swimLaneRulePrefab, swimLaneContent.transform, false);
  25. }
  26. return go.GetComponent<SwimlaneItemLabel>();
  27. }
  28. public void AddTimelineItem(string title, double pos, double length)
  29. {
  30. int posInt = (int)Math.Truncate(pos);
  31. float posfl = (float)pos - posInt;
  32. var rulerItem = swimLaneContent.transform.GetChild(posInt);
  33. var item = Instantiate(swimLaneContentItemPrefab, rulerItem, false);
  34. item.transform.localPosition = item.transform.localPosition + new Vector3(posfl * 100f, 0, 0);
  35. var timelineItem = item.GetComponent<TimelineContentItem>();
  36. timelineItem.SetupTitle(title);
  37. timelineItem.AdjustLength(length);
  38. }
  39. }
  40. }