Version: 2022.3
LanguageEnglish
  • C#

SerializedProperty.GetEnumerator

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public IEnumerator GetEnumerator();

Description

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