本文主要是介绍Odin Inspector 系列教程 --- On Collection Changed Attribute,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
OnCollectionChanged可以放在集合上,通过inspector更改集合提供事件回调。此外,它提供了CollectionChangeInfo结构,其中包含有关对集合所做的详细更改的信息。但更改其对应Value的内部值是不会进行对应回调的。
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using System.Collections.Generic;
using UnityEngine;public class OnCollectionChangedAttributeExample : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}[InfoBox("更改集合则调用对应的回调,并获取详细更改描述.")][OnCollectionChanged("Before", "After")]public List<string> list = new List<string>() { "str1", "str2", "str3" };[ShowInInspector][OnCollectionChanged("Before", "After")]public HashSet<string> hashset = new HashSet<string>() { "str1", "str2", "str3" };[ShowInInspector][OnCollectionChanged("Before", "After")]public Dictionary<string, string> dictionary = new Dictionary<string, string>() { { "key1", "str1" }, { "key2", "str2" }, { "key3", "str3" } };public void Before(CollectionChangeInfo info, object value){Debug.Log("接收回调之前改变的信息::\r\n" + info + ", 对应的集合实例::\r\n " + value);}public void After(CollectionChangeInfo info, object value){Debug.Log("接收回调后变化的信息:\r\n " + info + "对应的集合实例: \r\n " + value);}
}
更多教程内容详见:革命性Unity 编辑器扩展工具 --- Odin Inspector 系列教程
这篇关于Odin Inspector 系列教程 --- On Collection Changed Attribute的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!