123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using ObjectScripts;
- using CSVReader;
- using System;
- namespace UIScripts
- {
- public class EventTimestamp
- {
- //Not used anymore
- ///<summary>
- ///
- ///</summary>
- public UnityEngine.UI.Dropdown TimestampDropdown;
- ///<summary>
- ///
- ///</summary>
- double Timestamp;
- ///<summary>
- ///
- ///</summary>
- public UnityEngine.UI.Button JumpButton;
- ///<summary>
- ///
- ///</summary>
- GameObject EventDropdownPrefab;
- ///<summary>
- ///
- ///</summary>
- private List<Action> Actions;
- ///<summary>
- ///
- ///</summary>
- public List<uint> EventIDs;
- ///<summary>
- ///
- ///</summary>
- UnityEngine.UI.Slider GameTimelineSlider;
- ///<summary>
- ///
- ///</summary>
- RectTransform SliderRectTransform;
- ///<summary>
- ///
- ///</summary>
- public EventTimestamp(double timestamp, GameObject eventDropdownPrefab, UnityEngine.UI.Slider gameTimelineSlider)
- {
- EventDropdownPrefab = eventDropdownPrefab;
- TimestampDropdown = EventDropdownPrefab.GetComponent<UnityEngine.UI.Dropdown>();
- Timestamp = timestamp;
- JumpButton = EventDropdownPrefab.GetComponentInChildren<UnityEngine.UI.Button>();
- JumpButton.onClick.AddListener(() => this.JumpButtonClicked());
- Actions = new List<Action>();
- EventIDs = new List<uint>();
- GameTimelineSlider = gameTimelineSlider;
- SliderRectTransform = GameTimelineSlider.GetComponent<RectTransform>();
- EventDropdownPrefab.transform.localScale = Vector3.one;
- EventDropdownPrefab.transform.localRotation = Quaternion.Euler(0, 0, 0);
- }
- ///<summary>
- ///
- ///</summary>
- public void addEvent(AbstractEventScript e, Sprite sprite, Action p)
- {
- Actions.Add(p);
- EventIDs.Add(e.ID);
- TimestampDropdown.options.Add(new UnityEngine.UI.Dropdown.OptionData(sprite));
- }
- ///<summary>
- ///
- ///</summary>
- private void JumpButtonClicked()
- {
- Actions[TimestampDropdown.value]();
- }
- ///<summary>
- ///
- ///</summary>
- public void SetEventButtonPositon(AbstractEventScript e, GameObject UICamera)
- {
- Transform GameTimeLineSliderTransform = GameTimelineSlider.transform;
- Vector3 buttonPos = this.EventDropdownPrefab.transform.localPosition;
- double timestamp = e.Event.TimestampStart;
- Vector2 leftCord = new Vector2(GameTimeLineSliderTransform.localPosition.x - SliderRectTransform.sizeDelta.x * SliderRectTransform.pivot.x, GameTimeLineSliderTransform.localPosition.y - SliderRectTransform.sizeDelta.y * SliderRectTransform.pivot.y);
- float minValue = GameTimelineSlider.minValue;
- float maxValue = GameTimelineSlider.maxValue;
- if (float.IsInfinity(minValue) || float.IsInfinity(maxValue) || float.IsNaN(minValue) || float.IsNaN(maxValue))
- {
- minValue = 0;
- maxValue = 1;
- }
- float normalized = (float)(timestamp - minValue) / (maxValue - minValue);
- if (float.IsNaN(normalized))
- normalized = -1;
- if (float.IsInfinity(normalized))
- normalized = -1;
- if (normalized >= 0 && normalized < 1)
- {
- EventDropdownPrefab.SetActive(true);
- EventDropdownPrefab.transform.localPosition = new Vector3(leftCord.x + SliderRectTransform.sizeDelta.x * normalized, leftCord.y + 30, 0);
- }
- else
- {
- EventDropdownPrefab.SetActive(false);
- EventDropdownPrefab.transform.localPosition = new Vector3(0, 0, -20);
- // button.GetComponent<UnityEngine.UI.Button>().enabled = false;
- // button.GetComponent<UnityEngine.UI.Image>().enabled = false;
- }
- }
- }
- }
|