系统解锁
parent
095a49feec
commit
49f091b8c6
|
|
@ -40,6 +40,7 @@ public class MyGame : Game
|
|||
_Register<GameStateManager>();
|
||||
|
||||
_Register<MailSystem>();
|
||||
_Register<SystemManager>();
|
||||
SDKManager.Instance.Init();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed176476819284747b5ba270e7b3d698
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using cfg;
|
||||
using Framework;
|
||||
using Framework.Condition;
|
||||
using PhxhSDK;
|
||||
using UnityEngine;
|
||||
|
||||
public class SystemRuntimeInfo
|
||||
{
|
||||
private DataSystemCfg _cfg;
|
||||
|
||||
private bool _isOpen;
|
||||
|
||||
public ESystemType Type => _cfg.Id;
|
||||
|
||||
public int[] unlockCondition => _cfg.Unlock;
|
||||
|
||||
public bool IsOpen
|
||||
{
|
||||
get => _isOpen;
|
||||
set
|
||||
{
|
||||
if (_isOpen != value)
|
||||
{
|
||||
_isOpen = value;
|
||||
DebugUtil.Log($"系统{Type} {(_isOpen?"开启":"关闭")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SystemRuntimeInfo(DataSystemCfg cfg)
|
||||
{
|
||||
_cfg = cfg;
|
||||
if (unlockCondition == null || unlockCondition.Length == 0)
|
||||
{
|
||||
IsOpen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ConditionReactor.Instance.AddReaction(unlockCondition, OnConditionInvoke);
|
||||
}
|
||||
|
||||
private void OnConditionInvoke(bool conditionResult, object callBackParam, int reactionID)
|
||||
{
|
||||
if (conditionResult)
|
||||
{
|
||||
IsOpen = true;
|
||||
ConditionReactor.Instance.RemoveReaction(reactionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 管理游戏中所有的系统
|
||||
/// </summary>
|
||||
public class SystemManager : Singlenton<SystemManager>, IInitable
|
||||
{
|
||||
private Dictionary<ESystemType, SystemRuntimeInfo> _allSystemInfo = new();
|
||||
|
||||
#region MainLife
|
||||
|
||||
public void Init()
|
||||
{
|
||||
RegisterSignal();
|
||||
}
|
||||
|
||||
private void RegisterSignal()
|
||||
{
|
||||
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
|
||||
}
|
||||
|
||||
private void OnAllConfigLoad()
|
||||
{
|
||||
var allSystemCfg = TableManager.Instance.Tables.SystemCfg.DataMap;
|
||||
_allSystemInfo.Clear();
|
||||
foreach (var kv in allSystemCfg)
|
||||
{
|
||||
var systemType = kv.Key;
|
||||
if (systemType == ESystemType.None)
|
||||
continue;
|
||||
SystemRuntimeInfo systemRuntimeInfo = new(kv.Value);
|
||||
_allSystemInfo.Add(systemType, systemRuntimeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnRegisterSignal()
|
||||
{
|
||||
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
UnRegisterSignal();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region API
|
||||
|
||||
public SystemRuntimeInfo GetSystemRuntimeInfo(ESystemType systemType)
|
||||
{
|
||||
return _allSystemInfo.GetValueOrDefault(systemType);
|
||||
}
|
||||
|
||||
public bool IsSystemOpen(ESystemType systemType)
|
||||
{
|
||||
var systemInfo = GetSystemRuntimeInfo(systemType);
|
||||
if (systemInfo == null)
|
||||
return true;
|
||||
return systemInfo.IsOpen;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c62d2eb2a3a7ca543a74da429b2d053b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
|
||||
|
||||
namespace cfg
|
||||
{
|
||||
|
||||
public sealed partial class DataSystemCfg : Bright.Config.BeanBase
|
||||
{
|
||||
public DataSystemCfg(JSONNode _json)
|
||||
{
|
||||
{ if(!_json["Id"].IsNumber) { throw new SerializationException(); } Id = (ESystemType)_json["Id"].AsInt; }
|
||||
{ var __json0 = _json["Unlock"]; if(!__json0.IsArray) { throw new SerializationException(); } int _n0 = __json0.Count; Unlock = new int[_n0]; int __index0=0; foreach(JSONNode __e0 in __json0.Children) { int __v0; { if(!__e0.IsNumber) { throw new SerializationException(); } __v0 = __e0; } Unlock[__index0++] = __v0; } }
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public DataSystemCfg(ESystemType Id, int[] Unlock )
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Unlock = Unlock;
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public static DataSystemCfg DeserializeDataSystemCfg(JSONNode _json)
|
||||
{
|
||||
return new DataSystemCfg(_json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系统类型
|
||||
/// </summary>
|
||||
public ESystemType Id { get; private set; }
|
||||
/// <summary>
|
||||
/// 解锁条件
|
||||
/// </summary>
|
||||
public int[] Unlock { get; private set; }
|
||||
|
||||
public const int __ID__ = 122753803;
|
||||
public override int GetTypeId() => __ID__;
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{ "
|
||||
+ "Id:" + Id + ","
|
||||
+ "Unlock:" + Bright.Common.StringUtil.CollectionToString(Unlock) + ","
|
||||
+ "}";
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 637a4d3e083967340b200f136dae8762
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace cfg
|
||||
{
|
||||
public enum ESystemType
|
||||
{
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// 邮件
|
||||
/// </summary>
|
||||
Mail = 1,
|
||||
/// <summary>
|
||||
/// 关卡
|
||||
/// </summary>
|
||||
Level = 2,
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66ea47a7da406c544bf888ff44178a2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using SimpleJSON;
|
||||
|
||||
|
||||
|
||||
namespace cfg
|
||||
{
|
||||
|
||||
public sealed partial class SystemCfg
|
||||
{
|
||||
private readonly Dictionary<ESystemType, DataSystemCfg> _dataMap;
|
||||
private readonly List<DataSystemCfg> _dataList;
|
||||
|
||||
public SystemCfg(JSONNode _json)
|
||||
{
|
||||
_dataMap = new Dictionary<ESystemType, DataSystemCfg>();
|
||||
_dataList = new List<DataSystemCfg>();
|
||||
|
||||
foreach(JSONNode _row in _json.Children)
|
||||
{
|
||||
var _v = DataSystemCfg.DeserializeDataSystemCfg(_row);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.Id, _v);
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<ESystemType, DataSystemCfg> DataMap => _dataMap;
|
||||
public List<DataSystemCfg> DataList => _dataList;
|
||||
|
||||
public DataSystemCfg GetOrDefault(ESystemType key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public DataSystemCfg Get(ESystemType key) {
|
||||
if (_dataMap.TryGetValue(key, out var v)) {
|
||||
return v;
|
||||
} else {
|
||||
UnityEngine.Debug.LogError($"table SystemCfg key not found: {key}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public DataSystemCfg this[ESystemType key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e612b91434774ff4693222d53ee3e263
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -73,6 +73,7 @@ public sealed partial class Tables
|
|||
public SkillCfg.PlayerSkillConfig PlayerSkillConfig {get; }
|
||||
public ActorCfg.MailCfg MailCfg {get; }
|
||||
public ActorCfg.Shop Shop {get; }
|
||||
public SystemCfg SystemCfg {get; }
|
||||
|
||||
public Tables(System.Func<string, JSONNode> loader)
|
||||
{
|
||||
|
|
@ -191,6 +192,8 @@ public sealed partial class Tables
|
|||
tables.Add("ActorCfg.MailCfg", MailCfg);
|
||||
Shop = new ActorCfg.Shop(loader("actorcfg_shop"));
|
||||
tables.Add("ActorCfg.Shop", Shop);
|
||||
SystemCfg = new SystemCfg(loader("systemcfg"));
|
||||
tables.Add("SystemCfg", SystemCfg);
|
||||
PostInit();
|
||||
|
||||
CharacterAttri.Resolve(tables);
|
||||
|
|
@ -250,6 +253,7 @@ public sealed partial class Tables
|
|||
PlayerSkillConfig.Resolve(tables);
|
||||
MailCfg.Resolve(tables);
|
||||
Shop.Resolve(tables);
|
||||
SystemCfg.Resolve(tables);
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
|
|
@ -311,6 +315,7 @@ public sealed partial class Tables
|
|||
loader("skillcfg_playerskillconfig");
|
||||
loader("actorcfg_mailcfg");
|
||||
loader("actorcfg_shop");
|
||||
loader("systemcfg");
|
||||
}
|
||||
|
||||
public static void AfterLoaded(Action<string> loader) {
|
||||
|
|
@ -371,6 +376,7 @@ public sealed partial class Tables
|
|||
loader("skillcfg_playerskillconfig");
|
||||
loader("actorcfg_mailcfg");
|
||||
loader("actorcfg_shop");
|
||||
loader("systemcfg");
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
|
|
@ -432,6 +438,7 @@ public sealed partial class Tables
|
|||
PlayerSkillConfig.TranslateText(translator);
|
||||
MailCfg.TranslateText(translator);
|
||||
Shop.TranslateText(translator);
|
||||
SystemCfg.TranslateText(translator);
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
[
|
||||
{
|
||||
"Id": 1,
|
||||
"Unlock": [
|
||||
101
|
||||
]
|
||||
},
|
||||
{
|
||||
"Id": 2,
|
||||
"Unlock": [
|
||||
101
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa524b2256145eb45bd5eb48252ce2f3
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue