编辑器接收密钥有多种方法。

自定义菜单栏功能:1 using UnityEngine2 using UnityEditor3 public static class my menu commands { 4[menuitem(' my commands/first command _ p ')]5 static void first commands

从GUI刷新接收OnSceneGUI:1 using UnityEngine;2 using UnityEditor3[customeditor(type of(myspecialmonobehaviour))4 public class my customeditor : editor { 5 void onscene GUI 7 I10 } 11 I==e . type keycode . right control==e . keycode)12 { 13 move multi=false;14} 15} 16 }onSceneGUIDelegate注册事件:1 using UnityEditor2 using UnityEngine3 4[initialize onload]5 public static class editorhotkeystracker 6 { 7 static editorhotkeystracker 8 { 9 scene view . onscent 12 ii=null e.keyCode!=keycode . none)13 debug . log(' key pressed in editor : ' e . keycode);14 };15} 16}有关详细信息,请参阅:

方法2和3类似于Update函数,按下键时可以执行多次,不能同时接收多个键。通常,全局快捷键需要同时组合ctrl/shift/alt或其他键,以避免与普通键发生冲突。

UGUI在想要创建一个Image或者Text时不得不从菜单栏中级级点击多次才行(若是创建空物体再添加组件的方式只会更麻烦),而且创建的控件还是位于最外层层级中而不是直接成为我当前选中的物体的子物体,每次都得手动拖到父物体之下。

NGUI则大部分的控件创建都有对应的快捷键,且直接将新生成的物体放置到当前选中的控件之下,十分高效快捷。

现通过前面介绍的方式一为UGUI的控件创建添加快捷键,在创建控件的时你还可以同时进行一些默认初始设置,如改变Text的字体为常用字体,设置其对齐方式颜色等等:

1 using UnityEngine; 2 using UnityEditor; 3 using Uni; 4 5 //同时支持在选中物体上右键菜单创建和直接快捷键创建 6 public class UGUIHotKey 7 { 8 private static GameObject CheckSelection (MenuCommand menuCommand) 9 { 10 GameObject selectedObj = menuCommand.context as GameObject; 11 //若当前不是右键点击物体的操作则看当前选中的物体的情况 12 if (selectedObj == null) 13 selectedObj = Selec; 14 //当前没有选中物体或者选中的物体不在Canvas之下则返回空,按键不响应。(当然也可以不要求存在Canvas,没有时则先创建一个新的Canvas) 15 if (selectedObj == null || selectedObj != null && ;Canvas> == null) 16 return null; 17 return selectedObj; 18 } 19 20 [MenuItem ("GameObject/UGUI/Image #&i", false, 6)] 21 static void CreateImage (MenuCommand menuCommand) 22 { 23 GameObject selectedObj = CheckSelection (menuCommand); 24 if (selectedObj == null) 25 return; 26 GameObject go = new GameObject ("Image"); 27 GameObjec (go, selectedObj); 28 Undo.RegisterCreatedObjectUndo (go, "Create " + go.name); 29 Selec = go; 30 go.AddComponent<Image> ; 31 } 32 33 [MenuItem ("GameObject/UGUI/Text #&t", false, 6)] 34 static void CreateText (MenuCommand menuCommand) 35 { 36 GameObject selectedObj = CheckSelection (menuCommand); 37 if (selectedObj == null) 38 return; 39 GameObject go = new GameObject ("Text"); 40 GameObjec (go, selectedObj); 41 Undo.RegisterCreatedObjectUndo (go, "Create " + go.name); 42 Selec = go; 43 44 Text t = go.AddComponent<Text> ; 45 Font font = A ("Assets/ArtSources/Fon;, typeof (Font)) as Font; 46 t.font = font; 47 t.fontSize = 24; 48 t.alignment = Tex; 49 t.color = Color.white; 50 t.text = "New Text"; 51 t.rec = new Vector2 (150f, 30f); 52 } 53 }

1.《Unity添加自定义快捷键--UGUI快捷键》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《Unity添加自定义快捷键--UGUI快捷键》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/gl/2957220.html