ソースコード
using System.Text.RegularExpressions;
using UnityEditor;
public static class MyEditorUtils
{
public static string GetPropertyType( SerializedProperty property )
{
var type = property.type;
var match = Regex.Match( type, @"PPtr<\$(.*?)>" );
return match.Success ? match.Groups[ 1 ].Value : type;
}
}
使い方
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer( typeof( Example ) )]
public sealed class ExampleDrawer : PropertyDrawer
{
public override void OnGUI
(
Rect position,
SerializedProperty property,
GUIContent label
)
{
var obj = property.serializedObject;
var go = obj.targetObject as Component;
var type = MyEditorUtils.GetPropertyType( property );
var com = go.gameObject.GetComponent( type );
}
}
参考サイト様