On Value Changed Attribute:處理屬性和字段秘豹,并且只要通過檢查器更改了值,就會調(diào)用指定的函數(shù)舶治。
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnValueChangedAttributeExample : MonoBehaviour
{
[ShowInInspector]
[EnumPaging, OnValueChanged("SetCurrentTool")]
[InfoBox("更改此屬性將更改Unity編輯器中當(dāng)前選擇的工具.")]
private UnityEditor.Tool sceneTool;
private void SetCurrentTool()
{
UnityEditor.Tools.current = this.sceneTool;
Debug.Log($"更改為:{UnityEditor.Tools.current}");
}
[OnValueChanged("CreateMaterial")]
public Shader Shader;
[ReadOnly, InlineEditor(InlineEditorModes.LargePreview)]
public Material Material;
private void CreateMaterial()
{
if (this.Material != null)
{
Material.DestroyImmediate(this.Material);
}
if (this.Shader != null)
{
this.Material = new Material(this.Shader);
}
}
}