SHADE_Y3/Assets/Scripts/Gameplay/SC_PreviewLevel.cs

159 lines
4.5 KiB
C#
Raw 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;
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 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
listOfCamera[0].SetMainCamera();
2023-03-02 17:33:02 +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);
}
protected override void update()
{
if (!SceneFadeInOut.Instance.FadeOutFinished() && !point1Done)
{
moveToEndPoint1.Reset();
return;
}
if (Input.GetKeyUp(Input.KeyCode.Space))
{
skip = true;
point1Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
if (skip && SceneFadeInOut.Instance.FadeInFinished())
{
playerCamera.GetComponent<Camera>().SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
2023-03-02 17:33:02 +08:00
if (skip && SceneFadeInOut.Instance.FadeOutFinished())
{
GameManager.Instance.PreviewLevelDone = true;
}
if (!skip)
{
if (!point1Done)
{
listOfCamera[0].GetComponent<Transform>().LocalPosition = moveToEndPoint1.GetValue();
if (moveToEndPoint1.IsCompleted())
{
point1Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
}
if (SceneFadeInOut.Instance.FadeInFinished() && point1Done)
{
listOfCamera[1].SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
if (SceneFadeInOut.Instance.FadeOutFinished() && point1Done)
{
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;
}
}
}
if (SceneFadeInOut.Instance.FadeInFinished() && point2Done)
{
listOfCamera[2].SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
if (SceneFadeInOut.Instance.FadeOutFinished() && point2Done)
{
if (!point3Done)
{
if (reset3)
{
moveToEndPoint3 = TweenManager.CreateTweenThreadVec3(duration, listOfCamera[2].GetComponent<Transform>().LocalPosition, endPoint3, EASING_METHOD.EASE_IN_SINE);
reset3 = false;
}
listOfCamera[2].GetComponent<Transform>().LocalPosition = moveToEndPoint3.GetValue();
if (moveToEndPoint3.IsCompleted())
{
point3Done = true;
SceneFadeInOut.Instance.CallFadeIn();
SceneFadeInOut.Instance.alphaValue = 0.01f;
}
}
}
if (SceneFadeInOut.Instance.FadeInFinished() && point3Done)
{
playerCamera.GetComponent<Camera>().SetMainCamera();
SceneFadeInOut.Instance.CallFadeOut();
}
if (SceneFadeInOut.Instance.FadeOutFinished() && point3Done)
{
GameManager.Instance.PreviewLevelDone = true;
}
}
}
}
}