Preview Field Attribute特性:用于繪制一個方形ObjectField糊啡,它呈現(xiàn)UnityEngine.Object類型的預覽。此對象字段還添加了對拖放的支持菇怀,將對象拖動到另一個方形對象字段,交換值晌块。如果在放開時按住控制它將替換值爱沟,并且您可以Ctr+單擊對象字段以快速刪除它保存的值。
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;
public class PreviewFieldAttributeExample : MonoBehaviour
{
[VerticalGroup("row1/left")]
public string A, B, C;
[HideLabel]
[PreviewField(50, ObjectFieldAlignment.Right)]
[HorizontalGroup("row1", 50), VerticalGroup("row1/right")]
public Object D;
[HideLabel]
[PreviewField(50, ObjectFieldAlignment.Left)]
[HorizontalGroup("row2", 50), VerticalGroup("row2/left")]
public Object E;
[VerticalGroup("row2/right"), LabelWidth(-54)]
public string F, G, H;
[InfoBox(
"還可以有選擇地全局啟用和定制這些對象字段" +
"在 the Odin preferences window.\n\n" +
" - 長安 Ctrl + 點擊 = 刪除\n" +
" - 拖拽 = 移動或替換.\n" +
" - Ctrl + Drag = 替換.\n" +
" - Ctrl + drag and drop = Move and override.")]
[PropertyOrder(-1)]
[Button(ButtonSizes.Large)]
private void ConfigureGlobalPreviewFieldSettings()
{
Sirenix.OdinInspector.Editor.GeneralDrawerConfig.Instance.OpenInEditor();
}
}