From 0466aebd04c578642920c0d87f2e7093380ce315 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 24 Apr 2018 02:15:58 +0200 Subject: [PATCH] add functionality to pause Menu --- Assets/Prefabs/UI.prefab | 18 ++++++-- Assets/Scenes/CodeDEV.unity | 70 +++++++++++++++++++++++++++--- Assets/Scripts/GameController.cs | 35 +++++++++++++-- Assets/Scripts/UIController.cs | 11 +++++ ProjectSettings/InputManager.asset | 16 +++++++ 5 files changed, 137 insertions(+), 13 deletions(-) diff --git a/Assets/Prefabs/UI.prefab b/Assets/Prefabs/UI.prefab index b9a8ef8..fc670a4 100644 --- a/Assets/Prefabs/UI.prefab +++ b/Assets/Prefabs/UI.prefab @@ -265,7 +265,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!1 &1752959503665396 GameObject: m_ObjectHideFlags: 0 @@ -620,7 +620,18 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114026082862082466} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 0} + m_MethodName: Continue + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114060586777901180 @@ -1400,6 +1411,7 @@ MonoBehaviour: restartUIPanel: {fileID: 1604998495297016} healthcontroller: {fileID: 114617351635937986} brakeBarController: {fileID: 114745107968250074} + pausedUIPanel: {fileID: 1139220909146914} mainMenuSceneIndex: 0 --- !u!114 &114930219842054174 MonoBehaviour: @@ -1968,7 +1980,7 @@ RectTransform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1171183456984172} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: diff --git a/Assets/Scenes/CodeDEV.unity b/Assets/Scenes/CodeDEV.unity index 3d6de61..d0700d6 100644 --- a/Assets/Scenes/CodeDEV.unity +++ b/Assets/Scenes/CodeDEV.unity @@ -987,8 +987,8 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 5d9a051e822e2cf4ea3ca01c5a4df37c, type: 3} - m_Name: - m_EditorClassIdentifier: + m_Name: + m_EditorClassIdentifier: followSpeed: 0.05 minZoom: 5 zoomFactor: 4 @@ -1004,8 +1004,8 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 4e40ea81463f7264a8ce9334d6bf62ac, type: 3} - m_Name: - m_EditorClassIdentifier: + m_Name: + m_EditorClassIdentifier: mixer: {fileID: 24100000, guid: efb934a745665924d8c7dd46c0a117ae, type: 2} maintheme: {fileID: 1600556435} menutheme: {fileID: 30160411} @@ -1422,6 +1422,59 @@ Prefab: propertyPath: m_Pivot.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 224030602021903918, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_AnchorMax.x + value: 0.7 + objectReference: {fileID: 0} + - target: {fileID: 224030602021903918, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_AnchorMax.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 224899125652206328, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_AnchorMin.x + value: 0.7 + objectReference: {fileID: 0} + - target: {fileID: 224899125652206328, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_AnchorMax.x + value: 0.7 + objectReference: {fileID: 0} + - target: {fileID: 224899125652206328, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_AnchorMax.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1139220909146914, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1738841749900334, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224646073885350970, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 224646073885350970, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 224646073885350970, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 114917026543374048, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + propertyPath: pausedUIPanel + value: + objectReference: {fileID: 1379476070} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} m_IsPrefabParent: 0 @@ -1430,6 +1483,11 @@ GameObject: m_PrefabParentObject: {fileID: 1998375241450644, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} m_PrefabInternal: {fileID: 1379476068} +--- !u!1 &1379476070 stripped +GameObject: + m_PrefabParentObject: {fileID: 1139220909146914, guid: 460d856ea4eb14cedb5fecde1fe6d743, + type: 2} + m_PrefabInternal: {fileID: 1379476068} --- !u!1001 &1543828915 Prefab: m_ObjectHideFlags: 0 @@ -2259,8 +2317,8 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 87d25c2cd3eb97749b79f2cb5f7c5cea, type: 3} - m_Name: - m_EditorClassIdentifier: + m_Name: + m_EditorClassIdentifier: scorpion: {fileID: 1303102899095328, guid: 4c5ecfd27b4038941a6e493a8117ea0a, type: 2} bug: {fileID: 1887677565572348, guid: dd625f75dbf83194392a299951cf04fb, type: 2} coin: {fileID: 1974526777167790, guid: 35e8b8e102a45a1489ef949961dca4a6, type: 2} diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index c1e4f49..41f56c7 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -95,15 +95,17 @@ public class GameController : MonoBehaviour { [SerializeField] private GameObject mapRoot; - private bool engineInitDone; - private Player player; + bool engineInitDone; + Player player; + + bool pausedPressed = false; public static GameController instance; public GameController() { instance = this; } - public enum GameState { UNSET, INIT, STARTING, RUNNING, ENDED }; + public enum GameState { UNSET, INIT, STARTING, PAUSED, RUNNING, ENDED }; private EndedCause endCause = EndedCause.DIED; private GameState state = GameState.UNSET; @@ -152,6 +154,16 @@ public class GameController : MonoBehaviour { Debug.Log("First Frame"); ChangeState(GameState.INIT); } + if (Input.GetAxis("Pause") > 0) { + if (state == GameState.RUNNING && !pausedPressed) { + ChangeState(GameState.PAUSED); + } else if (state == GameState.PAUSED && !pausedPressed) { + ChangeState(GameState.RUNNING); + } + pausedPressed = true; + } else { + pausedPressed = false; + } } public void ChangeState(GameState nextState) { @@ -174,6 +186,9 @@ public class GameController : MonoBehaviour { case GameState.RUNNING: Running(); break; + case GameState.PAUSED: + Paused(); + break; case GameState.ENDED: Ended(); break; @@ -311,7 +326,9 @@ public class GameController : MonoBehaviour { } private void Running() { - + Time.timeScale = 1; + player.GetComponent().enabled = true; + GetUI().showPauseUI(false); } private void Ended() { @@ -354,4 +371,14 @@ public class GameController : MonoBehaviour { endCause = cause; ChangeState(GameState.ENDED); } + + void Paused() { + Time.timeScale = 0; + player.GetComponent().enabled = false; + GetUI().showPauseUI(true); + } + + public void Continue() { + ChangeState(GameState.RUNNING); + } } diff --git a/Assets/Scripts/UIController.cs b/Assets/Scripts/UIController.cs index 7784f11..63d0af3 100644 --- a/Assets/Scripts/UIController.cs +++ b/Assets/Scripts/UIController.cs @@ -22,6 +22,9 @@ public class UIController : MonoBehaviour [SerializeField] BrakeBarController brakeBarController; + [SerializeField] + GameObject pausedUIPanel; + [SerializeField] int mainMenuSceneIndex = 0; int firstSceneIndex = 1; @@ -80,4 +83,12 @@ public class UIController : MonoBehaviour public NotificationManager GetNotificationManager() { return notifications; } + + public void showPauseUI(bool show) { + if (pausedUIPanel != null) { + pausedUIPanel.SetActive(show); + } else { + Debug.Log("Paused UI not assigned"); + } + } } diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 132dc85..e55fec4 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -309,3 +309,19 @@ InputManager: type: 0 axis: 0 joyNum: 0 + - serializedVersion: 3 + m_Name: Pause + descriptiveName: + descriptiveNegativeName: + negativeButton: + positiveButton: escape + altNegativeButton: + altPositiveButton: p + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 0 + joyNum: 0