64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using SLSUtilities.General;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame
|
|
{
|
|
public partial class InfoTransistor : Singleton<InfoTransistor>
|
|
{
|
|
public HashSet<string> flags = new HashSet<string>();
|
|
public Dictionary<string, int> intInfo = new Dictionary<string, int>();
|
|
public Dictionary<string, string> stringInfo = new Dictionary<string, string>();
|
|
|
|
protected override void Awake()
|
|
{
|
|
Initialize(true);
|
|
}
|
|
}
|
|
|
|
public partial class InfoTransistor
|
|
{
|
|
public static void SetInfo(string key)
|
|
{
|
|
Instance.flags.Add(key);
|
|
}
|
|
|
|
public static void SetInfo<T>(string key, T value)
|
|
{
|
|
if (typeof(T) == typeof(int))
|
|
{
|
|
Instance.intInfo[key] = (int)(object)value;
|
|
}
|
|
else if (typeof(T) == typeof(string))
|
|
{
|
|
Instance.stringInfo[key] = (string)(object)value;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"Unsupported type {typeof(T)} for InfoTransistor.");
|
|
}
|
|
}
|
|
|
|
public static T GetInfo<T>(string key)
|
|
{
|
|
if (typeof(T) == typeof(int))
|
|
{
|
|
return Instance.intInfo.TryGetValue(key, out int value) ? (T)(object)value : default;
|
|
}
|
|
|
|
if (typeof(T) == typeof(string))
|
|
{
|
|
return Instance.stringInfo.TryGetValue(key, out string value) ? (T)(object)value : default;
|
|
}
|
|
|
|
if(typeof(T) == typeof(bool))
|
|
{
|
|
return (T)(object)Instance.flags.Contains(key);
|
|
}
|
|
|
|
Debug.LogError($"Unsupported type {typeof(T)} for InfoTransistor.");
|
|
return default;
|
|
}
|
|
}
|
|
} |