using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ObjectScripts;
namespace UIScripts
{
public class Timeline : MonoBehaviour
{
///
/// Manager to control and get GameTimestamp
///
[SerializeField] AbstractManager ManagerObject;
///
/// Timeline slider
///
[SerializeField] UnityEngine.UI.Slider GameTimelineSlider;
///
/// Text for showing current and newest timestamp
///
[SerializeField] UnityEngine.UI.Text TimestampText;
///
/// Start of time interval
///
private double StartChunk;
///
/// End of time interval
///
private double EndChunk;
///
///
///
private bool Dragging = false;
///
/// Current Gametimestamp
///
private float Gametimestamp = 0;
///
/// Current newest timestamp
///
private float NewestTimestamp;
///
/// Manager UpdateRate
///
private float UpdateRate;
void Start()
{
UpdateRate = ManagerObject.UpdateRateInSeconds;
StartCoroutine(ChangeSlider());
}
///
/// set slider values each 1/updaterate seconds
///
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);
}
}
///
/// On dragging slider
///
public void BeginDrag()
{
Dragging = true;
}
///
/// on slider value change
///
public void TimelineValueChanged()
{
if (!Dragging)
{
ManagerObject.JumpToTimestamp(GameTimelineSlider.value);
}
}
///
/// on stop dragging slider
///
public void StopDrag()
{
GameTimelineSlider.SetValueWithoutNotify(GameTimelineSlider.value);
ManagerObject.JumpToTimestamp(GameTimelineSlider.value);
Dragging = false;
}
}
}