SHADE_Y3/Assets/Scripts/UI/SC_CutsceneIntro.cs

585 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using SHADE;
public class CutsceneIntro : Script
{
public uint nextScene;
public float duration = 3.0f;
public float skipDuration = 0.1f;
private float oldDuration = 0.0f;
private Renderable pic1aRenderable;
private Renderable pic1bRenderable;
private Renderable pic1cRenderable;
private Renderable pic2aRenderable;
private Renderable pic2bRenderable;
private Renderable pic2cRenderable;
private Renderable pic3aRenderable;
private Renderable pic3bRenderable;
private Renderable pic3cRenderable;
private Renderable pic3dRenderable;
private Renderable pic3eRenderable;
private Transform pic1aTran;
private Transform pic1bTran;
private Transform pic1cTran;
private Transform pic2aTran;
private Transform pic2bTran;
private Transform pic2cTran;
private Transform pic3aTran;
private Transform pic3bTran;
private Transform pic3cTran;
private Transform pic3dTran;
private Transform pic3eTran;
private float alphaIn = 0.0f;
private float time = 0.0f;
private bool showPic1a = true;
private bool showPic1b = false;
private bool showPic1c = false;
private bool showPic2a = true;
private bool showPic2b = false;
private bool showPic2c = false;
private bool showPic3a = true;
private bool showPic3b = false;
private bool showPic3c = false;
private bool showPic3e = false;
private bool showPic3d = false;
private bool skip = false;
public GameObject cutscene1Points;
private List<Transform> listOfCutscene1Points;
public GameObject cutscene1Pics;
private List<Renderable> listOfCutscene1Pics;
public GameObject cutscene2Points;
private List<Transform> listOfCutscene2Points;
public GameObject cutscene2Pics;
private List<Renderable> listOfCutscene2Pics;
public GameObject cutscene3Points;
private List<Transform> listOfCutscene3Points;
public GameObject cutscene3Pics;
private List<Renderable> listOfCutscene3Pics;
private TextRenderable text1;
private TextRenderable text2;
private TextRenderable text3;
public GameObject canvas1;
public GameObject canvas2;
public GameObject canvas3;
private bool cutscene1Done = false;
private bool cutscene2Done = false;
private bool cutscene3Done = false;
protected override void awake()
{
initCutscene1();
initCutscene2();
initCutscene3();
}
protected override void update()
{
Canvas1();
Canvas2();
Canvas3();
if (Input.GetKeyDown(Input.KeyCode.Space) && !skip && (!cutscene1Done || !cutscene2Done || !cutscene3Done))
{
skip = true;
oldDuration = duration;
duration = skipDuration;
}
if (Input.GetKeyDown(Input.KeyCode.Space) && cutscene1Done && canvas1.IsActiveSelf)
{
canvas1.SetActive(false);
canvas2.SetActive(true);
duration = oldDuration;
skip = false;
}
if (Input.GetKeyDown(Input.KeyCode.Space) && cutscene2Done && canvas2.IsActiveSelf)
{
canvas2.SetActive(false);
canvas3.SetActive(true);
duration = oldDuration;
skip = false;
}
if (Input.GetKeyDown(Input.KeyCode.Space) && cutscene3Done && canvas3.IsActiveSelf)
{
SceneManager.ChangeScene(nextScene);
}
}
private void Canvas1()
{
if (canvas1.IsActiveSelf)
{
if (showPic1a)
{
if (time < duration)
{
pic1aTran.LocalPosition = Vector3.Lerp(pic1aTran.LocalPosition, listOfCutscene1Points[0].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1aTran.LocalPosition = listOfCutscene1Points[0].LocalPosition;
alphaIn = 1.0f;
}
pic1aRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic1a = false;
showPic1b = true;
time = 0;
alphaIn = 0;
}
}
if (showPic1b)
{
if (time < duration)
{
pic1bTran.LocalPosition = Vector3.Lerp(pic1bTran.LocalPosition, listOfCutscene1Points[1].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1bTran.LocalPosition = listOfCutscene1Points[1].LocalPosition;
alphaIn = 1.0f;
}
pic1bRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic1b = false;
showPic1c = true;
time = 0;
alphaIn = 0;
}
}
if (showPic1c)
{
if (time < duration)
{
pic1cTran.LocalPosition = Vector3.Lerp(pic1cTran.LocalPosition, listOfCutscene1Points[2].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic1cTran.LocalPosition = listOfCutscene1Points[2].LocalPosition;
alphaIn = 1.0f;
}
pic1cRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic1c = false;
cutscene1Done = true;
text1.Enabled = true;
time = 0;
alphaIn = 0;
}
}
}
}
private void Canvas2()
{
if (canvas2.IsActiveSelf)
{
if (showPic2a)
{
if (time < duration)
{
pic2aTran.LocalPosition = Vector3.Lerp(pic2aTran.LocalPosition, listOfCutscene2Points[0].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic2aTran.LocalPosition = listOfCutscene2Points[0].LocalPosition;
alphaIn = 1.0f;
}
pic2aRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic2a = false;
showPic2b = true;
time = 0;
alphaIn = 0;
}
}
if (showPic2b)
{
if (time < duration)
{
pic2bTran.LocalPosition = Vector3.Lerp(pic2bTran.LocalPosition, listOfCutscene2Points[1].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic2bTran.LocalPosition = listOfCutscene2Points[1].LocalPosition;
alphaIn = 1.0f;
}
pic2bRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic2b = false;
showPic2c = true;
time = 0;
alphaIn = 0;
}
}
if (showPic2c)
{
if (time < duration)
{
pic2cTran.LocalPosition = Vector3.Lerp(pic2cTran.LocalPosition, listOfCutscene2Points[2].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic2cTran.LocalPosition = listOfCutscene2Points[2].LocalPosition;
alphaIn = 1.0f;
}
pic2cRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic2c = false;
cutscene2Done = true;
text2.Enabled = true;
time = 0;
alphaIn = 0;
}
}
}
}
private void Canvas3()
{
if (canvas3.IsActiveSelf)
{
if (showPic3a)
{
if (time < duration)
{
pic3aTran.LocalPosition = Vector3.Lerp(pic3aTran.LocalPosition, listOfCutscene3Points[0].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic3aTran.LocalPosition = listOfCutscene3Points[0].LocalPosition;
alphaIn = 1.0f;
}
pic3aRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic3a = false;
showPic3b = true;
time = 0;
alphaIn = 0;
}
}
if (showPic3b)
{
if (time < duration)
{
pic3bTran.LocalPosition = Vector3.Lerp(pic3bTran.LocalPosition, listOfCutscene3Points[1].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic3bTran.LocalPosition = listOfCutscene3Points[1].LocalPosition;
alphaIn = 1.0f;
}
pic3bRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic3b = false;
showPic3c = true;
time = 0;
alphaIn = 0;
}
}
if (showPic3c)
{
if (time < duration)
{
pic3cTran.LocalPosition = Vector3.Lerp(pic3cTran.LocalPosition, listOfCutscene3Points[2].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic3cTran.LocalPosition = listOfCutscene3Points[2].LocalPosition;
alphaIn = 1.0f;
}
pic3cRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic3c = false;
showPic3d = true;
time = 0;
alphaIn = 0;
}
}
if (showPic3d)
{
if (time < duration)
{
pic3dTran.LocalPosition = Vector3.Lerp(pic3dTran.LocalPosition, listOfCutscene3Points[3].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic3dTran.LocalPosition = listOfCutscene3Points[3].LocalPosition;
alphaIn = 1.0f;
}
pic3dRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic3d = false;
showPic3e = true;
time = 0;
alphaIn = 0;
}
}
if (showPic3e)
{
if (time < duration)
{
pic3eTran.LocalPosition = Vector3.Lerp(pic3eTran.LocalPosition, listOfCutscene3Points[4].LocalPosition, time / duration);
alphaIn = SHADE.Math.Lerp(0.0f, 1.0f, time / duration);
time += Time.DeltaTimeF;
}
else
{
pic3eTran.LocalPosition = listOfCutscene3Points[4].LocalPosition;
alphaIn = 1.0f;
}
pic3eRenderable.Material.SetProperty<float>("data.alpha", alphaIn);
if (alphaIn >= 1.0f)
{
showPic3e = false;
cutscene3Done = true;
text3.Enabled = true;
time = 0;
alphaIn = 0;
}
}
}
}
private void initCutscene1()
{
if(cutscene1Points)
listOfCutscene1Points = cutscene1Points.GetComponentsInChildren<Transform>().ToList();
else
Debug.LogError("Cutscene1Points Missing");
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);
}
else
Debug.LogError("SCENE 1 PIC1 MISSING");
if (listOfCutscene1Pics[1])
{
pic1bRenderable = listOfCutscene1Pics[1].GetComponent<Renderable>();
pic1bTran = listOfCutscene1Pics[1].GetComponent<Transform>();
pic1bRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 1 PIC2 MISSING");
if (listOfCutscene1Pics[2])
{
pic1cRenderable = listOfCutscene1Pics[2].GetComponent<Renderable>();
pic1cTran = listOfCutscene1Pics[2].GetComponent<Transform>();
pic1cRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 1 PIC3 MISSING");
if (canvas1)
{
text1 = canvas1.GetComponentInChildren<TextRenderable>();
text1.Enabled = false;
}
else
Debug.LogError("Canvas 1 missing");
}
private void initCutscene2()
{
if(cutscene2Points)
listOfCutscene2Points = cutscene2Points.GetComponentsInChildren<Transform>().ToList();
else
Debug.LogError("cutscene2Points Missing");
if (listOfCutscene2Points.Count == 0)
Debug.LogError("Cutscene2Points Empty");
listOfCutscene2Pics = cutscene2Pics.GetComponentsInChildren<Renderable>().ToList();
if (listOfCutscene2Pics.Count == 0)
Debug.LogError("Cutscene2Pics Empty");
if (listOfCutscene2Pics[0])
{
pic2aRenderable = listOfCutscene2Pics[0].GetComponent<Renderable>();
pic2aTran = listOfCutscene2Pics[0].GetComponent<Transform>();
pic2aRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 2 PIC1 MISSING");
if (listOfCutscene2Pics[1])
{
pic2bRenderable = listOfCutscene2Pics[1].GetComponent<Renderable>();
pic2bTran = listOfCutscene2Pics[1].GetComponent<Transform>();
pic2bRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 2 PIC2 MISSING");
if (listOfCutscene2Pics[2])
{
pic2cRenderable = listOfCutscene2Pics[2].GetComponent<Renderable>();
pic2cTran = listOfCutscene2Pics[2].GetComponent<Transform>();
pic2cRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 2 PIC3 MISSING");
if (canvas2)
{
text2 = canvas2.GetComponentInChildren<TextRenderable>();
text2.Enabled = false;
canvas2.SetActive(false);
}
else
Debug.LogError("Canvas 2 missing");
}
private void initCutscene3()
{
if(cutscene3Points)
listOfCutscene3Points = cutscene3Points.GetComponentsInChildren<Transform>().ToList();
else
Debug.LogError("cutscene3Points Missing");
if (listOfCutscene3Points.Count == 0)
Debug.LogError("Cutscene3Points Empty");
listOfCutscene3Pics = cutscene3Pics.GetComponentsInChildren<Renderable>().ToList();
if (listOfCutscene3Pics.Count == 0)
Debug.LogError("Cutscene3Pics Empty");
if (listOfCutscene3Pics[0])
{
pic3aRenderable = listOfCutscene3Pics[0].GetComponent<Renderable>();
pic3aTran = listOfCutscene3Pics[0].GetComponent<Transform>();
pic3aRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 3 PIC1 MISSING");
if (listOfCutscene3Pics[1])
{
pic3bRenderable = listOfCutscene3Pics[1].GetComponent<Renderable>();
pic3bTran = listOfCutscene3Pics[1].GetComponent<Transform>();
pic3bRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 3 PIC2 MISSING");
if (listOfCutscene3Pics[2])
{
pic3cRenderable = listOfCutscene3Pics[2].GetComponent<Renderable>();
pic3cTran = listOfCutscene3Pics[2].GetComponent<Transform>();
pic3cRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 3 PIC3 MISSING");
if (listOfCutscene3Pics[3])
{
pic3dRenderable = listOfCutscene3Pics[3].GetComponent<Renderable>();
pic3dTran = listOfCutscene3Pics[3].GetComponent<Transform>();
pic3dRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 3 PIC4 MISSING");
if (listOfCutscene3Pics[4])
{
pic3eRenderable = listOfCutscene3Pics[4].GetComponent<Renderable>();
pic3eTran = listOfCutscene3Pics[4].GetComponent<Transform>();
pic3eRenderable.Material.SetProperty<float>("data.alpha", 0.0f);
}
else
Debug.LogError("SCENE 2 PIC5 MISSING");
if (canvas3)
{
text3 = canvas3.GetComponentInChildren<TextRenderable>();
text3.Enabled = false;
canvas3.SetActive(false);
}
else
Debug.LogError("Canvas 3 missing");
}
}