EventTimestamp.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using ObjectScripts;
  5. using CSVReader;
  6. using System;
  7. namespace UIScripts
  8. {
  9. public class EventTimestamp
  10. {
  11. //Not used anymore
  12. ///<summary>
  13. ///
  14. ///</summary>
  15. public UnityEngine.UI.Dropdown TimestampDropdown;
  16. ///<summary>
  17. ///
  18. ///</summary>
  19. double Timestamp;
  20. ///<summary>
  21. ///
  22. ///</summary>
  23. public UnityEngine.UI.Button JumpButton;
  24. ///<summary>
  25. ///
  26. ///</summary>
  27. GameObject EventDropdownPrefab;
  28. ///<summary>
  29. ///
  30. ///</summary>
  31. private List<Action> Actions;
  32. ///<summary>
  33. ///
  34. ///</summary>
  35. public List<uint> EventIDs;
  36. ///<summary>
  37. ///
  38. ///</summary>
  39. UnityEngine.UI.Slider GameTimelineSlider;
  40. ///<summary>
  41. ///
  42. ///</summary>
  43. RectTransform SliderRectTransform;
  44. ///<summary>
  45. ///
  46. ///</summary>
  47. public EventTimestamp(double timestamp, GameObject eventDropdownPrefab, UnityEngine.UI.Slider gameTimelineSlider)
  48. {
  49. EventDropdownPrefab = eventDropdownPrefab;
  50. TimestampDropdown = EventDropdownPrefab.GetComponent<UnityEngine.UI.Dropdown>();
  51. Timestamp = timestamp;
  52. JumpButton = EventDropdownPrefab.GetComponentInChildren<UnityEngine.UI.Button>();
  53. JumpButton.onClick.AddListener(() => this.JumpButtonClicked());
  54. Actions = new List<Action>();
  55. EventIDs = new List<uint>();
  56. GameTimelineSlider = gameTimelineSlider;
  57. SliderRectTransform = GameTimelineSlider.GetComponent<RectTransform>();
  58. EventDropdownPrefab.transform.localScale = Vector3.one;
  59. EventDropdownPrefab.transform.localRotation = Quaternion.Euler(0, 0, 0);
  60. }
  61. ///<summary>
  62. ///
  63. ///</summary>
  64. public void addEvent(AbstractEventScript e, Sprite sprite, Action p)
  65. {
  66. Actions.Add(p);
  67. EventIDs.Add(e.ID);
  68. TimestampDropdown.options.Add(new UnityEngine.UI.Dropdown.OptionData(sprite));
  69. }
  70. ///<summary>
  71. ///
  72. ///</summary>
  73. private void JumpButtonClicked()
  74. {
  75. Actions[TimestampDropdown.value]();
  76. }
  77. ///<summary>
  78. ///
  79. ///</summary>
  80. public void SetEventButtonPositon(AbstractEventScript e, GameObject UICamera)
  81. {
  82. Transform GameTimeLineSliderTransform = GameTimelineSlider.transform;
  83. Vector3 buttonPos = this.EventDropdownPrefab.transform.localPosition;
  84. double timestamp = e.Event.TimestampStart;
  85. Vector2 leftCord = new Vector2(GameTimeLineSliderTransform.localPosition.x - SliderRectTransform.sizeDelta.x * SliderRectTransform.pivot.x, GameTimeLineSliderTransform.localPosition.y - SliderRectTransform.sizeDelta.y * SliderRectTransform.pivot.y);
  86. float minValue = GameTimelineSlider.minValue;
  87. float maxValue = GameTimelineSlider.maxValue;
  88. if (float.IsInfinity(minValue) || float.IsInfinity(maxValue) || float.IsNaN(minValue) || float.IsNaN(maxValue))
  89. {
  90. minValue = 0;
  91. maxValue = 1;
  92. }
  93. float normalized = (float)(timestamp - minValue) / (maxValue - minValue);
  94. if (float.IsNaN(normalized))
  95. normalized = -1;
  96. if (float.IsInfinity(normalized))
  97. normalized = -1;
  98. if (normalized >= 0 && normalized < 1)
  99. {
  100. EventDropdownPrefab.SetActive(true);
  101. EventDropdownPrefab.transform.localPosition = new Vector3(leftCord.x + SliderRectTransform.sizeDelta.x * normalized, leftCord.y + 30, 0);
  102. }
  103. else
  104. {
  105. EventDropdownPrefab.SetActive(false);
  106. EventDropdownPrefab.transform.localPosition = new Vector3(0, 0, -20);
  107. // button.GetComponent<UnityEngine.UI.Button>().enabled = false;
  108. // button.GetComponent<UnityEngine.UI.Image>().enabled = false;
  109. }
  110. }
  111. }
  112. }