Version: 2023.1
言語: 日本語
public int depth ;

説明

プロパティーのネストの深さ (読み取り専用)

関連項目: 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