以下の内容はhttps://baba-s.hatenablog.com/entry/2020/05/08/210200より取得しました。


【Unity】アセットを Inspector にドラッグ&ドロップできるようにするエディタ拡張の例

ソースコード

/// <summary>
/// 指定された矩形にドラッグ & ドロップされたアセットのパスを返します
/// </summary>
public bool GetDragAndDropAssetPath( Rect rect, out string assetPath )
{
    var current   = Event.current;
    var controlId = GUIUtility.GetControlID( FocusType.Passive );

    assetPath = string.Empty;

    switch ( current.type )
    {
        case EventType.DragUpdated:
        case EventType.DragPerform:

            if ( !rect.Contains( current.mousePosition ) ) break;

            DragAndDrop.visualMode      = DragAndDropVisualMode.Copy;
            DragAndDrop.activeControlID = controlId;

            if ( current.type == EventType.DragPerform )
            {
                DragAndDrop.AcceptDrag();

                foreach ( var draggedObject in DragAndDrop.objectReferences )
                {
                    assetPath = AssetDatabase.GetAssetPath( draggedObject );
                }

                DragAndDrop.activeControlID = 0;
            }

            current.Use();
            break;
    }

    return !string.IsNullOrWhiteSpace( assetPath );
}

使用例

if ( GetDragAndDropAssetPath( pathRect, out var assetPath ) )
{
    pathProperty.stringValue = assetPath;
}



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

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