Documentation for the Unity C# Library
Loading...
Searching...
No Matches
StatesService.cs
Go to the documentation of this file.
1using System;
2using PixoVR.Event;
3using PixoVR.Audio;
4using System.Collections.Generic;
5using UnityEngine;
6
7namespace PixoVR.Event
8{
12 public static class StatesService
13 {
14 private static readonly Dictionary<Type, object> _states = new Dictionary<Type, object>();
15
16 public static void SaveState<T>(T data)
17 {
18 if (_states.ContainsKey(typeof(T)))
19 {
20 _states[typeof(T)] = data;
21 }
22
23 else
24 {
25 _states.Add(typeof(T), data);
26 }
27 }
28
29 public static T GetState<T>(bool isCreateInstance = false) where T : class, new()
30 {
31 if (_states.TryGetValue(typeof(T), out object value))
32 {
33 return value as T;
34 }
35
36 Debug.LogWarning("State does not exist");
37
38 if(isCreateInstance)
39 {
40 var intance = new T();
41
42 SaveState(intance);
43
44 return intance;
45 }
46
47 return null;
48 }
49 }
50}
Logic for saving and unloading states during project execution.
static T GetState< T >(bool isCreateInstance=false)
static void SaveState< T >(T data)
static readonly Dictionary< Type, object > _states