Skip to content
Snippets Groups Projects
Select Git revision
  • 8c33d3a84c0fe5a25cfc5c35a41e043f3d5aa40f
  • master default protected
2 results

Data.cs

Blame
  • Data.cs 1.95 KiB
    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("[{0}] Current Scene after Awake is: {1}", this.gameObject.name, currentScene);
        }
    
        public void RegisterSound(string name) {
            Debug.LogFormat("[{0}] Registering Sound as Played: {1}", this.gameObject.name, 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("[{0}] Scene Switch from {1} to {2} completed", this.gameObject.name, currentScene, SceneName);
            // Updating new scene
            currentScene = SceneName;
            RegisterScene(SceneName);
        }
    
        public void RegisterScene(string name) {
            if (!WasThereBefore(name)) {
                VisitedScenes.Add(name);
                Debug.LogFormat("[{0}] Registered Scene as Visited: {1}", this.gameObject.name, 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);
        }
        
    }