SerializedProperty.GetEnumerator

Unity · Версия 2020.3 LTS · Scripting · SerializedProperty

SerializedProperty.GetEnumerator

Объявление

public IEnumerator GetEnumerator();

Описание

Получает итератор для перечисления видимых дочерних свойств текущего свойства. Если свойство является массивом, оно будет перечислять элементы массива.

Смотрите так же: NextVisible, GetEndProperty, GetArrayElementAtIndex

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();
        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);
        }
    }
}

Обновлено 17 ноября 2026 г.