39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using UnityEditor;
|
|
|
|
namespace KitsuneCafe.Extension
|
|
{
|
|
public static class EditorExtension
|
|
{
|
|
public static bool TryGetValue<T>(this SerializedProperty property, out T value)
|
|
{
|
|
var target = property.serializedObject.targetObject;
|
|
var type = target.GetType();
|
|
var field = type.GetField(property.propertyPath, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
|
|
|
if (field != null)
|
|
{
|
|
value = (T)field.GetValue(target);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
value = default;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<SerializedProperty> Enumerate(this SerializedObject serializedObject, bool recurse = false)
|
|
{
|
|
var iter = serializedObject.GetIterator();
|
|
iter.NextVisible(true);
|
|
|
|
do
|
|
{
|
|
yield return iter;
|
|
}
|
|
while (iter.NextVisible(recurse));
|
|
}
|
|
}
|
|
}
|