拖拽生成路徑

using UnityEngine;
using System.Collections;
using UnityEditor;
public class TestDrag : EditorWindow
{
    private string path;

    Rect rect;

    [MenuItem("Window/TestDrag")]
    private static void Init()
    {
        EditorWindow.GetWindow(typeof(TestDrag));
    }

    void OnGUI()
    {
        EditorGUILayout.LabelField("路徑");
        rect = EditorGUILayout.GetControlRect(GUILayout.Width(400));

        path = EditorGUI.TextField(rect, path);

        if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragExited) && rect.Contains(Event.current.mousePosition))
        {
            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
            if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
            {
                path = DragAndDrop.paths[0];
                path = path.Split('.')[0];
                path = path.Replace("Assets/Resource/", "");
                path = path.Replace("/", "_");
            }
        }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章