From 32f3563c9d941500484bff175eebe8d34013ddcd Mon Sep 17 00:00:00 2001
From: David Huss <dh@atoav.com>
Date: Fri, 20 Nov 2020 20:10:38 +0100
Subject: [PATCH] Add Data.cs

---
 Assets/Data.cs        | 61 +++++++++++++++++++++++++++++++++++++++++++
 Assets/SceneSwitch.cs |  2 +-
 README.md             | 11 +++++---
 3 files changed, 70 insertions(+), 4 deletions(-)
 create mode 100644 Assets/Data.cs

diff --git a/Assets/Data.cs b/Assets/Data.cs
new file mode 100644
index 0000000..e7041d3
--- /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 e0faa19..38a7609 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 0c8143a..1e326b3 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
-- 
GitLab