using UnityEditor;
using UnityEngine;
public class StringEncrypter : EditorWindow
{
[MenuItem("MyPlugins/open window", false)]
public static void open()
{
StringEncrypter _stringEncrypter = GetWindow<StringEncrypter>(true, "window");
}
private string[] filePaths = null;
private string tip;
private void OnGUI()
{
if (mouseOverWindow == this)
{
//鼠标位于当前窗口
if (Event.current.type == EventType.DragUpdated)
{
//拖入窗口未松开鼠标
DragAndDrop.visualMode = DragAndDropVisualMode.Generic; //改变鼠标外观
}
else if (Event.current.type == EventType.DragExited)
{
//拖入窗口并松开鼠标
Focus(); //获取焦点,使unity置顶(在其他窗口的前面)
//Rect rect=EditorGUILayout.GetControlRect();
//rect.Contains(Event.current.mousePosition);//可以使用鼠标位置判断进入指定区域
if (DragAndDrop.paths != null)
{
filePaths = DragAndDrop.paths;
Event.current.Use();
}
}
}
//File.GetAttributes(path).CompareTo(FileAttributes.Directory) != 0
if (!string.IsNullOrEmpty(tip))
{
GUIStyle style2 = new GUIStyle();
style2.fontSize = 20;
style2.alignment = TextAnchor.MiddleCenter;
GUILayout.Label(tip, style2);
}
}
}
unity 把文件拖入自定义EditorWindow
最新推荐文章于 2024-08-27 22:25:44 发布