123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using ObjectScripts;
- namespace UIScripts
- {
- public class Timeline : MonoBehaviour
- {
- ///<summary>
- /// Manager to control and get GameTimestamp
- ///</summary>
- [SerializeField] AbstractManager ManagerObject;
- ///<summary>
- /// Timeline slider
- ///</summary>
- [SerializeField] UnityEngine.UI.Slider GameTimelineSlider;
- ///<summary>
- /// Text for showing current and newest timestamp
- ///</summary>
- [SerializeField] UnityEngine.UI.Text TimestampText;
- ///<summary>
- /// Start of time interval
- ///</summary>
- private double StartChunk;
- ///<summary>
- /// End of time interval
- ///</summary>
- private double EndChunk;
- ///<summary>
- ///
- ///</summary>
- private bool Dragging = false;
- ///<summary>
- /// Current Gametimestamp
- ///</summary>
- private float Gametimestamp = 0;
- ///<summary>
- /// Current newest timestamp
- ///</summary>
- private float NewestTimestamp;
- ///<summary>
- /// Manager UpdateRate
- ///</summary>
- private float UpdateRate;
- void Start()
- {
- UpdateRate = ManagerObject.UpdateRateInSeconds;
- StartCoroutine(ChangeSlider());
- }
- ///<summary>
- /// set slider values each 1/updaterate seconds
- ///</summary>
- private IEnumerator ChangeSlider()
- {
- while (true)
- {
- StartChunk = ManagerObject.startChunk;
- EndChunk = ManagerObject.endChunk;
- Gametimestamp = (float)ManagerObject.GameTimestamp;
- NewestTimestamp = (float)ManagerObject.NewestTimestamp;
- if (!Dragging)
- {
- float minTimeStamp = double.IsNaN(StartChunk) ? (float)ManagerObject.EarliestTimestamp : (float)StartChunk;
- float maxTimeStamp = double.IsNaN(EndChunk) ? (float)ManagerObject.NewestTimestamp : (float)EndChunk;
- GameTimelineSlider.maxValue = maxTimeStamp;
- GameTimelineSlider.minValue = minTimeStamp;
- GameTimelineSlider.SetValueWithoutNotify(Gametimestamp);
- }
- TimestampText.text = Gametimestamp.ToString("0.00") + " : " + NewestTimestamp.ToString("0.00");
- yield return new WaitForSecondsRealtime(UpdateRate);
- }
- }
- ///<summary>
- /// On dragging slider
- ///</summary>
- public void BeginDrag()
- {
- Dragging = true;
- }
- ///<summary>
- /// on slider value change
- ///</summary>
- public void TimelineValueChanged()
- {
- if (!Dragging)
- {
- ManagerObject.JumpToTimestamp(GameTimelineSlider.value);
- }
- }
- ///<summary>
- /// on stop dragging slider
- ///</summary>
- public void StopDrag()
- {
- GameTimelineSlider.SetValueWithoutNotify(GameTimelineSlider.value);
- ManagerObject.JumpToTimestamp(GameTimelineSlider.value);
- Dragging = false;
- }
- }
- }
|