首页 > 其他分享 >SerializedObject遍历

SerializedObject遍历

时间:2022-12-30 21:44:59浏览次数:59  
标签:遍历 itr depth so SerializedObject true public

# 数据类

[Serializable]
public class Test
{
    public float f;
    public Vector2 v2;
}

[CreateAssetMenu]
public class TestAsset : ScriptableObject
{
    [HideInInspector]
    [SerializeField]
    public int a;
    public Vector3 v3;
    public Test test;
}

 

1-1) NextVisible, enterChildren=false的情况

public class NewBehaviourScript : MonoBehaviour
{
    public TestAsset testAsset;

    void Start()
    {
        SerializedObject so = new SerializedObject(this.testAsset);
        var itr = so.GetIterator();
        itr.NextVisible(true); //第一次必须用true
        do
        {
            Debug.Log($"Property: {itr.propertyPath}, {itr.name}, depth:{itr.depth}, type:{itr.propertyType}, {itr.isExpanded}");
        }
        while (itr.NextVisible(false));
    }
}

运行结果:[HideInInspector]的不会显示

 

1-2) NextVisible, enterChildren=true的情况

public class NewBehaviourScript : MonoBehaviour
{
    public TestAsset testAsset;

    void Start()
    {
        SerializedObject so = new SerializedObject(this.testAsset);
        var itr = so.GetIterator();
        itr.NextVisible(true); //第一次必须用true
        do
        {
            Debug.Log($"Property: {itr.propertyPath}, {itr.name}, depth:{itr.depth}, type:{itr.propertyType}, {itr.isExpanded}");
        }
        while (itr.NextVisible(true));
    }
}

运行结果:遇到struct或class会遍历其成员

 

 2-1) Next, enterChildren=false

public class NewBehaviourScript : MonoBehaviour
{
    public TestAsset testAsset;

    void Start()
    {
        SerializedObject so = new SerializedObject(this.testAsset);
        var itr = so.GetIterator();
        itr.Next(true); //第一次必须用true
        do
        {
            Debug.Log($"Property: {itr.propertyPath}, {itr.name}, depth:{itr.depth}, type:{itr.propertyType}, {itr.isExpanded}");
        }
        while (itr.Next(false));
    }
}

运行结果:会把所有序列化成员显示出来

 

2-2) Next, enterChildren=true

public class NewBehaviourScript : MonoBehaviour
{
    public TestAsset testAsset;

    void Start()
    {
        SerializedObject so = new SerializedObject(this.testAsset);
        var itr = so.GetIterator();
        itr.Next(true); //第一次必须用true
        do
        {
            Debug.Log($"Property: {itr.propertyPath}, {itr.name}, depth:{itr.depth}, type:{itr.propertyType}, {itr.isExpanded}");
        }
        while (itr.Next(true));
    }
}

运行结果(太多了,没全部显示)

 

参考

Unity插件开发:SerializedObject/SerializedProperty——查找引用的资源 - CodeGize - 博客园 (cnblogs.com)

Unity编辑器扩展——SerializedObject_Hello Bug.的博客-CSDN博客_unity serializedobject

Unity Inspector用脚本修改不触发保存~~2018.3_刘培玉--大王的博客-CSDN博客_unity脚本修改无法保存

标签:遍历,itr,depth,so,SerializedObject,true,public
From: https://www.cnblogs.com/sailJs/p/17009613.html

相关文章

  • 3任务的创建-列表项的删除&遍历
     1、列表项的删除:从列表中删除指定的列表项,通过uxListRemove()函数来完成pxItemToRemove:要删除的列表项uxListRemove:剩余列表项的数目步骤:获取列表项所在的列表地址将......
  • 迭代(遍历数组)forEach
    1.forEach用法vararr=[13,2,2,5] varsum=0 //forEach用法:Array.forEach(function(数组当前项的值,数组当前项的索引值,数组本身){}) arr.forEach(function(valu......
  • java list集合存储学生对象3种遍历方式
        ......
  • Opnecv_遍历Mat
    opencv图像数据是BGR的顺序,其它的通常为RGB的顺序。Theefficientway Mat&ScanImageAndReduceC(Mat&I,constuchar*consttable){//acceptonlychartypematri......
  • C++中vector的遍历方法
    假设有这样的一个vector:(注意,这种列表初始化的方法是c++11中新增语法)vector<int>valList={0,1,2,3,4,5,6,7,8,9};需要输出这个vector中的每个元素,测试原......
  • Java 遍历 Map 的 5 种方式
    Java中遍历Map有多种方法,从最早的迭代器Iterator,到JDK5开始支持的增强型for循环——即foreach,再到JDK8的Lambda表达式,让我们一起来看下具体的用......
  • java List集合存储学生对象并遍历
        ......
  • java Collection集合遍历
              ......
  • 层序遍历
    二叉树的层次遍历从左到右访问所有节点逐层地,从左到右访问所有节点,返回其层次遍历结果:[[3],[9,20],[15,7]]实现思路:创建一个数组存放结果,一个队列存放......
  • mysql 循环遍历结果集,来逐条更新
    SELECTUSER_IDFROMua;会返回USER_ID的列表  通过循环来逐条更新符合USER_ID的记录#delimiter$$告诉解释器使用$$结尾delimiter$$DROPPROCEDUREIFEXIST......