Skip to content

Commit

Permalink
No1. SOLID GameState Fields Problem Reference losing
Browse files Browse the repository at this point in the history
- Base pre, Works Here
- No Data Fields to Game State Here
  • Loading branch information
michailmarkou1995 committed Aug 1, 2022
1 parent 862eeef commit 981f5af
Show file tree
Hide file tree
Showing 29 changed files with 472 additions and 742 deletions.
54 changes: 10 additions & 44 deletions Assets/Prefabs/_managers/Level Starter.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ GameObject:
- component: {fileID: 4200383187230866}
- component: {fileID: 114750208195470174}
- component: {fileID: 9213773268289219142}
- component: {fileID: 287011022097929418}
- component: {fileID: 8664226275268435725}
- component: {fileID: 6261290678525385038}
m_Layer: 0
m_Name: Level Manager
m_TagString: Untagged
Expand Down Expand Up @@ -83,15 +80,24 @@ MonoBehaviour:
hurryUp: 0
marioSize: 0
lives: 0
isRespawning: 0
coins: 0
scores: 0
timeLeft: 0
isInvinciblePowerdown: 0
isInvincibleStarman: 0
scoreText: {fileID: 114097602158662608}
coinText: {fileID: 114108165712623676}
timeText: {fileID: 114793167711461314}
floatingTextEffect: {fileID: 1196479104050882, guid: 1ad1e9f06ef1b47b0ba83ef5484e63cf, type: 3}
coinBonus: 200
powerupBonus: 1000
starmanBonus: 1000
oneupBonus: 0
breakBlockBonus: 50
stompBounceVelocity: {x: 0, y: 15}
gamePaused: 0
timerPaused: 0
musicPaused: 0
--- !u!114 &9213773268289219142
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -131,46 +137,6 @@ MonoBehaviour:
powerupAppearSound: {fileID: 8300000, guid: 97a450c65284a4a3094ba5c2221a492b, type: 3}
stompSound: {fileID: 8300000, guid: d84415726495b4d46b5a557ed2a97cfa, type: 3}
warningSound: {fileID: 8300000, guid: c0ea6c25686884e1a9547efdebf43492, type: 3}
--- !u!114 &287011022097929418
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1004064948157000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b08dd87c3e2f4e6085d0ed5d145c09cf, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &8664226275268435725
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1004064948157000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a4c34187099f4992aa4100a92a21daa4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &6261290678525385038
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1004064948157000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6ade286070354de3b9d0016e59d3514c, type: 3}
m_Name:
m_EditorClassIdentifier:
scoreText: {fileID: 114097602158662608}
coinText: {fileID: 114108165712623676}
timeText: {fileID: 114793167711461314}
floatingTextEffect: {fileID: 1196479104050882, guid: 1ad1e9f06ef1b47b0ba83ef5484e63cf, type: 3}
--- !u!1 &1006136692691096
GameObject:
m_ObjectHideFlags: 0
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scenes/Main Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ GameObject:
- component: {fileID: 693547088}
- component: {fileID: 693547089}
- component: {fileID: 693547090}
- component: {fileID: 693547091}
m_Layer: 0
m_Name: SoundManager
m_TagString: SoundManager
Expand Down Expand Up @@ -1517,6 +1518,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 16df295c1140448a9440ab3d732d3e2a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &693547091
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 693547087}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 411fe83d26391384bbc5244f7de427bc, type: 3}
m_Name:
m_EditorClassIdentifier:
soundTest: {fileID: 8300000, guid: a396fb5db437f453d89c54963e7b9719, type: 3}
--- !u!1 &819667513
GameObject:
m_ObjectHideFlags: 0
Expand Down
93 changes: 1 addition & 92 deletions Assets/Scripts/Core/Managers/GameStateManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections;
using Interfaces.Core.Managers;
using JetBrains.Annotations;
using Interfaces.Core.Managers;
using UnityEngine;

namespace Core.Managers
Expand Down Expand Up @@ -59,12 +56,6 @@ public float TimeLeft
set => timeLeft = value;
}

public int TimeLeftInt
{
get => timeLeftInt;
set => timeLeftInt = value;
}

public bool HurryUp
{
get => hurryUp;
Expand All @@ -83,28 +74,9 @@ public bool TimeUp
set => timeUp = value;
}

public bool GamePaused
{
get => gamePaused;
set => gamePaused = value;
}

public bool TimerPaused
{
get => timerPaused;
set => timerPaused = value;
}

public bool MusicPaused
{
get => musicPaused;
set => musicPaused = value;
}

#endregion

private ISaveGameState _saveGameStateOnMemory;
[CanBeNull] private ILevelManager _levelManager;

private void Awake()
{
Expand Down Expand Up @@ -169,68 +141,5 @@ public void GetSaveGameState()
{
_saveGameStateOnMemory.SaveGameState(this);
}

public void PauseUnPauseState()
{
_levelManager = FindObjectOfType<LevelManager>();
StartCoroutine(!GamePaused ? PauseGameCo() : UnpauseGameCo());
}

private IEnumerator PauseGameCo()
{
if (_levelManager == null) {
yield break;
}

Debug.Log("PauseGameCo!!!!!!!!!!");
GamePaused = true;
PauseGamePrevTimeScale = Time.timeScale;

Time.timeScale = 0;
PausePrevMusicPaused = MusicPaused;
_levelManager.GetSoundManager.MusicSource.Pause();
MusicPaused = true;
_levelManager.GetSoundManager.SoundSource.Pause();

// Set any active animators that use unscaled time mode to normal
UnScaledAnimators.Clear();
foreach (Animator animator in FindObjectsOfType<Animator>()) {
if (animator.updateMode != AnimatorUpdateMode.UnscaledTime) continue;
UnScaledAnimators.Add(animator);
animator.updateMode = AnimatorUpdateMode.Normal;
}

_levelManager.GetSoundManager.PauseSoundSource.Play();
yield return new WaitForSecondsRealtime(_levelManager.GetSoundManager.PauseSoundSource.clip.length);
Debug.Log(this.name + " PauseGameCo stops: records prevTimeScale=" + PauseGamePrevTimeScale.ToString());
}

private IEnumerator UnpauseGameCo()
{
if (_levelManager == null) {
yield break;
}

_levelManager.GetSoundManager.PauseSoundSource.Play();
yield return new WaitForSecondsRealtime(_levelManager.GetSoundManager.PauseSoundSource.clip.length);

MusicPaused = PausePrevMusicPaused;
if (!MusicPaused) {
_levelManager.GetSoundManager.MusicSource.UnPause();
}

_levelManager.GetSoundManager.SoundSource.UnPause();

// Reset animators
foreach (Animator animator in UnScaledAnimators) {
animator.updateMode = AnimatorUpdateMode.UnscaledTime;
}

UnScaledAnimators.Clear();

Time.timeScale = PauseGamePrevTimeScale;
GamePaused = false;
Debug.Log(this.name + " UnpauseGameCo stops: resume prevTimeScale=" + PauseGamePrevTimeScale.ToString());
}
}
}
Loading

0 comments on commit 981f5af

Please sign in to comment.