Unity3D編輯器菠菜出售平臺原始碼擴充套件——EditorWindow互動響應事件
Unity的菠菜出售平臺原始碼 dsluntan.com Q:3393756370 VX:17061863513編輯器介面中由這麼一些事件: EventType
MouseDown //滑鼠按下
MouseUp //滑鼠擡起
MouseDrag//滑鼠拖動
KeyDown//按鍵按下
KeyUp //按鍵擡起
ScrollWheel//中輪滾動
Repaint //每一幀重新渲染會發
Layout //佈局更新
DragUpdated //拖拽的資源進入介面
DragPerform //拖拽的資源放到了某個區域裡
Ignore //操作被忽略
Used//操作已經被使用過了
ValidateCommand //有某種操作被觸發(例如複製和貼上)
ExecuteCommand//有某種操作被執行(例如複製和貼上)
DragExited //鬆開拖拽的資源
ContextClick //右鍵點選
private void OnGUI()
{
if (Event.current.type == EventType.MouseDown)
{
Debug.LogError(EventType.MouseDown);//滑鼠按下
}
else if (Event.current.type == EventType.MouseUp)
{
Debug.LogError(EventType.MouseUp);//滑鼠擡起
}
else if (Event.current.type == EventType.MouseMove)
{
Debug.LogError(EventType.MouseMove);
}
else if (Event.current.type == EventType.MouseDrag)
{
Debug.LogError(EventType.MouseDrag);//滑鼠拖動
}
else if (Event.current.type == EventType.KeyDown)
{
Debug.LogError(EventType.KeyDown);//按鍵按下
}
else if (Event.current.type == EventType.KeyUp)
{
Debug.LogError(EventType.KeyUp);//按鍵擡起
}
else if (Event.current.type == EventType.ScrollWheel)
{
Debug.LogError(EventType.ScrollWheel);//中輪滾動
}
else if (Event.current.type == EventType.Repaint)
{
Debug.LogError(EventType.Repaint);//每一幀重新渲染會發
}
else if (Event.current.type == EventType.Layout)
{
Debug.LogError(EventType.Layout);
}
else if (Event.current.type == EventType.DragUpdated)
{
Debug.LogError(EventType.DragUpdated);//拖拽的資源進入介面
}
else if (Event.current.type == EventType.DragPerform)
{
Debug.LogError(EventType.DragPerform);//拖拽的資源放到了某個區域裡
}
else if (Event.current.type == EventType.Ignore)
{
Debug.LogError(EventType.Ignore);//操作被忽略
}
else if (Event.current.type == EventType.Used)
{
Debug.LogError(EventType.Used);//操作已經被使用過了
}
else if (Event.current.type == EventType.ValidateCommand)
{
Debug.LogError(EventType.ValidateCommand);//有某種操作被觸發(例如複製和貼上)
}
else if (Event.current.type == EventType.ExecuteCommand)
{
Debug.LogError(EventType.ExecuteCommand);//有某種操作被執行(例如複製和貼上)
}
else if (Event.current.type == EventType.DragExited)
{
Debug.LogError(EventType.DragExited);//鬆開拖拽的資源
}
else if (Event.current.type == EventType.ContextClick)
{
Debug.LogError(EventType.ContextClick);//右鍵點選
}
else if (Event.current.type == EventType.MouseEnterWindow)
{
Debug.LogError(EventType.MouseEnterWindow);
}
else if (Event.current.type == EventType.MouseLeaveWindow)
{
Debug.LogError(EventType.MouseLeaveWindow);
}
}
具體使用:
右鍵顯示選單:
if (Event.current.type == EventType.ContextClick)
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("1"), false, null, null);
menu.AddSeparator("");
menu.AddItem(new GUIContent("2"), false, null, null);
menu.ShowAsContext();
//設定該事件被使用
Event.current.Use();
}
有三個事件比較特殊,需要在OnGUI的方法的時候設定一個引數為true才能接收到
MouseEnterWindow //滑鼠進入窗體
MouseLeaveWindow //滑鼠離開窗體
MouseMove //滑鼠移動
private void OnGUI()
{
wantsMouseMove = true;
wantsMouseEnterLeaveWindow = true;
}
---------------------
作者:海王星很危險
來源:CSDN
原文:https://blog.csdn.net/qq_28474981/article/details/83037411
版權宣告:本文為博主原創文章,轉載請附上博文連結!