Create a flashy intro
This commit is contained in:
18
Assets/Scripts/Cutscene.cs
Normal file
18
Assets/Scripts/Cutscene.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class Cutscene : MonoBehaviour
|
||||
{
|
||||
public IEnumerator Play()
|
||||
{
|
||||
OnSceneStart();
|
||||
yield return OnScenePlay();
|
||||
OnSceneEnd();
|
||||
}
|
||||
|
||||
protected abstract IEnumerator OnScenePlay();
|
||||
|
||||
protected virtual void OnSceneStart() { }
|
||||
|
||||
protected virtual void OnSceneEnd() { }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 903dd5f2ae67978468e09862de06157f
|
||||
guid: 06fd16eb9a50013478bb59097b4d038a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
13
Assets/Scripts/CutsceneManager.cs
Normal file
13
Assets/Scripts/CutsceneManager.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CutsceneManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
Cutscene cutscene;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (cutscene != null)
|
||||
StartCoroutine(cutscene.Play());
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CutsceneManager.cs.meta
Normal file
11
Assets/Scripts/CutsceneManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4461999c2bda5da4e8eb91e0390c45d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
134
Assets/Scripts/Easing.cs
Normal file
134
Assets/Scripts/Easing.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public static class Easing
|
||||
{
|
||||
public static float QuadIn(float t) => t * t;
|
||||
|
||||
public static float QuadOut(float t) => t * (2f - t);
|
||||
|
||||
public static float QuadInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * t * t
|
||||
: -.5f * ((t -= 1f) * (t - 2f) - 1f);
|
||||
}
|
||||
|
||||
public static float CubeIn(float t) => t * t * t;
|
||||
|
||||
public static float CubeOut(float t) => 1f + ((t -= 1f) * t * t);
|
||||
|
||||
public static float CubeInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * t * t * t
|
||||
: .5f * ((t -= 2f) * t * t + 2f);
|
||||
}
|
||||
|
||||
public static float QuartIn(float t) => t * t * t * t;
|
||||
|
||||
public static float QuartOut(float t) => 1f - ((t -= 1f) * t * t * t);
|
||||
|
||||
public static float QuartInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * t * t * t * t
|
||||
: -.5f * ((t -= 2f) * t * t * t - 2f);
|
||||
}
|
||||
|
||||
public static float QuintIn(float t) => t * t * t * t * t;
|
||||
|
||||
public static float QuintOut(float t) => 1f + ((t -= 1f) * t * t * t * t);
|
||||
|
||||
public static float QuintInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * t * t * t * t * t
|
||||
: .5f * ((t -= 2f) * t * t * t * t + 2f);
|
||||
}
|
||||
|
||||
public static float SineIn(float t) => 1f - Mathf.Cos(t * Mathf.PI / 2f);
|
||||
|
||||
public static float SineOut(float t) => Mathf.Sin(t * Mathf.PI / 2f);
|
||||
|
||||
public static float SineInOut(float t) => .5f * (1f - Mathf.Cos(Mathf.PI * t));
|
||||
|
||||
public static float ExpoIn(float t) => t == 0f ? 0f : Mathf.Pow(1024f, t - 1f);
|
||||
|
||||
public static float ExpoOut(float t) => t == 1f ? 1f : 1f - Mathf.Pow(2f, -10f * t);
|
||||
|
||||
public static float ExpoInOut(float t)
|
||||
{
|
||||
if (t == 0f || t == 1f) return t;
|
||||
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * Mathf.Pow(1024f, t - 1f)
|
||||
: .5f * (-Mathf.Pow(2f, -10f * (t - 1f)) + 2f);
|
||||
}
|
||||
|
||||
public static float CircIn(float t) => 1f - Mathf.Sqrt(1f - t * t);
|
||||
|
||||
public static float CircOut(float t) => Mathf.Sqrt(1f - ((t -= 1f) * t));
|
||||
|
||||
public static float CircInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? -.5f * (Mathf.Sqrt(1f - t * t) - 1)
|
||||
: .5f * (Mathf.Sqrt(1f - (t -= 2f) * t) + 1f);
|
||||
}
|
||||
|
||||
public static float ElastIn(float t)
|
||||
{
|
||||
if (t == 0f || t == 1f) return t;
|
||||
|
||||
return -Mathf.Pow(2f, 10f * (t -= 1f))
|
||||
* Mathf.Sin((t - 0.1f) * (2f * Mathf.PI) / .4f);
|
||||
}
|
||||
|
||||
public static float ElastOut(float t)
|
||||
{
|
||||
if (t == 0f || t == 1f) return t;
|
||||
|
||||
return Mathf.Pow(2f, -10f * t)
|
||||
* Mathf.Sin((t - .1f) * (2f * Mathf.PI) / .4f) + 1f;
|
||||
}
|
||||
|
||||
public static float ElastInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? -.5f * Mathf.Pow(2f, 10f * (t -= 1f))
|
||||
* Mathf.Sin((t - .1f) * (2f * Mathf.PI) / .4f)
|
||||
: Mathf.Pow(2f, -10f * (t -= 1f))
|
||||
* Mathf.Sin((t - .1f) * (2f * Mathf.PI) / .4f) * .5f + 1f;
|
||||
}
|
||||
|
||||
public static float BackIn(float t) => t * t * (2.70158f * t - 1.70158f);
|
||||
|
||||
public static float BackOut(float t) => (t -= 1f) * t * (2.70158f * t + 1.70158f) + 1f;
|
||||
|
||||
public static float BackInOut(float t)
|
||||
{
|
||||
return (t *= 2f) < 1f
|
||||
? .5f * (t * t * ((2.5949095f + 1f) * t - 2.5949095f))
|
||||
: .5f * ((t -= 2f) * t * ((2.5949095f + 1f) * t + 2.5949095f) + 2f);
|
||||
}
|
||||
|
||||
public static float BounceIn(float t) => 1f - BounceOut(1f - t);
|
||||
|
||||
public static float BounceOut(float t)
|
||||
{
|
||||
if (t < (1f / 2.75f)) return 7.5625f * t * t;
|
||||
else if (t < (2f / 2.75f)) return 7.5625f * (t -= 1.5f / 2.75f) * t + .75f;
|
||||
else if (t < (2.5f / 2.75f)) return 7.5625f * (t -= 2.25f / 2.75f) * t + .9375f;
|
||||
else return 7.5625f * (t -= 2.625f / 2.75f) * t + .984375f;
|
||||
}
|
||||
|
||||
public static float BounceInOut(float t)
|
||||
{
|
||||
return t < 0.5f
|
||||
? BounceIn(t * 2f) * .5f
|
||||
: BounceOut(t * 2f - 1f) * .5f + .5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Easing.cs.meta
Normal file
11
Assets/Scripts/Easing.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed7563d26ca64b440ae5873040e5d0af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
Assets/Scripts/LogoIntroCutscene.cs
Normal file
66
Assets/Scripts/LogoIntroCutscene.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Assets.Scripts;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LogoIntroCutscene : Cutscene
|
||||
{
|
||||
[SerializeField]
|
||||
GameObject logoCubic;
|
||||
[SerializeField]
|
||||
GameObject logoFull;
|
||||
[SerializeField]
|
||||
SpriteRenderer logoFullRenderer;
|
||||
|
||||
protected override void OnSceneStart()
|
||||
{
|
||||
logoFull.SetActive(false);
|
||||
logoCubic.SetActive(true);
|
||||
logoCubic.transform.eulerAngles = Vector3.up * 90f;
|
||||
}
|
||||
|
||||
protected override IEnumerator OnScenePlay()
|
||||
{
|
||||
yield return RotateCube();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
yield return FadeInLogo();
|
||||
yield return new WaitForSeconds(.5f);
|
||||
}
|
||||
|
||||
protected override void OnSceneEnd()
|
||||
{
|
||||
// TODO: Go to the next scene.
|
||||
}
|
||||
|
||||
IEnumerator RotateCube()
|
||||
{
|
||||
const int maxTicks = 80;
|
||||
var angle = logoCubic.transform.eulerAngles;
|
||||
|
||||
for (int i = 0; i <= maxTicks; i++)
|
||||
{
|
||||
var percent = Easing.SineOut(1f * i / maxTicks);
|
||||
var angleLerp = new Vector3(
|
||||
Mathf.Lerp(angle.x, angle.x + 360f, percent),
|
||||
Mathf.Lerp(angle.y, angle.y + 360f, percent),
|
||||
Mathf.Lerp(angle.z, angle.z + 360f, percent));
|
||||
logoCubic.transform.eulerAngles = angleLerp;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator FadeInLogo()
|
||||
{
|
||||
const int maxTicks = 45;
|
||||
var clearWhite = new Color(1f, 1f, 1f, 0f);
|
||||
|
||||
logoFull.SetActive(true);
|
||||
|
||||
for (int i = 0; i <= maxTicks; i++)
|
||||
{
|
||||
var percent = Easing.SineIn(1f * i / maxTicks);
|
||||
logoFullRenderer.color = Color.Lerp(clearWhite, Color.white, percent);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LogoIntroCutscene.cs.meta
Normal file
11
Assets/Scripts/LogoIntroCutscene.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91beb731ac9f798499917d65e4b79eb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RotatingLogo : MonoBehaviour
|
||||
{
|
||||
public Vector3 speed;
|
||||
|
||||
void Update()
|
||||
{
|
||||
transform.Rotate(speed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user