diff --git a/Assets/Data.cs b/Assets/Data.cs new file mode 100644 index 0000000000000000000000000000000000000000..e7041d3d17b075e73fc579af52f490403e3aff5c --- /dev/null +++ b/Assets/Data.cs @@ -0,0 +1,61 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + + public class Data : MonoBehaviour + { + public bool debug = true; + public static Data instance; + public string currentScene; + public List<string> PlayedList = new List<string>(); + public List<string> VisitedScenes = new List<string>(); + + void Awake() { + if(instance == null) { + instance = this; + DontDestroyOnLoad(this.gameObject); + } + if (currentScene == "") { + currentScene = SceneManager.GetActiveScene().name; + RegisterScene(currentScene); + } + Debug.LogFormat("Current Scene after Awake is: {0}", currentScene); + } + + public void RegisterSound(string name) { + Debug.LogFormat("Registering Sound as Played: {0}", name); + PlayedList.Add(name); + } + + public bool PlayedSound(string name) { + return PlayedList.Contains(name); + } + + public void UpdateScene(string SceneName){ + // Unloading old scene + SceneManager.UnloadSceneAsync(currentScene); + Debug.LogFormat("Scene Switch from {0} to {1} completed", currentScene, SceneName); + // Updating new scene + currentScene = SceneName; + RegisterScene(SceneName); + } + + public void RegisterScene(string name) { + if (!WasThereBefore(name)) { + VisitedScenes.Add(name); + Debug.LogFormat("Registering Scene as Visited: {0}", name); + } + } + + // Return true if the scene was visited before + public bool WasThereBefore(string name) { + return VisitedScenes.Contains(name); + } + + // Return true if the current scene was visited before + public bool WasHereBefore() { + return VisitedScenes.Contains(currentScene); + } + +} diff --git a/Assets/SceneSwitch.cs b/Assets/SceneSwitch.cs index e0faa190e76515b4e7912e04a3e6a5fb06d6f0bd..38a7609004e3f3c856d3c3d17712e8e6e03d22cf 100644 --- a/Assets/SceneSwitch.cs +++ b/Assets/SceneSwitch.cs @@ -111,7 +111,7 @@ public class SceneSwitch : MonoBehaviour yield return null; } - // Data.instance.UpdateScene(SceneName); + Data.instance.UpdateScene(SceneName); } } diff --git a/README.md b/README.md index 0c8143ae46c7db34a4d22e647b6a5e9301e746cb..1e326b32d15626625b564ad5252cfc6c329ffa9b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ Allows you to switch the active Scene when a Triggervolume is entered, exited or when you stay in a trigger volume for long enough -1. Copy the Script `Assets/SceneSwitch.cs` to your assets folder -2. Drag it onto the Trigger Volume +1. Copy the Script `Assets/SceneSwitch.cs` and `Assets/Data.cs` to your assets folder +2. Drag `SceneSwitch.cs` onto the Trigger Volume 3. Enter a Scene Name (for the target Scene) -4. Select a mode (On Enter, On Exit, Countdown) \ No newline at end of file +4. Select a mode (On Enter, On Exit, Countdown) +5. Drag `Data.cs` onto an empty Gameobject called "Data" + + + +Data.cs can be used to transfer Data between scenes \ No newline at end of file