SHADE_Y3/Assets/Scripts/Gameplay/SC_PreviewLevel.cs

171 lines
5.0 KiB
C#
Raw Permalink Normal View History

using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
2023-03-02 17:33:02 +08:00
namespace SHADE_Scripting.UI
{
2023-03-02 17:33:02 +08:00
public class PreviewLevel : Script
{
private List<Camera> listOfCamera;
public GameObject levelTransistion;
2023-03-02 17:33:02 +08:00
public Vector3 endPoint1;
public Vector3 endPoint2;
public Vector3 endPoint3;
2023-03-02 17:33:02 +08:00
public GameObject playerCamera;
public GameObject gameplayCanvas;
2023-03-02 17:33:02 +08:00
public float duration = 3.0f;
2023-03-02 17:33:02 +08:00
private bool point1Done = false;
private bool point2Done = false;
private bool point3Done = false;
2023-03-02 17:33:02 +08:00
private bool reset2 = true;
private bool reset3 = true;
2023-03-02 17:33:02 +08:00
private bool skip = false;
[NonSerialized]
private TweenThreadVec3 moveToEndPoint1;
[NonSerialized]
private TweenThreadVec3 moveToEndPoint2;
[NonSerialized]
private TweenThreadVec3 moveToEndPoint3;
2023-03-02 17:33:02 +08:00
protected override void awake()
{
listOfCamera = GameObject.GetComponentsInChildren<Camera>().ToList();
2023-03-02 17:33:02 +08:00
if (listOfCamera.Count == 0)
Debug.LogError("EMPTY PREVIEW POINTS");
2023-03-02 17:33:02 +08:00
}
2023-03-05 02:51:11 +08:00
protected override void start()
{
if (gameplayCanvas)
gameplayCanvas.SetActive(false);
2023-03-05 02:51:11 +08:00
listOfCamera[0].SetMainCamera();
2023-03-09 00:33:36 +08:00
moveToEndPoint1 = TweenManager.CreateTweenThreadVec3(duration, listOfCamera[0].GetComponent<Transform>().LocalPosition, endPoint1, EASING_METHOD.EASE_IN_SINE);
moveToEndPoint2 = TweenManager.CreateTweenThreadVec3(duration, listOfCamera[1].GetComponent<Transform>().LocalPosition, endPoint2, EASING_METHOD.EASE_IN_SINE);
moveToEndPoint3 = TweenManager.CreateTweenThreadVec3(duration, listOfCamera[2].GetComponent<Transform>().LocalPosition, endPoint3, EASING_METHOD.EASE_IN_SINE);
2023-03-05 02:51:11 +08:00
}
2023-03-02 17:33:02 +08:00
protected override void update()
{
if (SceneFadeInOut.Instance && !levelTransistion.GetScript<LevelTransistion>().complete && !point1Done)
2023-03-02 17:33:02 +08:00
{
moveToEndPoint1.Reset();
return;
}
2023-03-03 00:40:16 +08:00
if (Input.GetKeyUp(Input.KeyCode.Space) && !point3Done)
2023-03-02 17:33:02 +08:00
{
skip = true;
point1Done = true;
2023-03-05 02:51:11 +08:00
point3Done = true;
2023-03-02 17:33:02 +08:00
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
2023-03-05 15:35:57 +08:00
if (skip && SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeInFinished())
2023-03-02 17:33:02 +08:00
{
playerCamera.GetComponent<Camera>().SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
2023-03-05 15:35:57 +08:00
if (skip && SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeOutFinished())
2023-03-02 17:33:02 +08:00
{
GameManager.Instance.PreviewLevelDone = true;
if (gameplayCanvas)
gameplayCanvas.SetActive(true);
2023-03-02 17:33:02 +08:00
}
if (!skip)
{
if (!point1Done)
{
listOfCamera[0].GetComponent<Transform>().LocalPosition = moveToEndPoint1.GetValue();
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && moveToEndPoint1.IsCompleted())
2023-03-02 17:33:02 +08:00
{
point1Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeInFinished() && point1Done)
2023-03-02 17:33:02 +08:00
{
listOfCamera[1].SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeOutFinished() && point1Done)
2023-03-02 17:33:02 +08:00
{
if (!point2Done)
{
if (reset2)
{
moveToEndPoint2.Reset();
reset2 = false;
}
listOfCamera[1].GetComponent<Transform>().LocalPosition = moveToEndPoint2.GetValue();
if (moveToEndPoint2.IsCompleted())
{
point2Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
}
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeInFinished() && point2Done)
2023-03-02 17:33:02 +08:00
{
listOfCamera[2].SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeOutFinished() && point2Done)
2023-03-02 17:33:02 +08:00
{
if (!point3Done)
{
if (reset3)
{
2023-03-09 00:33:36 +08:00
moveToEndPoint3.Reset();
2023-03-02 17:33:02 +08:00
reset3 = false;
}
listOfCamera[2].GetComponent<Transform>().LocalPosition = moveToEndPoint3.GetValue();
if (moveToEndPoint3.IsCompleted())
{
point3Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
}
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeInFinished() && point3Done)
2023-03-02 17:33:02 +08:00
{
playerCamera.GetComponent<Camera>().SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
2023-03-05 15:35:57 +08:00
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeOutFinished() && point3Done)
2023-03-02 17:33:02 +08:00
{
GameManager.Instance.PreviewLevelDone = true;
if (gameplayCanvas)
gameplayCanvas.SetActive(true);
2023-03-02 17:33:02 +08:00
}
}
}
}
}