Skip to content

Commit

Permalink
Better scene management to avoid breaking everything if a scene is re…
Browse files Browse the repository at this point in the history
…named
  • Loading branch information
markellus committed Jan 28, 2019
1 parent 8f77dcf commit 74713d4
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/Enemies/PlayerBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void Die()

public void winLevel()
{
SceneManager.LoadScene("WinMenu");
SceneManager.LoadScene(Scene.MENU_WIN);
}

public void TeleportTo(DropTile tile)
Expand Down
11 changes: 11 additions & 0 deletions Unity/Assets/Scripts/SceneManagement/Scene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum Scene
{
MENU_MAIN,
MENU_CREDITS,
MENU_WIN,

}
11 changes: 11 additions & 0 deletions Unity/Assets/Scripts/SceneManagement/Scene.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Unity/Assets/Scripts/SceneManagement/SceneManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public static class SceneManager
{
public static void LoadScene(Scene scene)
{
switch(scene)
{
case Scene.MENU_MAIN:
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
break;
case Scene.MENU_CREDITS:
UnityEngine.SceneManagement.SceneManager.LoadScene("CreditMenu");
break;
case Scene.MENU_WIN:
UnityEngine.SceneManagement.SceneManager.LoadScene("WinMenu");
break;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Unity/Assets/Scripts/UIScripts/Credit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene("MainMenu");
SceneManager.LoadScene(Scene.MENU_MAIN);
}


}

public void LoadMenu()
{
SceneManager.LoadScene("MainMenu");
SceneManager.LoadScene(Scene.MENU_MAIN);
}

}
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/UIScripts/GameOver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Show()

public void Retry()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
canvas.SetActive(false);
}
}
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/UIScripts/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GameUI : MonoBehaviour
// Start is called before the first frame update
public void ReloadScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
}

public void LoadPause()
Expand Down
4 changes: 2 additions & 2 deletions Unity/Assets/Scripts/UIScripts/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public void Play()
}

GameState.Reset();
SceneManager.LoadScene("Level 1");
UnityEngine.SceneManagement.SceneManager.LoadScene("Level 1");
}

public void LoadCredits()
{
SceneManager.LoadScene("CreditMenu");
SceneManager.LoadScene(Scene.MENU_CREDITS);
}

public void QuitGame()
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/UIScripts/PauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Resume()
public void LoadMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene("SplashScreen");
SceneManager.LoadScene(Scene.MENU_MAIN);
}

public void Pause()
Expand Down
7 changes: 3 additions & 4 deletions Unity/Assets/Scripts/UIScripts/Win.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Win : MonoBehaviour
{
Expand All @@ -11,14 +10,14 @@ public void LoadNextLevel()
{
if(GameState.nexLevel >= 0)
{
SceneManager.LoadScene("Level " + GameState.nexLevel);
UnityEngine.SceneManagement.SceneManager.LoadScene("Level " + GameState.nexLevel);
}else{
SceneManager.LoadScene("CreditMenu");
SceneManager.LoadScene(Scene.MENU_CREDITS);
}
}

public void BackToMenu()
{
SceneManager.LoadScene("MainMenu");
SceneManager.LoadScene(Scene.MENU_MAIN);
}
}

0 comments on commit 74713d4

Please sign in to comment.