Skip to content
Snippets Groups Projects
Data.cs 1.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • David Huss's avatar
    David Huss committed
    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);
            }
    
    David Huss's avatar
    David Huss committed
            Debug.LogFormat("[{0}] Current Scene after Awake is: {1}", this.gameObject.name, currentScene);
    
    David Huss's avatar
    David Huss committed
        }
    
        public void RegisterSound(string name) {
    
    David Huss's avatar
    David Huss committed
            Debug.LogFormat("[{0}] Registering Sound as Played: {1}", this.gameObject.name, name);
    
    David Huss's avatar
    David Huss committed
            PlayedList.Add(name);
        }
    
        public bool PlayedSound(string name) {
            return PlayedList.Contains(name);
        }
    
        public void UpdateScene(string SceneName){
            // Unloading old scene
            SceneManager.UnloadSceneAsync(currentScene);
    
    David Huss's avatar
    David Huss committed
            Debug.LogFormat("[{0}] Scene Switch from {1} to {2} completed", this.gameObject.name, currentScene, SceneName);
    
    David Huss's avatar
    David Huss committed
            // Updating new scene
            currentScene = SceneName;
            RegisterScene(SceneName);
        }
    
        public void RegisterScene(string name) {
            if (!WasThereBefore(name)) {
                VisitedScenes.Add(name);
    
    David Huss's avatar
    David Huss committed
                Debug.LogFormat("[{0}] Registered Scene as Visited: {1}", this.gameObject.name, name);
    
    David Huss's avatar
    David Huss committed
            }
        }
    
        // 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);
        }
        
    }