canto/Assets/Scripts/Extension/Editor.cs

26 lines
728 B
C#

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;
}
}
}
}