Horizo??ntalGroup特性:用于在檢查器中水平分組多個屬性。寬度可以指定為百分比或像素圆兵。0到1之間的所有值都將視為百分比砾层。如果寬度為0,則會自動調(diào)整列的大小拴泌。左右邊距只能以像素為單位指定魏身。
【Horizo??ntalGroup】制作一個水平分組
[HorizontalGroup]
public int A;
[HorizontalGroup("Group 1", LabelWidth = 20)]
public int C;
[HorizontalGroup("Group 1")]
public int D;
[HorizontalGroup("Group 1")]
public int E;
也可以在一個橫向Group中分類不同的BoxGroup
[HorizontalGroup("Split", 0.5f, LabelWidth = 40)]
[BoxGroup("Split/Left")]
public int L;
[BoxGroup("Split/Left")]
public int N;
[BoxGroup("Split/Right")]
public int M;
[BoxGroup("Split/Right")]
public int O;
劃分一個Buttons in Boxes折頁,在這個折頁中劃分一個Buttons in Boxes/Horizontal 組蚪腐,然后在這個Horizontal Group中劃分兩個Box
[Button(ButtonSizes.Large)]
[FoldoutGroup("Buttons in Boxes")]
[HorizontalGroup("Buttons in Boxes/Horizontal")]
[BoxGroup("Buttons in Boxes/Horizontal/One")]
public void Button1() { }
[Button(ButtonSizes.Large)]
[BoxGroup("Buttons in Boxes/Horizontal/Two")]
public void Button2() { }
[Button]
[HorizontalGroup("Buttons in Boxes/Horizontal", Width = 60)]
[BoxGroup("Buttons in Boxes/Horizontal/Double")]
public void Accept() { }
[Button]
[BoxGroup("Buttons in Boxes/Horizontal/Double")]
public void Cancel() { }
輔助類設置:MarginLeft箭昵、MarginRight(左右邊距)、PaddingLeft回季、PaddingRight(組與組的邊距)家制、MinWidth與MaxWidth間距正林,設置Title標題
完整示例代碼
using Sirenix.OdinInspector;
using UnityEngine;
public class HorizontalGroupAttributeExample : MonoBehaviour
{
[HorizontalGroup]
public int A;
[HorizontalGroup("Group 1", LabelWidth = 20)]
public int C;
[HorizontalGroup("Group 1")]
public int D;
[HorizontalGroup("Group 1")]
public int E;
[PropertySpace(40, 40)]
public string space = "";
[HorizontalGroup("Split", 0.5f, LabelWidth = 40)]
[BoxGroup("Split/Left")]
public int L;
[BoxGroup("Split/Left")]
public int N;
[BoxGroup("Split/Right")]
public int M;
[BoxGroup("Split/Right")]
public int O;
[PropertySpace(40, 40)]
public string space1 = "";
[Button(ButtonSizes.Large)]
[FoldoutGroup("Buttons in Boxes")]
[HorizontalGroup("Buttons in Boxes/Horizontal")]
[BoxGroup("Buttons in Boxes/Horizontal/One")]
public void Button1() { }
[Button(ButtonSizes.Large)]
[BoxGroup("Buttons in Boxes/Horizontal/Two")]
public void Button2() { }
[Button]
[HorizontalGroup("Buttons in Boxes/Horizontal", Width = 60)]
[BoxGroup("Buttons in Boxes/Horizontal/Double")]
public void Accept() { }
[Button]
[BoxGroup("Buttons in Boxes/Horizontal/Double")]
public void Cancel() { }
}