using System; using System.Collections.Generic; using Sirenix.OdinInspector; using SLSUtilities.General; using UnityEngine; namespace Cielonos.MainGame { public partial class InfoTransistor : Singleton { public HashSet flags = new HashSet(); public Dictionary customInfo = new Dictionary(); protected override void Awake() { Initialize(true); } } public partial class InfoTransistor { public static void SetFlag(string key) { Instance.flags.Add(key); } public static void SetInfo(string key, T value) { Instance.customInfo[key] = value; } public static T GetInfo(string key) { if (typeof(T) == typeof(bool)) { return (T)(object)Instance.flags.Contains(key); } if (Instance.customInfo.TryGetValue(key, out object value)) { if (value is T typedValue) { return typedValue; } // 兼容可能存在的隐式/强制类型转换(如 int -> float 或数值类型转换) try { return (T)Convert.ChangeType(value, typeof(T)); } catch { Debug.LogError($"[InfoTransistor] Cannot cast object with key '{key}' from {value.GetType().Name} to {typeof(T).Name}."); } } return default; } public static void ClearAll() { Instance.flags.Clear(); Instance.customInfo.Clear(); } } }