using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core; namespace KairoEngine.CharacterSystem { /// /// Singleton that stores serialized data from scenes. /// public class DataManager : SerializedMonoBehaviour { #region Singleton private static DataManager dataManager; public static DataManager instance { get { if(!dataManager) { dataManager = FindObjectOfType (typeof(DataManager)) as DataManager; if(!dataManager) { //Debug.LogError("There need to one active DataManager script on the scene."); return null; } } return dataManager; } } #endregion public List scenesData = new List(); public DataScene currentSceneData; void Awake() { //DontDestroyOnLoad(gameObject); } void OnEnable() { TransitionEvents.OnLocationName += ChangeCurrentSceneData; } void Ondisable() { TransitionEvents.OnLocationName += ChangeCurrentSceneData; } /// /// Function executed after OnLocation event, for changing the current sceneData object /// /// The name of the new location private void ChangeCurrentSceneData(string locationName) { currentSceneData = GetSceneDataByname(locationName); if(currentSceneData == null) { currentSceneData = new DataScene(); currentSceneData.locationName = locationName; scenesData.Add(currentSceneData); } currentSceneData.visited += 1; } /// /// Find a DataScene with using a location name. /// /// The name of the location to be searched /// Requested DataScene object public DataScene GetSceneDataByname(string locationName) { DataScene dataScene = null; for (int i = 0; i < scenesData.Count; i++) { if(scenesData[i].locationName == locationName) { dataScene = scenesData[i]; break; } } return dataScene; } } }