You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.1 KiB
C#
122 lines
3.1 KiB
C#
1 month ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class WorldTimelineManager : MonoBehaviour
|
||
|
{
|
||
|
public static WorldTimelineManager Instance;
|
||
|
|
||
|
[Header("Original Panels to Snapshot")]
|
||
|
public GameObject newEmailReceived;
|
||
|
public GameObject EmailListPanel;
|
||
|
public GameObject OpenedEmailPanel;
|
||
4 weeks ago
|
public GameObject DataStolen;
|
||
1 month ago
|
[Header("Timeline Canvas (World Space)")]
|
||
|
public Transform timelineParent;
|
||
|
public float panelSpacing = 2f;
|
||
|
|
||
|
[Header("Playback Settings")]
|
||
|
public float frameDelay = 1.0f;
|
||
|
public bool loopPlayback = true;
|
||
|
|
||
|
private List<GameObject> playbackFrames = new List<GameObject>();
|
||
|
private Coroutine playbackCoroutine;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
Instance = this;
|
||
|
}
|
||
|
|
||
|
public void SnapshotCurrentSequence()
|
||
|
{
|
||
4 weeks ago
|
UserActionLogger.Instance.ShowSummary();
|
||
1 month ago
|
ClearPlaybackFrames();
|
||
|
|
||
|
CloneAndAddToTimeline(newEmailReceived);
|
||
|
CloneAndAddToTimeline(EmailListPanel);
|
||
|
if (OpenedEmailPanel != null)
|
||
|
{
|
||
|
CloneAndAddToTimeline(OpenedEmailPanel);
|
||
|
}
|
||
|
|
||
4 weeks ago
|
CloneAndAddToTimeline(DataStolen);
|
||
1 month ago
|
PlayTimelineLoop();
|
||
|
}
|
||
|
|
||
|
private void CloneAndAddToTimeline(GameObject original)
|
||
|
{
|
||
|
if (original == null) return;
|
||
|
|
||
|
GameObject clone = Instantiate(original, timelineParent);
|
||
|
clone.transform.localScale = original.transform.localScale;
|
||
|
clone.transform.localRotation = Quaternion.identity;
|
||
4 weeks ago
|
clone.transform.localPosition = Vector3.zero;
|
||
|
//clone.transform.localPosition = Vector3.right * panelSpacing * playbackFrames.Count;
|
||
1 month ago
|
|
||
|
clone.SetActive(false);
|
||
|
DisableButtons(clone);
|
||
|
|
||
|
playbackFrames.Add(clone);
|
||
|
}
|
||
|
|
||
|
private void DisableButtons(GameObject root)
|
||
|
{
|
||
|
foreach (Button btn in root.GetComponentsInChildren<Button>(true))
|
||
|
{
|
||
4 weeks ago
|
btn.enabled = false;
|
||
1 month ago
|
}
|
||
|
}
|
||
|
|
||
|
public void PlayTimelineLoop()
|
||
|
{
|
||
|
if (playbackCoroutine != null)
|
||
|
StopCoroutine(playbackCoroutine);
|
||
|
|
||
|
playbackCoroutine = StartCoroutine(PlayFramesInLoop());
|
||
|
}
|
||
|
|
||
|
IEnumerator PlayFramesInLoop()
|
||
|
{
|
||
|
while (loopPlayback)
|
||
|
{
|
||
|
for (int i = 0; i < playbackFrames.Count; i++)
|
||
|
{
|
||
|
// Hide all
|
||
|
foreach (var frame in playbackFrames)
|
||
|
frame.SetActive(false);
|
||
|
|
||
|
// Show current frame
|
||
|
playbackFrames[i].SetActive(true);
|
||
|
|
||
|
yield return new WaitForSeconds(frameDelay);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void StopLoop()
|
||
|
{
|
||
|
loopPlayback = false;
|
||
|
|
||
|
if (playbackCoroutine != null)
|
||
|
StopCoroutine(playbackCoroutine);
|
||
|
|
||
|
foreach (var frame in playbackFrames)
|
||
|
frame.SetActive(false);
|
||
|
}
|
||
|
|
||
|
public void ClearPlaybackFrames()
|
||
|
{
|
||
|
if (playbackCoroutine != null)
|
||
|
StopCoroutine(playbackCoroutine);
|
||
|
|
||
|
foreach (var frame in playbackFrames)
|
||
|
{
|
||
|
if (frame != null)
|
||
|
Destroy(frame);
|
||
|
}
|
||
|
|
||
|
playbackFrames.Clear();
|
||
|
}
|
||
|
}
|