以下の内容はhttps://baba-s.hatenablog.com/entry/2018/01/18/133200より取得しました。


【Unity】SerializedProperty の型名を取得する関数

ソースコード

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

参考サイト様




以上の内容はhttps://baba-s.hatenablog.com/entry/2018/01/18/133200より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14