diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/MyGame.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/MyGame.cs index 048dc0b3139..8f2cae36b08 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/MyGame.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/MyGame.cs @@ -40,6 +40,7 @@ public class MyGame : Game _Register(); _Register(); + _Register(); SDKManager.Instance.Init(); } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/System.meta b/ProjectNLD/Assets/Code/Scripts/Gameplay/System.meta new file mode 100644 index 00000000000..41c89265d5f --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/System.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed176476819284747b5ba270e7b3d698 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs new file mode 100644 index 00000000000..53fb76182c1 --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs @@ -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); + } + } +} + +/// +/// 管理游戏中所有的系统 +/// +public class SystemManager : Singlenton, IInitable +{ + private Dictionary _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 +} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs.meta b/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs.meta new file mode 100644 index 00000000000..ee51d1aeb5d --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/System/SystemManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c62d2eb2a3a7ca543a74da429b2d053b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs new file mode 100644 index 00000000000..749c5d710fc --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +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); + } + + /// + /// 系统类型 + /// + public ESystemType Id { get; private set; } + /// + /// 解锁条件 + /// + public int[] Unlock { get; private set; } + + public const int __ID__ = 122753803; + public override int GetTypeId() => __ID__; + + public void Resolve(Dictionary _tables) + { + PostResolve(); + } + + public void TranslateText(System.Func translator) + { + } + + public override string ToString() + { + return "{ " + + "Id:" + Id + "," + + "Unlock:" + Bright.Common.StringUtil.CollectionToString(Unlock) + "," + + "}"; + } + + partial void PostInit(); + partial void PostResolve(); +} +} diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs.meta b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs.meta new file mode 100644 index 00000000000..db1f761a4eb --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/DataSystemCfg.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 637a4d3e083967340b200f136dae8762 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs new file mode 100644 index 00000000000..04fe62b8b6a --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs @@ -0,0 +1,25 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace cfg +{ + public enum ESystemType + { + None = 0, + /// + /// 邮件 + /// + Mail = 1, + /// + /// 关卡 + /// + Level = 2, + } + +} diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs.meta b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs.meta new file mode 100644 index 00000000000..fc68fbd14fb --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/ESystemType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 66ea47a7da406c544bf888ff44178a2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs new file mode 100644 index 00000000000..1e77c8d6b42 --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +using Bright.Serialization; +using System.Collections.Generic; +using SimpleJSON; + + + +namespace cfg +{ + +public sealed partial class SystemCfg +{ + private readonly Dictionary _dataMap; + private readonly List _dataList; + + public SystemCfg(JSONNode _json) + { + _dataMap = new Dictionary(); + _dataList = new List(); + + foreach(JSONNode _row in _json.Children) + { + var _v = DataSystemCfg.DeserializeDataSystemCfg(_row); + _dataList.Add(_v); + _dataMap.Add(_v.Id, _v); + } + PostInit(); + } + + public Dictionary DataMap => _dataMap; + public List 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 _tables) + { + foreach(var v in _dataList) + { + v.Resolve(_tables); + } + PostResolve(); + } + + public void TranslateText(System.Func translator) + { + foreach(var v in _dataList) + { + v.TranslateText(translator); + } + } + + + partial void PostInit(); + partial void PostResolve(); +} + +} \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs.meta b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs.meta new file mode 100644 index 00000000000..e8abf97cb6f --- /dev/null +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/SystemCfg.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e612b91434774ff4693222d53ee3e263 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/Tables.cs b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/Tables.cs index 49f8f8ed0d3..e960e02899e 100644 --- a/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/Tables.cs +++ b/ProjectNLD/Assets/Code/Scripts/GenCode/Luban/DataTable/Tables.cs @@ -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 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 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 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(); diff --git a/ProjectNLD/Assets/Config/Data/systemcfg.json b/ProjectNLD/Assets/Config/Data/systemcfg.json new file mode 100644 index 00000000000..589a966c47d --- /dev/null +++ b/ProjectNLD/Assets/Config/Data/systemcfg.json @@ -0,0 +1,14 @@ +[ + { + "Id": 1, + "Unlock": [ + 101 + ] + }, + { + "Id": 2, + "Unlock": [ + 101 + ] + } +] \ No newline at end of file diff --git a/ProjectNLD/Assets/Config/Data/systemcfg.json.meta b/ProjectNLD/Assets/Config/Data/systemcfg.json.meta new file mode 100644 index 00000000000..d83e3dc3d86 --- /dev/null +++ b/ProjectNLD/Assets/Config/Data/systemcfg.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fa524b2256145eb45bd5eb48252ce2f3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: