From 5d6f9b5a20996cc3c8899af8c93a21a79824eb5f Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Thu, 19 Dec 2024 11:54:39 +0100 Subject: [PATCH] Add countdown and animation --- Assets/Scenes/Main.unity | 38 ++++++++++++++++++++- Assets/StartScreen.cs | 70 ++++++++++++++++++++++++++++++++++++++ Assets/StartScreen.cs.meta | 11 ++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Assets/StartScreen.cs create mode 100644 Assets/StartScreen.cs.meta diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index eeb34fcd..3b15bd10 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -6774,6 +6774,26 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 2967639384774196494, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2967639384774196494, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1282961724} + - target: {fileID: 2967639384774196494, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: StartGame + objectReference: {fileID: 0} + - target: {fileID: 2967639384774196494, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName + value: Netherlands3D.Twin.StartScreen, Assembly-CSharp + objectReference: {fileID: 0} - target: {fileID: 2984712510486319644, guid: 9963fec33e379324db2affcb3f83332f, type: 3} propertyPath: m_AnchorMax.y @@ -10224,6 +10244,18 @@ PrefabInstance: type: 3} insertIndex: 3 addedObject: {fileID: 199510459} + - targetCorrespondingSourceObject: {fileID: 2773908478669454240, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + insertIndex: -1 + addedObject: {fileID: 1727774868} + - targetCorrespondingSourceObject: {fileID: 2773908478669454240, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + insertIndex: -1 + addedObject: {fileID: 365423229} + - targetCorrespondingSourceObject: {fileID: 2773908478669454240, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + insertIndex: -1 + addedObject: {fileID: 1289894843} - targetCorrespondingSourceObject: {fileID: 8632740765308209879, guid: 9963fec33e379324db2affcb3f83332f, type: 3} insertIndex: -1 @@ -10232,7 +10264,11 @@ PrefabInstance: type: 3} insertIndex: -1 addedObject: {fileID: 392614950} - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 6774909300678283129, guid: 9963fec33e379324db2affcb3f83332f, + type: 3} + insertIndex: -1 + addedObject: {fileID: 1282961724} m_SourcePrefab: {fileID: 100100000, guid: 9963fec33e379324db2affcb3f83332f, type: 3} --- !u!224 &7732943800119484193 stripped RectTransform: diff --git a/Assets/StartScreen.cs b/Assets/StartScreen.cs new file mode 100644 index 00000000..77f37469 --- /dev/null +++ b/Assets/StartScreen.cs @@ -0,0 +1,70 @@ +using DG.Tweening; +using UnityEngine; +using UnityEngine.Events; + +namespace Netherlands3D.Twin +{ + public class StartScreen : MonoBehaviour + { + public UnityEvent getReady = new(); + public UnityEvent startGame = new (); + [SerializeField] private CanvasGroup canvasGroup; + [SerializeField] private CanvasGroup CountdownOne; + [SerializeField] private CanvasGroup CountdownTwo; + [SerializeField] private CanvasGroup CountdownThree; + [SerializeField] private float fadeDuration = .3f; + [SerializeField] private float countDownDuration = 1f; + [SerializeField] private float countDownTargetScale = .5f; + + private void Start() + { + Show(); + } + + private void OnEnable() + { + CountdownThree.alpha = 1f; + CountdownThree.gameObject.SetActive(false); + CountdownTwo.alpha = 1f; + CountdownTwo.gameObject.SetActive(false); + CountdownOne.alpha = 1f; + CountdownOne.gameObject.SetActive(false); + } + + public void Show() + { + gameObject.SetActive(true); + } + + public void StartGame() + { + var sequence = DOTween.Sequence(this); + sequence.Append(canvasGroup.DOFade(0, fadeDuration).OnComplete(TriggerGetReady)); + sequence.AppendCallback(() => CountdownThree.gameObject.SetActive(true)); + sequence.Append(CountdownThree.transform.DOScale(countDownTargetScale, countDownDuration)); + sequence.Join(CountdownThree.DOFade(0, countDownDuration).SetEase(Ease.InQuad)); + sequence.AppendCallback(() => CountdownThree.gameObject.SetActive(false)); + sequence.AppendCallback(() => CountdownTwo.gameObject.SetActive(true)); + sequence.Append(CountdownTwo.transform.DOScale(countDownTargetScale, countDownDuration)); + sequence.Join(CountdownTwo.DOFade(0, countDownDuration).SetEase(Ease.InQuad)); + sequence.AppendCallback(() => CountdownTwo.gameObject.SetActive(false)); + sequence.AppendCallback(() => CountdownOne.gameObject.SetActive(true)); + sequence.Append(CountdownOne.transform.DOScale(countDownTargetScale, countDownDuration)); + sequence.Join(CountdownOne.DOFade(0, countDownDuration).SetEase(Ease.InQuad)); + sequence.AppendCallback(() => CountdownOne.gameObject.SetActive(false)); + sequence.AppendCallback(TriggerStartOfGame); + sequence.Play(); + } + + private void TriggerGetReady() + { + gameObject.SetActive(false); + getReady.Invoke(); + } + + private void TriggerStartOfGame() + { + startGame.Invoke(); + } + } +} diff --git a/Assets/StartScreen.cs.meta b/Assets/StartScreen.cs.meta new file mode 100644 index 00000000..5709cb48 --- /dev/null +++ b/Assets/StartScreen.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0a827f570df226499c050398477eab1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: