12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- namespace KairoEngine.CharacterSystem
- {
- /// <summary>
- /// Singleton that stores serialized data from scenes.
- /// </summary>
- 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<DataScene> scenesData = new List<DataScene>();
- public DataScene currentSceneData;
- void Awake()
- {
- //DontDestroyOnLoad(gameObject);
- }
- void OnEnable()
- {
- TransitionEvents.OnLocationName += ChangeCurrentSceneData;
- }
-
- void Ondisable()
- {
- TransitionEvents.OnLocationName += ChangeCurrentSceneData;
- }
- /// <summary>
- /// Function executed after OnLocation event, for changing the current sceneData object
- /// </summary>
- /// <param name="locationName">The name of the new location</param>
- private void ChangeCurrentSceneData(string locationName)
- {
- currentSceneData = GetSceneDataByname(locationName);
- if(currentSceneData == null)
- {
- currentSceneData = new DataScene();
- currentSceneData.locationName = locationName;
- scenesData.Add(currentSceneData);
- }
- currentSceneData.visited += 1;
- }
- /// <summary>
- /// Find a DataScene with using a location name.
- /// </summary>
- /// <param name="locationName">The name of the location to be searched</param>
- /// <returns>Requested DataScene object</returns>
- 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;
- }
- }
- }
|