SHADE_Y3/Assets/Scripts/UI/SC_Cutscene.cs

152 lines
4.0 KiB
C#
Raw Normal View History

2023-02-27 15:33:58 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using SHADE;
public class Cutscene : Script
{
public float duration = 3.0f;
private Renderable pic1aRenderable;
private Renderable pic1bRenderable;
private Renderable pic1cRenderable;
2023-02-27 15:33:58 +08:00
private Transform pic1aTran;
private Transform pic1bTran;
private Transform pic1cTran;
2023-02-27 15:33:58 +08:00
private float alphaIn = 0.0f;
//private float alphaOut = 1.0f;
private float time = 0.0f;
private bool showPic1a = true;
private bool showPic1b = false;
private bool showPic1c = false;
private bool cutsceneDone = false;
2023-02-27 15:33:58 +08:00
public float slideSpeed = 5.0f;
public GameObject cutscene1Points;
private List<Transform> listOfCutscene1Points;
public GameObject cutscene1Pics;
private List<Renderable> listOfCutscene1Pics;
protected override void awake()
{
listOfCutscene1Points = cutscene1Points.GetComponentsInChildren<Transform>().ToList();
if (listOfCutscene1Points.Count == 0)
Debug.LogError("Cutscene1Points Empty");
listOfCutscene1Pics = cutscene1Pics.GetComponentsInChildren<Renderable>().ToList();
if (listOfCutscene1Pics.Count == 0)
Debug.LogError("Cutscene1Pics Empty");
if (listOfCutscene1Pics[0])
{
pic1aRenderable = listOfCutscene1Pics[0].GetComponent<Renderable>();
pic1aTran = listOfCutscene1Pics[0].GetComponent<Transform>();
pic1aRenderable.Material.SetProperty<float>("data.alpha" , 0.0f);
2023-02-27 15:33:58 +08:00
}
else
Debug.LogError("PIC1 MISSING");
if (listOfCutscene1Pics[1])
{
pic1bRenderable = listOfCutscene1Pics[1].GetComponent<Renderable>();
pic1bTran = listOfCutscene1Pics[1].GetComponent<Transform>();
pic1bRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
2023-02-27 15:33:58 +08:00
}
else
Debug.LogError("PIC2 MISSING");
if (listOfCutscene1Pics[2])
{
pic1cRenderable = listOfCutscene1Pics[2].GetComponent<Renderable>();
pic1cTran = listOfCutscene1Pics[2].GetComponent<Transform>();
pic1cRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
2023-02-27 15:33:58 +08:00
}
else
Debug.LogError("PIC3 MISSING");
}
protected override void update()
{
if (showPic1a)
2023-02-27 15:33:58 +08:00
{
pic1aTran.LocalPosition = Vector3.Lerp(pic1aTran.LocalPosition, listOfCutscene1Points[0].LocalPosition, slideSpeed * Time.DeltaTimeF);
2023-02-27 15:33:58 +08:00
if (time < duration)
{
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1aTran.LocalPosition = listOfCutscene1Points[0].LocalPosition;
2023-02-27 15:33:58 +08:00
alphaIn = 1.0f;
}
2023-02-27 15:33:58 +08:00
pic1aRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
2023-02-27 15:33:58 +08:00
if (alphaIn >= 1.0f)
{
showPic1a = false;
showPic1b = true;
2023-02-27 15:33:58 +08:00
time = 0;
alphaIn = 0;
}
}
if (showPic1b)
2023-02-27 15:33:58 +08:00
{
pic1bTran.LocalPosition = Vector3.Lerp(pic1bTran.LocalPosition, listOfCutscene1Points[1].LocalPosition, slideSpeed * Time.DeltaTimeF);
2023-02-27 15:33:58 +08:00
if (time < duration)
{
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1bTran.LocalPosition = listOfCutscene1Points[1].LocalPosition;
2023-02-27 15:33:58 +08:00
alphaIn = 1.0f;
}
2023-02-27 15:33:58 +08:00
pic1bRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
2023-02-27 15:33:58 +08:00
if (alphaIn >= 1.0f)
{
showPic1b = false;
showPic1c = true;
2023-02-27 15:33:58 +08:00
time = 0;
alphaIn = 0;
}
}
if (showPic1c)
2023-02-27 15:33:58 +08:00
{
pic1cTran.LocalPosition = Vector3.Lerp(pic1cTran.LocalPosition, listOfCutscene1Points[2].LocalPosition, slideSpeed * Time.DeltaTimeF);
2023-02-27 15:33:58 +08:00
if (time < duration)
{
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1cTran.LocalPosition = listOfCutscene1Points[2].LocalPosition;
2023-02-27 15:33:58 +08:00
alphaIn = 1.0f;
}
2023-02-27 15:33:58 +08:00
pic1cRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
2023-02-27 15:33:58 +08:00
if (alphaIn >= 1.0f)
{
showPic1c = false;
cutsceneDone = true;
2023-02-27 15:33:58 +08:00
time = 0;
alphaIn = 0;
}
}
}
}