1
0
Fork 0

add functionality to pause Menu

This commit is contained in:
Jan 2018-04-24 02:15:58 +02:00
parent 84cb62559a
commit 0466aebd04
5 changed files with 137 additions and 13 deletions

View file

@ -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:

View file

@ -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}

View file

@ -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<PlayerMovement>().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<PlayerMovement>().enabled = false;
GetUI().showPauseUI(true);
}
public void Continue() {
ChangeState(GameState.RUNNING);
}
}

View file

@ -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");
}
}
}

View file

@ -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