From a7622f1e5ebc5cbc47cf1e7d6ea5280ec6eceac1 Mon Sep 17 00:00:00 2001 From: MichaelO Date: Fri, 8 Dec 2023 10:28:21 +0800 Subject: [PATCH] updated to v2.9.8 (AutoBind section) --- Assets/OxGFrame/CHANGELOG.md | 19 +++++++++++ .../Editor/BindCodeAutoGenerateEditor.cs | 27 +++++++++++---- .../Scripts/Editor/BindCodeSetting.cs | 34 ++++++++++++++++++- .../Runtime/Core/Implement/FrameBase.cs | 8 ++++- Assets/OxGFrame/package.json | 2 +- .../Settings/OxGFrame/BindCodeSetting.asset | 1 + 6 files changed, 82 insertions(+), 9 deletions(-) diff --git a/Assets/OxGFrame/CHANGELOG.md b/Assets/OxGFrame/CHANGELOG.md index 4153507e..cdb2ad01 100644 --- a/Assets/OxGFrame/CHANGELOG.md +++ b/Assets/OxGFrame/CHANGELOG.md @@ -1,5 +1,24 @@ # CHANGELOG +## [2.9.8] - 2023-12-08 +- Added Generate binding code rule (MethodType: Manual, Auto, default is Auto). +```C# + #region Binding Components + protected Image _bgImg; + protected Text _msgTxt; + + /// + /// Auto Binding Section + /// + protected override void OnAutoBind() + { + base.OnAutoBind(); + this._bgImg = this.collector.GetNodeComponent("Bg*Img"); + this._msgTxt = this.collector.GetNodeComponent("Msg*Txt"); + } + #endregion +``` + ## [2.9.7] - 2023-12-07 - Modified repair procedure (Supports patch repair during download). - Modified BundleDemo in Samples. diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeAutoGenerateEditor.cs b/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeAutoGenerateEditor.cs index 43e0473e..3e5f56be 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeAutoGenerateEditor.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeAutoGenerateEditor.cs @@ -214,12 +214,27 @@ private static void _GenerateCodes() #endregion #region 方法定義生成 - _builder += "\n"; - _builder += "/// \n"; - _builder += "/// Don't forget to call via OnBind method\n"; - _builder += "/// \n"; - _builder += $"{_settings.methodAccessModifier} void {_settings.methodPrefix}{_settings.methodName}()\n"; - _builder += "{\n"; + switch (_settings.methodType) + { + case BindCodeSetting.MethodType.Auto: + _builder += "\n"; + _builder += "/// \n"; + _builder += "/// Auto Binding Section\n"; + _builder += "/// \n"; + _builder += $"{_settings.GetMethodAccessModifier()} override void {_settings.GetMethodName()}()\n"; + _builder += "{\n"; + _builder += $" base.{_settings.GetMethodName()}();\n"; + break; + default: + _builder += "\n"; + _builder += "/// \n"; + _builder += "/// Don't forget to call via OnBind method\n"; + _builder += "/// \n"; + _builder += $"{_settings.GetMethodAccessModifier()} void {_settings.methodPrefix}{_settings.GetMethodName()}()\n"; + _builder += "{\n"; + break; + } + foreach (var bindInfo in _collectBindInfos) { // Array diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeSetting.cs b/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeSetting.cs index 44e1586b..45714345 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeSetting.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeSetting.cs @@ -8,6 +8,12 @@ namespace OxGFrame.CoreFrame.Editor [CreateAssetMenu(fileName = nameof(BindCodeSetting), menuName = "OxGFrame/Create Settings/Create Bind Code Setting")] public class BindCodeSetting : ScriptableObject { + public enum MethodType + { + Manual = 1, + Auto = 0 + } + [Serializable] public struct Pluralize { @@ -52,9 +58,13 @@ public enum IndicateModifier public string variablePrefix = "_"; [Separator("Method Setting")] + public MethodType methodType = MethodType.Auto; + [ConditionalField(nameof(methodType), false, MethodType.Manual)] public string methodAccessModifier = "protected"; + [ConditionalField(nameof(methodType), false, MethodType.Manual)] public string methodPrefix = ""; - public string methodName = "InitBindingComponents"; + [ConditionalField(nameof(methodType), false, MethodType.Manual)] + public string methodName = "InitBind"; [Separator("Indicate Modifier Setting")] public IndicateModifier indicateModifier = IndicateModifier.This; @@ -99,6 +109,28 @@ public string GetIndicateModifier() } } + public string GetMethodAccessModifier() + { + switch (this.methodType) + { + case MethodType.Auto: + return "protected"; + default: + return this.methodAccessModifier; + } + } + + public string GetMethodName() + { + switch (this.methodType) + { + case MethodType.Auto: + return "OnAutoBind"; + default: + return this.methodName; + } + } + #region ContextMenus [Space(2.5f)] [ButtonClicker(nameof(SortTailRules), "Sort Tail Rules (A-Z)", "#00ffd1")] diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/Implement/FrameBase.cs b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/Implement/FrameBase.cs index 972deeeb..a2fd629b 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/Implement/FrameBase.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/Implement/FrameBase.cs @@ -7,7 +7,7 @@ namespace OxGFrame.CoreFrame { /// /// - /// Init Order: Awake (Once) > OnCreate (Once) > OnBind (Once) > PreInit (EveryOpen) > OnPreShow (EveryOpen) > OnShow (EveryOpen) + /// Init Order: Awake (Once) > OnCreate (Once) > OnAutoBind (Once) > OnBind (Once) > PreInit (EveryOpen) > OnPreShow (EveryOpen) > OnShow (EveryOpen) /// /// [DisallowMultipleComponent] @@ -161,6 +161,7 @@ public virtual void InitFirst() // 初次初始相關綁定組件與事件 if (!this._isInitFirst) { + this.OnAutoBind(); this.OnBind(); this._isInitFirst = true; } @@ -187,6 +188,11 @@ public async UniTask PreInit() /// protected abstract void OnPreClose(); + /// + /// 自動綁定初始區塊 (僅執行一次) + /// + protected virtual void OnAutoBind() { } + /// /// 初始相關綁定組件與事件 (僅執行一次) /// diff --git a/Assets/OxGFrame/package.json b/Assets/OxGFrame/package.json index 8ad8d99d..738f7fae 100644 --- a/Assets/OxGFrame/package.json +++ b/Assets/OxGFrame/package.json @@ -2,7 +2,7 @@ "name": "com.michaelo.oxgframe", "displayName": "OxGFrame", "description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.", - "version": "2.9.7", + "version": "2.9.8", "unity": "2021.3", "license": "MIT", "samples": [ diff --git a/Assets/Settings/OxGFrame/BindCodeSetting.asset b/Assets/Settings/OxGFrame/BindCodeSetting.asset index e15f0431..402ca640 100644 --- a/Assets/Settings/OxGFrame/BindCodeSetting.asset +++ b/Assets/Settings/OxGFrame/BindCodeSetting.asset @@ -15,6 +15,7 @@ MonoBehaviour: variableCaseType: 0 variableAccessModifier: protected variablePrefix: _ + methodType: 0 methodAccessModifier: protected methodPrefix: methodName: InitBindingComponents