Skip to content

Commit

Permalink
文檔 : 更新至 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
naukri7707 committed Nov 13, 2023
1 parent 91223c6 commit adde7fd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 40 deletions.
12 changes: 12 additions & 0 deletions Packages/com.naukri.inspector-maid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [2.3.0] - 2023-11-14

### 新增

- `IfScpoe` 系列小部件新增預設比較方法,減少產生不必要的判斷函式。

### 重構

- 簡化與快速反射相關的底層 API。
- 取消綁定約定以減少設計限制。
- 部分 `Widget` 使用 `Compose` 模組重寫,使其更具結構性。

## [2.2.0] - 2023-11-12

### 新增
Expand Down
96 changes: 57 additions & 39 deletions Packages/com.naukri.inspector-maid/Documentation/Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,20 @@ public void MyMethod()
public string message = "Hello World!";
```

- 如果要綁定物件本身請使用預先定義的關鍵字 `"this"`

- 依據綁定的成員類型不同,會有不同的回傳邏輯

1. 欄位:該欄位的數值。
2. 屬性:該屬性 `getMethod` 的回傳值,如果該屬性沒有 `getMethod` 則無法運行。
3. 函式:該函式調用後的回傳值,如果該函式有參數則需使用 `args` 定義參數。

```cs
// 如果只有一個參數,可以利用 params 關鍵字的特性,省略 new object[] { ... }
[HelpBox(binding: nameof(HelloMessage), args: "world")]
// 如果有多個參數,則必須使用 new object[] { ... } 來包裹
[HelpBox(binding: nameof(HelloTwoMessage), args: new object[] { "world", "you" })]
// 如果目標是帶參數函式,使用 new object[] { ... } 來包裹參數
[HelpBox(binding: nameof(HelloTwoMessage), args: new object[] { "Hello", "world" })]
public string message = "";

public string HelloMessage(string message)
{
return $"Hello {message}!";
}

public string HelloTwoMessage(string message1, string message2)

public string CombineMessage(string message1, string message2)
{
return $"Hello {message1} and {message2}!";
return $"{message1} {message2}!";
}
```

Expand Down Expand Up @@ -377,31 +368,6 @@ public void MyMethod()
```

![optional-variable-compare](Images/optional-variable-compare.png)

4. 如果想要支援資料綁定,你需要讓該 `WidgetAttribute` 繼承 `IBindable` 介面。為了統一綁定邏輯,我們約定永遠使 `binding` 及 `args` 作為最後兩個參數且 `args` 需使用 `params` 關鍵字。

```cs
public class MyItemAttribute : ItemAttribute, IBindable
{
public MyItemAttribute(
string myString,
string binding = null,
params object[] args
)
{
this.myString = myString;
this.binding = binding;
this.args = args;
}

public readonly string myString;

public string binding { get; }

public object[] args { get; }
}
```

### 建立 `Widget`

根據 `WidgetAttribute` 的不同,我們需要繼承的類別也有所不同
Expand Down Expand Up @@ -486,6 +452,58 @@ public class MyStylerWidget : StylerWidgetOf<MyStylerAttribute>
#### 內置 `Receiver`

- `IContextAttachedReceiver`:當該 `Widget``Context` 被附加到 `Context Tree` 時。

### 資料綁定

如果想要支援資料綁定,你可以在 `WidgetAttribute` 上實作 `IBindable` 介面使 `Widget` 可以使用包裝好的綁定函式,或者你也可以在 `Widget` 上直接使用 `GetValue()` 等函式來存取目標成員。

`MyItemAttribute.cs`
```cs
public class MyItemAttribute : ItemAttribute, IBindable
{
public MyItemAttribute(
string myString,
string binding = null,
params object[] args
)
{
this.myString = myString;
this.binding = binding;
this.args = args;
}

public readonly string myString;

public string binding { get; }

public object[] args { get; }
}
```

`MyItemWidget.cs`
```cs
public class MyItemWidget : ItemWidgetOf<MyItemAttribute>
{
public override VisualElement Build(IBuildContext context)
{
// 獲取綁定成員的值
var bindingValue = context.GetBindingValue();
// 監聽綁定成員的值
context.ListenBindingValue(value =>
{
// Do something on value changed
});

// 你也可以直接指定成員名稱來存取
var a = context.GetValue("memberName");
context.ListenValue("memberName" ,value =>
{
// Do something
});
}
}
```

## 内置小部件

你可以在 package 中的 Sample 中找到所有内置小部件的 demo 以及詳細的說明。
2 changes: 1 addition & 1 deletion Packages/com.naukri.inspector-maid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.naukri.inspector-maid",
"author": "Naukri",
"displayName": "Inspector Maid",
"version": "2.2.0",
"version": "2.3.0",
"unity": "2022.3",
"description": "This is a Unity Inspector UI customization feature.\r\n You can use it to create some simple interactive functionalities for your Component without the need to write a dedicated Editor. It has several key features:\r\n\r\n\u2022Uses UIElements for rendering.\r\n\r\n\u2022Allows direct access to properties and functions in the Inspector.\r\n\r\n\u2022Supports adding multiple widgets to the same target.\r\n\r\n\u2022Allows customization of custom widgets.\r\n\r\n\u2022Allows dynamic content modification through binding.",
"samples": [
Expand Down

0 comments on commit adde7fd

Please sign in to comment.