Version: 2023.1
LanguageEnglish
  • C#

SerializedProperty.depth

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

public int depth;

Description

Nesting depth of the property. (Read Only)

See Also: propertyPath.

using System;
using System.Text;
using UnityEngine;
using UnityEditor;

public class SerializePropertyDepthExample : ScriptableObject { // Declare fields to demonstrate data at different depths public int m_depth0;

[Serializable] public struct Nested { public int m_depth1;

[Serializable] public struct NestedInNested { public int m_depth2; public Vector2 m_vectorDepth2; // Contains x,y at depth 3 }; public NestedInNested m_Nested1; }; public Nested m_Nested0; public bool m_boolDepth0;

[MenuItem("Example/SerializedProperty depth Example")] static void DepthExample() { var scriptableObject = ScriptableObject.CreateInstance<SerializePropertyDepthExample>();

using (var serializedObject = new SerializedObject(scriptableObject)) { var report = new StringBuilder();

var iterator = serializedObject.FindProperty("m_depth0");

const bool visitChildren = true; do { report.AppendLine($"Found {iterator.propertyPath} (depth {iterator.depth})"); } while (iterator.Next(visitChildren));

//Output: //Found m_depth0 (depth 0) //Found m_Nested0 (depth 0) //Found m_Nested0.m_depth1 (depth 1) //Found m_Nested0.m_Nested1 (depth 1) //Found m_Nested0.m_Nested1.m_depth2 (depth 2) //Found m_Nested0.m_Nested1.m_vectorDepth2 (depth 2) //Found m_Nested0.m_Nested1.m_vectorDepth2.x (depth 3) //Found m_Nested0.m_Nested1.m_vectorDepth2.y (depth 3) //Found m_boolDepth0 (depth 0) Debug.Log(report.ToString()); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961