UP-Viagg-io/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStereoscopicSlideshow.cs

112 lines
3.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using MyBT;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(NamedStereoscopicSlideshow))]
public class NamedStereoscopicSlideshowInspector : ComponentHandlerInspector {
}
#endif
[System.Serializable]
public class NamedStereoscopicSlideshow : ComponentHandler {
public override string TypeLabel()
{
return "StereoSlideshow";
}
public override string ContentLabel()
{
UpdateComponent();
if (photoTransition == null || photoTransition.imgPathList.Count == 0)
{
return "ImgsNotDefined";
}
string[] fullPath = photoTransition.imgPathList[0].Split('/');
string filename = fullPath[fullPath.Length - 1];
string fileNameWithoutExt = filename.Remove(filename.Length - 4); // remove .JPG
string final = fileNameWithoutExt.Length > 10 ? fileNameWithoutExt.Substring(0, 10) : fileNameWithoutExt; // first 10 characters
return final;
}
public override void UpdateComponent()
{
base.UpdateComponent();
photoTransition = GetComponent<PhotoTransition>();
if (photoTransition == null)
{
Debug.Log($"NamedStereoscopicSlideshow.UpdateComponent photoTransition is null");
}
}
public PhotoTransition photoTransition;
float _timeLeft;
public float totalTime = 5.0f;
public override void Run(NodeState nodeState)
{
switch (nodeState)
{
case NodeState.FirstRun:
photoTransition.Reset();
_timeLeft = totalTime;
string path = photoTransition.imgPathList[0];
photoTransition.ImageLoader(path);
photoTransition.SetUp();
break;
case NodeState.Running:
_timeLeft -= Time.deltaTime;
if (_timeLeft < 0)
{
StartCoroutine(photoTransition.LoadNextImage());
_timeLeft = totalTime;
}
if (photoTransition.IsSlideshowFinished())
{
Task.SetSucceeded();
}
break;
case NodeState.Aborting:
_timeLeft = totalTime;
break;
}
}
public override void BlendImage(NodeState nodeState, int srcIndex, int dstIndex)
{
if (nodeState == NodeState.FirstRun)
{
StartCoroutine(photoTransition.BlendImage(srcIndex, dstIndex));
Task.SetSucceeded();
}
}
public override void LoadImage(NodeState nodeState, int index)
{
// LoadImage(0): 1. bild laden im hintergrund
// Show: Setup srctxt (1. bild einblenden) + im hintergrund loadImage(1)
// (Sprachinput): blendimage(2)
if (nodeState == NodeState.FirstRun)
{
string path = photoTransition.imgPathList[index];
StartCoroutine(photoTransition.ImageLoader(path));
Task.SetSucceeded();
}
}
public override void Show(NodeState nodeState)
{
if (nodeState == NodeState.FirstRun)
{
photoTransition.SetUp();
Task.SetSucceeded();
}
}
}