113 lines
3.0 KiB
C#
113 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Core.Base;
|
|
using CoreEventDefine = UnityEngine.Gonbest.MagicCube.CoreEventDefine;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
/// <summary>
|
|
/// 配置处理的基础类
|
|
/// </summary>
|
|
public class SettingProcessBase
|
|
{
|
|
//当配置被改变后的处理
|
|
private Dictionary<int, MyAction<int>> _settingChangedHandler = new Dictionary<int, MyAction<int>>();
|
|
|
|
//初始化
|
|
public void Initialize()
|
|
{
|
|
RegisterSettingChangeHandler();
|
|
GameCenter.EventManager.UnRegFixEventHandle(CoreEventDefine.EID_CORE_GAME_SETTING_CHANGED, OnSettingChanged);
|
|
GameCenter.EventManager.RegFixEventHandle(CoreEventDefine.EID_CORE_GAME_SETTING_CHANGED, OnSettingChanged);
|
|
OnInitializeAfter();
|
|
}
|
|
|
|
//加载默认配置
|
|
public void LoadDefault(bool isforce, bool save)
|
|
{
|
|
OnLoadDefault(isforce, save);
|
|
}
|
|
|
|
//进入场景时的调用
|
|
public void EnterScene(GameScene scene)
|
|
{
|
|
OnEnterScene(scene);
|
|
}
|
|
//卸载
|
|
public void Uninitialize()
|
|
{
|
|
OnUninitializeBefore();
|
|
GameCenter.EventManager.UnRegFixEventHandle(CoreEventDefine.EID_CORE_GAME_SETTING_CHANGED, OnSettingChanged);
|
|
}
|
|
|
|
#region//注册回调的处理函数
|
|
//配置信息改变
|
|
private void OnSettingChanged(object obj,object sender=null)
|
|
{
|
|
try
|
|
{
|
|
GameSettingKeyCode code = (GameSettingKeyCode)obj;
|
|
MyAction<int> handler;
|
|
if (_settingChangedHandler.TryGetValue((int)code, out handler))
|
|
{
|
|
if (handler != null)
|
|
{
|
|
var value = GameSettingCore.Get(code);
|
|
handler(value);
|
|
}
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
UnityEngine.Debug.LogException(ex);
|
|
}
|
|
}
|
|
|
|
//注册设置信息改变后的处理句柄
|
|
private void RegisterSettingChangeHandler()
|
|
{
|
|
_settingChangedHandler.Clear();
|
|
OnRegisterSettingChangedHandler();
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region//保护的函数,由子类继承
|
|
|
|
protected virtual void OnRegisterSettingChangedHandler()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void OnInitializeAfter()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void OnUninitializeBefore()
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void OnLoadDefault(bool isforce, bool save)
|
|
{
|
|
|
|
}
|
|
|
|
protected virtual void OnEnterScene(GameScene scene)
|
|
{
|
|
|
|
}
|
|
|
|
protected void AddSettingChangedHandler(GameSettingKeyCode code, MyAction<int> action)
|
|
{
|
|
_settingChangedHandler.Add((int)code, action);
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |