VR4Medical/ICI/Library/PackageCache/com.unity.xr.interaction.toolkit@42ef3600567b/Editor/Utilities/XRInteractionEditorUtility.cs
2025-07-29 13:45:50 +03:00

40 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace UnityEditor.XR.Interaction.Toolkit.Utilities
{
/// <summary>
/// Utility class for Inspector <see cref="Editor"/> classes in the XR Interaction Toolkit.
/// </summary>
public static class XRInteractionEditorUtility
{
/// <summary>
/// Returns a list containing the <see cref="SerializeField"/> names of all <see cref="SerializedProperty"/> fields
/// defined in the Editor (including derived types).
/// </summary>
/// <param name="editor">The <see cref="Editor"/> instance to reflect.</param>
/// <returns>Returns a list of strings with property names.</returns>
/// <seealso cref="Editor.DrawPropertiesExcluding"/>
public static List<string> GetDerivedSerializedPropertyNames(Editor editor)
{
if (editor == null)
throw new ArgumentNullException(nameof(editor));
var fields = editor.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
var propertyNames = new List<string> { "m_Script" };
foreach (var field in fields)
{
var value = field.GetValue(editor);
if (value is SerializedProperty serializedProperty)
{
propertyNames.Add(serializedProperty.name);
}
}
return propertyNames;
}
}
}