Version: 2021.3
public IEnumerator GetEnumerator ();

描述

Retrieves an iterator for enumerating over the visible child properties of the current property. If the property is an array it will enumerate over the array elements.

using UnityEditor;
using UnityEngine;

public class EnumerateExample : ScriptableObject { public Vector3 m_vector3 = new Vector3(1.0f, 2.0f, 3.0f); public int m_anotherField = 2;

[MenuItem("Example/SerializedProperty GetEnumerator Example")] static void Example() { EnumerateExample obj = ScriptableObject.CreateInstance<EnumerateExample>(); SerializedObject serializedObject = new SerializedObject(obj); SerializedProperty property = serializedObject.FindProperty("m_vector3");

// Visit the x, y, z values of the vector, stopping once m_anotherField is reached var enumerator = property.GetEnumerator(); while (enumerator.MoveNext()) { property = enumerator.Current as SerializedProperty; Debug.Log(property.propertyPath + " : " + property.floatValue); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961