86 lines
1.3 KiB
C#
Raw Normal View History

2024-12-14 18:27:59 +08:00
using QFramework;
using System;
2024-12-14 18:27:59 +08:00
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);
2024-12-14 18:27:59 +08:00
}
private void OnQuit(OnModuleQuit quit)
{
varDict.Clear();
}
2024-12-14 18:27:59 +08:00
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();
2025-02-07 17:06:19 +08:00
if (varDict!=null)
{
varDict.Clear();
varDict = null;
}
2024-12-14 18:27:59 +08:00
}
2025-07-01 17:54:39 +08:00
[ContextMenu("<22><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>")]
public void DebugVarController()
{
foreach (var item in varDict)
{
2024-12-14 18:27:59 +08:00
2025-07-01 17:54:39 +08:00
Debug.Log(item.Key+ "!!!"+item.Value+"???");
}
}
2024-12-14 18:27:59 +08:00
}