using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ObjectScripts;
using CSVReader;
namespace UIScripts
{
public class EventSlider : MonoBehaviour
{
///
/// EventHandler to get Events from
///
[SerializeField] AbstractEventHandler EventHandler;
///
/// Canvas for each moving Timestamp
///
[SerializeField] GameObject TimestampCanvas;
///
/// Timeline slider
///
[SerializeField] UnityEngine.UI.Slider Slider;
///
/// Manager to control
///
[SerializeField] AbstractManager Manager;
///
/// Sprites for each Eventtype
///
[SerializeField] Sprite[] EventImages;
///
/// Dictionary to keep track of each timestamp canvas
///
Dictionary Timestamps;
///
/// number of known events
///
private int KnownCount = 0;
///
/// Left timeline postion
///
private Vector3 MinPositon;
void Start()
{
Timestamps = new Dictionary();
MinPositon = TimestampCanvas.transform.position;
}
// Update is called once per frame
void Update()
{
//for each unknown event
for (int i = KnownCount; i < EventHandler.EventList.Count; i++)
{
EventObject eventObject = EventHandler.EventList[i].Event;
double timestamp = eventObject.TimestampStart;
GameObject obj;
if (Timestamps.TryGetValue(timestamp, out obj))
{
EventStamp eventStamp = obj.GetComponent();
eventStamp.addContent(EventHandler.EventList[i], EventImages[(int)eventObject.Type]);
}
else
{
obj = Instantiate(TimestampCanvas, TimestampCanvas.transform.localPosition, Quaternion.Euler(0, 0, 0), transform);
obj.transform.localRotation = Quaternion.Euler(0, 0, 0);
obj.SetActive(true);
EventStamp eventStamp = obj.GetComponent();
eventStamp.Slider = Slider;
eventStamp.Manager = Manager;
eventStamp.Timestamp = eventObject.TimestampStart;
eventStamp.addContent(EventHandler.EventList[i], EventImages[(int)eventObject.Type]);
Timestamps.Add(timestamp, obj);
obj.GetComponent().anchoredPosition = new Vector2(0, -obj.GetComponent().sizeDelta.y);
}
KnownCount += 1;
}
}
}
}