using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ObjectScripts;
using CSVReader;
using System;
namespace UIScripts
{
public class EventTimestamp
{
//Not used anymore
///
///
///
public UnityEngine.UI.Dropdown TimestampDropdown;
///
///
///
double Timestamp;
///
///
///
public UnityEngine.UI.Button JumpButton;
///
///
///
GameObject EventDropdownPrefab;
///
///
///
private List Actions;
///
///
///
public List EventIDs;
///
///
///
UnityEngine.UI.Slider GameTimelineSlider;
///
///
///
RectTransform SliderRectTransform;
///
///
///
public EventTimestamp(double timestamp, GameObject eventDropdownPrefab, UnityEngine.UI.Slider gameTimelineSlider)
{
EventDropdownPrefab = eventDropdownPrefab;
TimestampDropdown = EventDropdownPrefab.GetComponent();
Timestamp = timestamp;
JumpButton = EventDropdownPrefab.GetComponentInChildren();
JumpButton.onClick.AddListener(() => this.JumpButtonClicked());
Actions = new List();
EventIDs = new List();
GameTimelineSlider = gameTimelineSlider;
SliderRectTransform = GameTimelineSlider.GetComponent();
EventDropdownPrefab.transform.localScale = Vector3.one;
EventDropdownPrefab.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
///
///
///
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));
}
///
///
///
private void JumpButtonClicked()
{
Actions[TimestampDropdown.value]();
}
///
///
///
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().enabled = false;
// button.GetComponent().enabled = false;
}
}
}
}