エディター拡張で使用できるマウスカーソルと、その使用例について。
(Unity 2019.4.17f1)
マウスカーソル一覧表
上記リンクは Unity の公式リファレンスですが変数の解説に誤りがあるため、正しい組み合わせを以下の表にまとめました。
カーソル | MouseCursor | Enum |
---|---|---|
Arrow | 0 | |
ArrowMinus | 12 | |
ArrowPlus | 11 | |
( ) | CustomCursor | 17 |
FPS | 16 | |
Link | 4 | |
MoveArrow | 8 | |
Orbit | 14 | |
Pan | 13 | |
ResizeHorizontal | 3 | |
ResizeUpLeft | 7 | |
ResizeUpRight | 6 | |
ResizeVertical | 2 | |
ScaleArrow | 10 | |
RotateArrow | 9 | |
SlideArrow | 5 | |
SplitResizeLeftRight | 19 | |
SplitResizeUpDown | 18 | |
Text | 1 | |
Zoom | 15 |
使用例
EditorGUIUtility
クラスのAddCursorRect
メソッドで、前述のMouseCursor
を指定します。
上記リンク内のコードは、コピーしてそのまま使用できます。
// Create a small window that has a color box in it. // Hovering over it causes a Zoom mouse cursor to appear. (The window is not // zoomed however.) using UnityEngine; using UnityEditor; public class AddCursorRectExample : EditorWindow { [MenuItem("Examples/AddCursorRect Example")] static void addCursorRectExample() { AddCursorRectExample window = EditorWindow.GetWindowWithRect<AddCursorRectExample>(new Rect(0, 0, 180, 80)); window.Show(); } void OnGUI() { EditorGUI.DrawRect(new Rect(10, 10, 160, 60), new Color(0.5f, 0.5f, 0.85f)); EditorGUI.DrawRect(new Rect(20, 20, 140, 40), new Color(0.9f, 0.9f, 0.9f)); EditorGUIUtility.AddCursorRect(new Rect(20, 20, 140, 40), MouseCursor.Zoom); } }
Unity Editor のメニューバーで "Example" → "AddCursorRectExample" を選ぶと、新たなウインドウが開きます。
以上、エディター拡張のマウスカーソル一覧と使用例についての記事でした。