美文网首页
Odin Inspector 系列教程 --- On State

Odin Inspector 系列教程 --- On State

作者: su9257_海澜 | 来源:发表于2020-12-21 08:57 被阅读0次
StateUpdate可以使用在属性字段上,,属性的状态更新时,OnStateUpdate提供事件回调。回调频率每帧至少发生一次,即使属性不可见,也会调用回调。它相当于自定义一个更新回调函数,并且可以通过@+表达式的形式进行回调。
image
using Sirenix.OdinInspector;
using System.Collections.Generic;
using UnityEngine;

public class OnStateUpdateAttributeExample : MonoBehaviour
{
    // Start is called before the first frame update
    void 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

      本文链接:https://www.haomeiwen.com/subject/tlflnktx.html