From 823025e7c8762b22395da202690209e147eb1e4b Mon Sep 17 00:00:00 2001 From: Denis NUTIU Date: Sat, 6 Jul 2019 18:44:07 +0300 Subject: [PATCH] Implement pre init game --- Assets/Prefabs/UI/PreStageUI.prefab | 13 ++ Assets/Scenes/SampleScene.unity | 134 ++++++++++++++++++ .../src/{Upgrade => Base}/UpgradeBase.cs | 0 .../src/{Upgrade => Base}/UpgradeBase.cs.meta | 0 .../Scripts/src/Helpers/ApplicationActions.cs | 11 +- Assets/Scripts/src/Managers/GameManager.cs | 16 ++- .../Scripts/src/Managers/GameStateManager.cs | 15 ++ .../src/Managers/GameStateManager.cs.meta | 3 + Assets/Scripts/src/Player/PlayerController.cs | 6 +- Assets/Scripts/src/UI.meta | 8 ++ Assets/Scripts/src/UI/PreLevelLoad.cs | 18 +++ Assets/Scripts/src/UI/PreLevelLoad.cs.meta | 11 ++ 12 files changed, 226 insertions(+), 9 deletions(-) rename Assets/Scripts/src/{Upgrade => Base}/UpgradeBase.cs (100%) rename Assets/Scripts/src/{Upgrade => Base}/UpgradeBase.cs.meta (100%) create mode 100644 Assets/Scripts/src/Managers/GameStateManager.cs create mode 100644 Assets/Scripts/src/Managers/GameStateManager.cs.meta create mode 100644 Assets/Scripts/src/UI.meta create mode 100644 Assets/Scripts/src/UI/PreLevelLoad.cs create mode 100644 Assets/Scripts/src/UI/PreLevelLoad.cs.meta diff --git a/Assets/Prefabs/UI/PreStageUI.prefab b/Assets/Prefabs/UI/PreStageUI.prefab index cb4d0b9..dfaf195 100644 --- a/Assets/Prefabs/UI/PreStageUI.prefab +++ b/Assets/Prefabs/UI/PreStageUI.prefab @@ -165,6 +165,7 @@ GameObject: - component: {fileID: 2152024136797500473} - component: {fileID: 936482196064115039} - component: {fileID: 826719949318333507} + - component: {fileID: 2684488013186753063} m_Layer: 5 m_Name: PreStageUI m_TagString: Untagged @@ -253,3 +254,15 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 4294967295 +--- !u!114 &2684488013186753063 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4994633962466276707} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a89bdde63eb80ad41bb0e1472e665667, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index c6d40ec..14953ca 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -480,6 +480,140 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1152312890 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 4994633962466276707, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_Name + value: PreStageUI + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_RootOrder + value: 9 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchoredPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_SizeDelta.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_SizeDelta.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchorMin.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchorMax.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_AnchorMax.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_Pivot.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7935883257743492533, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_Pivot.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2152024136797500473, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2152024136797500473, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_PixelPerfect + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4935993846136593301, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, + type: 3} + propertyPath: m_Text + value: + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, type: 3} --- !u!4 &1352658977 stripped Transform: m_CorrespondingSourceObject: {fileID: 6843575828445418654, guid: d3055091a17dc4aa1accf2e33ccef144, diff --git a/Assets/Scripts/src/Upgrade/UpgradeBase.cs b/Assets/Scripts/src/Base/UpgradeBase.cs similarity index 100% rename from Assets/Scripts/src/Upgrade/UpgradeBase.cs rename to Assets/Scripts/src/Base/UpgradeBase.cs diff --git a/Assets/Scripts/src/Upgrade/UpgradeBase.cs.meta b/Assets/Scripts/src/Base/UpgradeBase.cs.meta similarity index 100% rename from Assets/Scripts/src/Upgrade/UpgradeBase.cs.meta rename to Assets/Scripts/src/Base/UpgradeBase.cs.meta diff --git a/Assets/Scripts/src/Helpers/ApplicationActions.cs b/Assets/Scripts/src/Helpers/ApplicationActions.cs index 795c920..1b91e34 100644 --- a/Assets/Scripts/src/Helpers/ApplicationActions.cs +++ b/Assets/Scripts/src/Helpers/ApplicationActions.cs @@ -1,11 +1,12 @@ +using src.Managers; using UnityEngine; namespace src.Helpers { public static class ApplicationActions { - public static bool IsGamePaused { get; private set; } - + private static GameStateManager _gameStateManager = GameStateManager.Instance; + public static void QuitGame() { Application.Quit(); @@ -13,19 +14,19 @@ namespace src.Helpers public static void PauseGame() { - IsGamePaused = true; + _gameStateManager.IsGamePaused = true; Time.timeScale = 0f; } public static void UnpauseGame() { - IsGamePaused = false; + _gameStateManager.IsGamePaused = false; Time.timeScale = 1f; } public static void HandlePauseKey() { - if (IsGamePaused) + if (_gameStateManager.IsGamePaused) { UnpauseGame(); } diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index 1f421eb..d43d6f3 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -1,4 +1,5 @@ -using src.Helpers; +using System.Collections; +using src.Helpers; using UnityEngine; namespace src.Managers @@ -9,6 +10,7 @@ namespace src.Managers private LevelManager _levelManager; private UpgradeManager _upgradeManager; private BombsUtilManager _bombsUtilManager; + private GameObject _preStageUi; public void Awake() { @@ -27,7 +29,12 @@ namespace src.Managers _levelManager = GetComponent(); _upgradeManager = GetComponent(); _bombsUtilManager = BombsUtilManager.Instance; + _preStageUi = GameObject.Find("PreStageUI"); + } + public void Start() + { + StartCoroutine(PreInitGame()); InitGame(); } @@ -45,6 +52,12 @@ namespace src.Managers { _levelManager.InitLevel(); } + private IEnumerator PreInitGame() + { + _preStageUi.SetActive(true); + yield return new WaitForSeconds(0.7f); + _preStageUi.SetActive(false); + } private void Update() { @@ -55,7 +68,6 @@ namespace src.Managers { if (Input.GetKeyDown(KeyCode.Escape)) { - Application.Quit(); ApplicationActions.QuitGame(); } else if (Input.GetKeyDown(KeyCode.P)) diff --git a/Assets/Scripts/src/Managers/GameStateManager.cs b/Assets/Scripts/src/Managers/GameStateManager.cs new file mode 100644 index 0000000..2c620e5 --- /dev/null +++ b/Assets/Scripts/src/Managers/GameStateManager.cs @@ -0,0 +1,15 @@ +namespace src.Managers +{ + public class GameStateManager + { + public static GameStateManager Instance { get; } = new GameStateManager(); + public bool IsGamePaused { get; internal set; } + public int Level { get; private set; } = 1; + + + public void IncreaseLevel() + { + Level += 1; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/GameStateManager.cs.meta b/Assets/Scripts/src/Managers/GameStateManager.cs.meta new file mode 100644 index 0000000..addeca7 --- /dev/null +++ b/Assets/Scripts/src/Managers/GameStateManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7038cabd5b7145d7bad2dc0d2dd1a8fe +timeCreated: 1562425331 \ No newline at end of file diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 52c7197..542d9f3 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -2,6 +2,7 @@ using src.Base; using src.Helpers; using src.Interfaces; +using src.Managers; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; @@ -9,6 +10,7 @@ namespace src.Player { public class PlayerController : PlayerBase { + private GameStateManager _gameStateManager = GameStateManager.Instance; private Transform _respawnPosition; private BombsSpawner _bombsSpawner; private Animator _animator; @@ -35,13 +37,13 @@ namespace src.Player private void FixedUpdate() { - if (ApplicationActions.IsGamePaused) {return;} + if (_gameStateManager.IsGamePaused) {return;} HandleMovement(); } private void Update() { - if (ApplicationActions.IsGamePaused) {return;} + if (_gameStateManager.IsGamePaused) {return;} HandleBomb(); } diff --git a/Assets/Scripts/src/UI.meta b/Assets/Scripts/src/UI.meta new file mode 100644 index 0000000..db91021 --- /dev/null +++ b/Assets/Scripts/src/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eedf5bc1f8ea9484cb1063e7b5db029d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/UI/PreLevelLoad.cs b/Assets/Scripts/src/UI/PreLevelLoad.cs new file mode 100644 index 0000000..720626d --- /dev/null +++ b/Assets/Scripts/src/UI/PreLevelLoad.cs @@ -0,0 +1,18 @@ +using src.Managers; +using UnityEngine; +using UnityEngine.UI; + +namespace src.UI +{ + public class PreLevelLoad : MonoBehaviour + { + private readonly GameStateManager _gameStateManager = GameStateManager.Instance; + private Text _stageText; + + public void Start() + { + _stageText = GetComponentInChildren(); + _stageText.text = $"Stage {_gameStateManager.Level}"; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/src/UI/PreLevelLoad.cs.meta b/Assets/Scripts/src/UI/PreLevelLoad.cs.meta new file mode 100644 index 0000000..9476dc1 --- /dev/null +++ b/Assets/Scripts/src/UI/PreLevelLoad.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a89bdde63eb80ad41bb0e1472e665667 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: