2025-07-01 17:54:39 +08:00

86 lines
1.3 KiB
C#

using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VarController : MonoSingleton<VarController>
{
public Dictionary<string, float> varDict;
public override void OnSingletonInit()
{
base.OnSingletonInit();
varDict = new Dictionary<string, float>();
TypeEventSystem.Global.Register<OnModuleQuit>(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject);
}
private void OnQuit(OnModuleQuit quit)
{
varDict.Clear();
}
public void Set(string key, float value)
{
if (varDict.ContainsKey(key))
{
varDict[key] = value;
}
else
{
varDict.Add(key, value);
}
}
public float Get(string key)
{
if (varDict.ContainsKey(key))
{
return varDict[key];
}
else
{
return 0;
}
}
protected override void OnDestroy()
{
base.OnDestroy();
if (varDict!=null)
{
varDict.Clear();
varDict = null;
}
}
[ContextMenu("Êä³öÒ»±é¿ØÖƱäÁ¿")]
public void DebugVarController()
{
foreach (var item in varDict)
{
Debug.Log(item.Key+ "!!!"+item.Value+"???");
}
}
}