Skip to content

Commit

Permalink
updated to v2.9.8 (AutoBind section)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Dec 8, 2023
1 parent ac99614 commit a7622f1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
19 changes: 19 additions & 0 deletions Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Auto Binding Section
/// </summary>
protected override void OnAutoBind()
{
base.OnAutoBind();
this._bgImg = this.collector.GetNodeComponent<Image>("Bg*Img");
this._msgTxt = this.collector.GetNodeComponent<Text>("Msg*Txt");
}
#endregion
```

## [2.9.7] - 2023-12-07
- Modified repair procedure (Supports patch repair during download).
- Modified BundleDemo in Samples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,27 @@ private static void _GenerateCodes()
#endregion

#region 方法定義生成
_builder += "\n";
_builder += "/// <summary>\n";
_builder += "/// Don't forget to call via OnBind method\n";
_builder += "/// </summary>\n";
_builder += $"{_settings.methodAccessModifier} void {_settings.methodPrefix}{_settings.methodName}()\n";
_builder += "{\n";
switch (_settings.methodType)
{
case BindCodeSetting.MethodType.Auto:
_builder += "\n";
_builder += "/// <summary>\n";
_builder += "/// Auto Binding Section\n";
_builder += "/// </summary>\n";
_builder += $"{_settings.GetMethodAccessModifier()} override void {_settings.GetMethodName()}()\n";
_builder += "{\n";
_builder += $" base.{_settings.GetMethodName()}();\n";
break;
default:
_builder += "\n";
_builder += "/// <summary>\n";
_builder += "/// Don't forget to call via OnBind method\n";
_builder += "/// </summary>\n";
_builder += $"{_settings.GetMethodAccessModifier()} void {_settings.methodPrefix}{_settings.GetMethodName()}()\n";
_builder += "{\n";
break;
}

foreach (var bindInfo in _collectBindInfos)
{
// Array
Expand Down
34 changes: 33 additions & 1 deletion Assets/OxGFrame/CoreFrame/Scripts/Editor/BindCodeSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OxGFrame.CoreFrame
{
/// <summary>
/// <para>
/// 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)
/// </para>
/// </summary>
[DisallowMultipleComponent]
Expand Down Expand Up @@ -161,6 +161,7 @@ public virtual void InitFirst()
// 初次初始相關綁定組件與事件
if (!this._isInitFirst)
{
this.OnAutoBind();
this.OnBind();
this._isInitFirst = true;
}
Expand All @@ -187,6 +188,11 @@ public async UniTask PreInit()
/// </summary>
protected abstract void OnPreClose();

/// <summary>
/// 自動綁定初始區塊 (僅執行一次)
/// </summary>
protected virtual void OnAutoBind() { }

/// <summary>
/// 初始相關綁定組件與事件 (僅執行一次)
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions Assets/Settings/OxGFrame/BindCodeSetting.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MonoBehaviour:
variableCaseType: 0
variableAccessModifier: protected
variablePrefix: _
methodType: 0
methodAccessModifier: protected
methodPrefix:
methodName: InitBindingComponents
Expand Down

0 comments on commit a7622f1

Please sign in to comment.