Implement Game Pause behaviour

This commit is contained in:
Denis-Cosmin Nutiu 2019-07-06 17:44:09 +03:00
parent 2beb2395ce
commit 93f2a11e69
11 changed files with 342 additions and 112 deletions

8
Assets/Prefabs/UI.meta Normal file
View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3cdc08213b0a440449d840e093556476
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -19,7 +19,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &311312840
RectTransform:
m_ObjectHideFlags: 0
@ -29,14 +29,14 @@ RectTransform:
m_GameObject: {fileID: 311312839}
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_LocalScale: {x: 1.5, y: 1.5, z: 1}
m_Children: []
m_Father: {fileID: 2219516564235934920}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.163, y: 0.31100002}
m_AnchorMax: {x: 0.163, y: 0.31100002}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 40}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &311312842
@ -178,7 +178,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2794171661481808020
RectTransform:
m_ObjectHideFlags: 0
@ -188,14 +188,14 @@ RectTransform:
m_GameObject: {fileID: 1533625511004221075}
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_LocalScale: {x: 1.5, y: 1.5, z: 1}
m_Children: []
m_Father: {fileID: 2219516564235934920}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.2342355, y: 0.2132826}
m_AnchorMax: {x: 0.2342355, y: 0.2132826}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 46, y: 16}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4417380224599296100
@ -430,7 +430,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2219516564235934924
RectTransform:
m_ObjectHideFlags: 0
@ -697,7 +697,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &6194349751570614361
RectTransform:
m_ObjectHideFlags: 0
@ -707,14 +707,14 @@ RectTransform:
m_GameObject: {fileID: 7551096532728223647}
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_LocalScale: {x: 1.5, y: 1.5, z: 1}
m_Children: []
m_Father: {fileID: 2219516564235934920}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.08852906, y: 0.2132826}
m_AnchorMax: {x: 0.08852906, y: 0.2132826}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: -46, y: 16}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1369717971988284717
@ -856,7 +856,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1067509750367631514
RectTransform:
m_ObjectHideFlags: 0
@ -866,7 +866,7 @@ RectTransform:
m_GameObject: {fileID: 8007755715420797612}
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_LocalScale: {x: 1.5, y: 1.5, z: 1}
m_Children: []
m_Father: {fileID: 2219516564235934920}
m_RootOrder: 2

View file

@ -0,0 +1,255 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &611824455253221635
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7943136189830570838}
- component: {fileID: 5829552964612260718}
- component: {fileID: 4935993846136593301}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7943136189830570838
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 611824455253221635}
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: []
m_Father: {fileID: 7935883257743492533}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5829552964612260718
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 611824455253221635}
m_CullTransparentMesh: 0
--- !u!114 &4935993846136593301
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 611824455253221635}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 24
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 0
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Stage 1
--- !u!1 &2251350585563921972
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3320912831386190365}
- component: {fileID: 6964405497678007768}
- component: {fileID: 3201857181095885022}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3320912831386190365
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2251350585563921972}
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: []
m_Father: {fileID: 7935883257743492533}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6964405497678007768
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2251350585563921972}
m_CullTransparentMesh: 0
--- !u!114 &3201857181095885022
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2251350585563921972}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!1 &4994633962466276707
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7935883257743492533}
- component: {fileID: 2152024136797500473}
- component: {fileID: 936482196064115039}
- component: {fileID: 826719949318333507}
m_Layer: 5
m_Name: PreStageUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7935883257743492533
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4994633962466276707}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 3320912831386190365}
- {fileID: 7943136189830570838}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!223 &2152024136797500473
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4994633962466276707}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &936482196064115039
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: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!114 &826719949318333507
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: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1f5ebc13237e070449ea8bc9e8b07ac8
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -762,100 +762,6 @@ PrefabInstance:
propertyPath: m_Pivot.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 311312840, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_LocalScale.x
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 311312840, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 311312840, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_LocalScale.z
value: 1
objectReference: {fileID: 0}
- target: {fileID: 311312840, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_AnchoredPosition.y
value: 40
objectReference: {fileID: 0}
- target: {fileID: 311312840, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1067509750367631514, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.x
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 1067509750367631514, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 2794171661481808020, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.x
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 2794171661481808020, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 2794171661481808020, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 46
objectReference: {fileID: 0}
- target: {fileID: 2794171661481808020, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 16
objectReference: {fileID: 0}
- target: {fileID: 6194349751570614361, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.x
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 6194349751570614361, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 6194349751570614361, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -46
objectReference: {fileID: 0}
- target: {fileID: 6194349751570614361, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 16
objectReference: {fileID: 0}
- target: {fileID: 311312839, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8007755715420797612, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2219516564249810540, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1533625511004221075, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7551096532728223647, guid: 4ca131020414f4b1597dac2e1d292d7f,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3}
--- !u!1001 &6843575829779162303

View file

@ -0,0 +1,38 @@
using UnityEngine;
namespace src.Helpers
{
public static class ApplicationActions
{
public static bool IsGamePaused { get; private set; }
public static void QuitGame()
{
Application.Quit();
}
public static void PauseGame()
{
IsGamePaused = true;
Time.timeScale = 0f;
}
public static void UnpauseGame()
{
IsGamePaused = false;
Time.timeScale = 1f;
}
public static void HandlePauseKey()
{
if (IsGamePaused)
{
UnpauseGame();
}
else
{
PauseGame();
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 243966f3fa384f4dac96170eacc1bee1
timeCreated: 1562422098

View file

@ -1,4 +1,5 @@
using UnityEngine;
using src.Helpers;
using UnityEngine;
namespace src.Managers
{
@ -45,11 +46,22 @@ namespace src.Managers
_levelManager.InitLevel();
}
/* Listen for meta keys */
private void Update(){
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
private void Update()
{
ListenForMetaKeys();
}
private static void ListenForMetaKeys()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
ApplicationActions.QuitGame();
}
else if (Input.GetKeyDown(KeyCode.P))
{
ApplicationActions.HandlePauseKey();
}
}
}
}

View file

@ -35,11 +35,13 @@ namespace src.Player
private void FixedUpdate()
{
if (ApplicationActions.IsGamePaused) {return;}
HandleMovement();
}
private void Update()
{
if (ApplicationActions.IsGamePaused) {return;}
HandleBomb();
}

View file

@ -34,7 +34,6 @@ GraphicsSettings:
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}