EventSlider.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using ObjectScripts;
  5. using CSVReader;
  6. namespace UIScripts
  7. {
  8. public class EventSlider : MonoBehaviour
  9. {
  10. ///<summary>
  11. /// EventHandler to get Events from
  12. ///</summary>
  13. [SerializeField] AbstractEventHandler EventHandler;
  14. ///<summary>
  15. /// Canvas for each moving Timestamp
  16. ///</summary>
  17. [SerializeField] GameObject TimestampCanvas;
  18. ///<summary>
  19. /// Timeline slider
  20. ///</summary>
  21. [SerializeField] UnityEngine.UI.Slider Slider;
  22. ///<summary>
  23. /// Manager to control
  24. ///</summary>
  25. [SerializeField] AbstractManager Manager;
  26. ///<summary>
  27. /// Sprites for each Eventtype
  28. ///</summary>
  29. [SerializeField] Sprite[] EventImages;
  30. ///<summary>
  31. /// Dictionary to keep track of each timestamp canvas
  32. ///</summary>
  33. Dictionary<double, GameObject> Timestamps;
  34. ///<summary>
  35. /// number of known events
  36. ///</summary>
  37. private int KnownCount = 0;
  38. ///<summary>
  39. /// Left timeline postion
  40. ///</summary>
  41. private Vector3 MinPositon;
  42. void Start()
  43. {
  44. Timestamps = new Dictionary<double, GameObject>();
  45. MinPositon = TimestampCanvas.transform.position;
  46. }
  47. // Update is called once per frame
  48. void Update()
  49. {
  50. //for each unknown event
  51. for (int i = KnownCount; i < EventHandler.EventList.Count; i++)
  52. {
  53. EventObject eventObject = EventHandler.EventList[i].Event;
  54. double timestamp = eventObject.TimestampStart;
  55. GameObject obj;
  56. if (Timestamps.TryGetValue(timestamp, out obj))
  57. {
  58. EventStamp eventStamp = obj.GetComponent<EventStamp>();
  59. eventStamp.addContent(EventHandler.EventList[i], EventImages[(int)eventObject.Type]);
  60. }
  61. else
  62. {
  63. obj = Instantiate(TimestampCanvas, TimestampCanvas.transform.localPosition, Quaternion.Euler(0, 0, 0), transform);
  64. obj.transform.localRotation = Quaternion.Euler(0, 0, 0);
  65. obj.SetActive(true);
  66. EventStamp eventStamp = obj.GetComponent<EventStamp>();
  67. eventStamp.Slider = Slider;
  68. eventStamp.Manager = Manager;
  69. eventStamp.Timestamp = eventObject.TimestampStart;
  70. eventStamp.addContent(EventHandler.EventList[i], EventImages[(int)eventObject.Type]);
  71. Timestamps.Add(timestamp, obj);
  72. obj.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -obj.GetComponent<RectTransform>().sizeDelta.y);
  73. }
  74. KnownCount += 1;
  75. }
  76. }
  77. }
  78. }