本文主要是介绍Odin Inspector 系列教程 --- On State Update Attribute,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
StateUpdate可以使用在属性字段上,,属性的状态更新时,OnStateUpdate提供事件回调。回调频率每帧至少发生一次,即使属性不可见,也会调用回调。它相当于自定义一个更新回调函数,并且可以通过@+表达式的形式进行回调。

image
using Sirenix.OdinInspector;
using System.Collections.Generic;
using UnityEngine;public class OnStateUpdateAttributeExample : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}public List<string> list_0;[OnStateUpdate("@#(list_0).State.Expanded = $value")]public bool ExpandList;//此 bool 值通过上述表达式控制 list_0 列表[OnStateUpdate("@$property.State.Expanded = ExpandList_1")]public List<string> list_1;public bool ExpandList_1;[OnStateUpdate("@$property.State.Visible = ToggleMyInt")]public int MyInt;public bool ToggleMyInt;[OnStateUpdate("CustomPropertyUpdateCallBack")]public string MyString;private void CustomPropertyUpdateCallBack(string tempMyString){if (!string.IsNullOrEmpty(tempMyString)){Debug.Log(tempMyString);}}
}
调用自定义回调效果

image
更多教程内容详见:革命性Unity 编辑器扩展工具 --- Odin Inspector 系列教程
这篇关于Odin Inspector 系列教程 --- On State Update Attribute的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!