78 lines
1.1 KiB
C#
78 lines
1.1 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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|