Update: inspector section

This commit is contained in:
AnnulusGames 2024-02-20 11:08:34 +09:00
parent 10e4173f6f
commit f0cae5823e
11 changed files with 115 additions and 78 deletions

View File

@ -0,0 +1,46 @@
# Button属性
メソッドに`[Button]`属性を追加することで、Inspector上にメソッドを実行するボタンを表示できます。
```cs
using System;
using System.Text;
using UnityEngine;
using Alchemy.Inspector;
[Serializable]
public sealed class SampleClass
{
public float foo;
public Vector3 bar;
public GameObject baz;
}
public class ButtonAttributeExample : MonoBehaviour
{
[Button]
public void Foo()
{
Debug.Log("Foo");
}
[Button]
public void Foo(int parameter)
{
Debug.Log("Foo: " + parameter);
}
[Button]
public void Foo(SampleClass parameter)
{
var builder = new StringBuilder();
builder.AppendLine();
builder.Append("foo = ").AppendLine(parameter.foo.ToString());
builder.Append("bar = ").AppendLine(parameter.bar.ToString());
builder.Append("baz = ").Append(parameter.baz == null ? "Null" : parameter.baz.ToString());
Debug.Log("Foo: " + builder.ToString());
}
}
```
![img](../../images/img-button.png)

View File

@ -0,0 +1,61 @@
# グループ属性
Alchemyでは、フィールドをグループ化する属性が提供されています。
```cs
using UnityEngine;
using Alchemy.Inspector;
public class GroupAttributesExample : MonoBehaviour
{
[FoldoutGroup("Foldout")]
public int a;
[FoldoutGroup("Foldout")]
public int b;
[FoldoutGroup("Foldout")]
public int c;
[TabGroup("Tab", "Tab1")]
public int x;
[TabGroup("Tab", "Tab2")]
public string y;
[TabGroup("Tab", "Tab3")]
public Vector3 z;
}
```
![img](../../images/img-group-1.png)
各グループはスラッシュで区切ることでネストできます。
```cs
using UnityEngine;
using Alchemy.Inspector;
public class GroupAttributesExample : MonoBehaviour
{
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box1")]
public float foo;
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box1")]
public Vector3 bar;
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box1")]
public GameObject baz;
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box2")]
public float alpha;
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box2")]
public Vector3 beta;
[HorizontalGroup("Horizontal"), BoxGroup("Horizontal/Box2")]
public GameObject gamma;
}
```
![img](../../images/img-group-2.png)

View File

@ -1,4 +1,4 @@
# 属性を使用したInspector拡張
# 属性を用いたInspector拡張
Alchemyでは属性を用いてInspectorを拡張することが可能です。Inspectorの表示をカスタマイズしたい場合には、クラスが持つフィールドに属性を付加します。
@ -7,7 +7,7 @@ using UnityEngine;
using UnityEngine.UIElements;
using Alchemy.Inspector; // Alchemy.Inspector名前空間をusingに追加
public class BasicAttributesSample : MonoBehaviour
public class AttributesExample : MonoBehaviour
{
[LabelText("Custom Label")]
public float foo;
@ -25,78 +25,4 @@ public class BasicAttributesSample : MonoBehaviour
}
```
![img1](../../images/img1.png)
各フィールドをグループ化する属性もいくつか用意されています。各グループはスラッシュで区切ることでネストできます。
```cs
using UnityEngine;
using Alchemy.Inspector;
public class GroupAttributesSample : MonoBehaviour
{
[FoldoutGroup("Foldout")] public int a;
[FoldoutGroup("Foldout")] public int b;
[FoldoutGroup("Foldout")] public int c;
[TabGroup("Tab", "Tab1")] public int x;
[TabGroup("Tab", "Tab2")] public string y;
[TabGroup("Tab", "Tab3")] public Vector3 z;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box1")] public float foo;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box1")] public Vector3 bar;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box1")] public GameObject baz;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box2")] public float alpha;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box2")] public Vector3 beta;
[HorizontalGroup("Horizontal")][BoxGroup("Horizontal/Box2")] public GameObject gamma;
}
```
![img2](../../images/img2.png)
メソッドに`[Button]`属性を付加することで、メソッドをInspectorから実行することが可能になります。
```cs
using System.Text;
using UnityEngine;
using Alchemy.Inspector;
[Serializable]
public sealed class SampleClass : ISample
{
public float foo;
public Vector3 bar;
public GameObject baz;
}
public class ButtonSample : MonoBehaviour
{
[Button]
public void Foo()
{
Debug.Log("Foo");
}
[Button]
public void Foo(int parameter)
{
Debug.Log("Foo: " + parameter);
}
[Button]
public void Foo(SampleClass parameter)
{
var builder = new StringBuilder();
builder.AppendLine();
builder.Append("foo = ").AppendLine(parameter.foo.ToString());
builder.Append("bar = ").AppendLine(parameter.bar.ToString());
builder.Append("baz = ").Append(parameter.baz == null ? "Null" : parameter.baz.ToString());
Debug.Log("Foo: " + builder.ToString());
}
}
```
![img3](../../images/img3.png)
他にもAlchemyでは数多くの属性が用意されています。詳細は属性一覧を参照してください。
![img](../../images/img-attributes-example.png)

View File

@ -5,8 +5,12 @@
href: installation.md
- name: Inspector
- name: 属性を使用したInspector拡張
- name: 属性を用いたInspector拡張
href: inspector-extension-using-attributes.md
- name: グループ属性
href: group-attributes.md
- name: Button属性
href: button-attribute.md
- name: SerializeReference
href: serialize-reference.md
- name: 属性一覧

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
docs/images/img-button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
docs/images/img-group-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
docs/images/img-group-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB