【Unity3D编辑器开发】Unity3D中制作一个可以随时查看键盘对应KeyCode值面板,方便开发

本文主要是介绍【Unity3D编辑器开发】Unity3D中制作一个可以随时查看键盘对应KeyCode值面板,方便开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

推荐阅读

  • CSDN主页
  • GitHub开源地址
  • Unity3D插件分享
  • 简书地址
  • 我的个人博客

大家好,我是佛系工程师☆恬静的小魔龙☆,不定时更新Unity开发技巧,觉得有用记得一键三连哦。

一、前言

在开发中,会遇到要使用监控键盘输入的KeyCode值来执行代码的情况。

比如说:

using System;
using UnityEditor;
using UnityEngine;public class Test01 : MonoBehaviour
{void Update(){if (Input.GetKeyDown(KeyCode.W)){Debug.Log("点击了键盘W");}}
}

但是,如果是一些不常用的键位,比如说{}[],这些KeyCode值就比较难查看了,因为API是这样的:
在这里插入图片描述
根本不知道这英文还是数字代表了啥,于是就诞生了,在Unity做一个键盘,然后在键盘的键位下标注每个键位的KeyCode值,方便开发。

先看下效果图:
在这里插入图片描述

小明:键位没有对齐,逼死强迫症啊喂!
张三:不重要!不重要!

二、正文

2-1、构建键盘键值表

让我们新建一个脚本,命名为VirtualKeyboardEditor.cs名字无所谓,主要是要继承与EditorWindow类,并且把脚本放到Editor文件夹内。

编辑代码:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;public class VirtualKeyboardEditor : EditorWindow
{[MenuItem("工具/键盘映射值")]static void OpenWindow(){GetWindow<VirtualKeyboardEditor>().Show();}//用于绘制窗口内容private void OnGUI(){}
}

然后,我们需要写一个自定义类,用来保存键盘值名和KeyCode值,以及长宽。

// 键盘映射value值
public class VirKeyValue
{public float height;public float width;public string name;public string key;public VirKeyValue(string name, string key, float width, float height){this.name = name;this.width = width;this.height = height;this.key = key;}
}

接着构建键值库:

static Dictionary<int, List<VirKeyValue>> dicVirKeys;const int width1 = 50;const int width2 = 80;const int width100 = 100;const int width120 = 120;const int width140 = 138;const int width3 = 300;const int height1 = 30;private void DataInit(){if (dicVirKeys == null){dicVirKeys = new Dictionary<int, List<VirKeyValue>>();List<VirKeyValue> tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Esc","Esc", width1, height1),new VirKeyValue("F1","F1", width1, height1),new VirKeyValue("F2","F2", width1, height1),new VirKeyValue("F3","F3", width1, height1),new VirKeyValue("F4","F4", width1, height1),new VirKeyValue("F5","F5", width1, height1),new VirKeyValue("F6","F6", width1, height1),new VirKeyValue("F7","F7", width1, height1),new VirKeyValue("F8","F8", width1, height1),new VirKeyValue("F9","F9", width1, height1),new VirKeyValue("F10","F10", width1, height1),new VirKeyValue("F11","F11", width1, height1),new VirKeyValue("F12","F12", width1, height1),new VirKeyValue("Print\nScreen","Print", width1, height1),new VirKeyValue("Scroll\nLock", "ScrollLockScroll",width1, height1),new VirKeyValue("Pause","Pause", width1, height1)};dicVirKeys.Add(0, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("~\n`","BackQuote", width1, height1),new VirKeyValue("!\n1","Alpha1", width1, height1),new VirKeyValue("@\n2","Alpha2", width1, height1),new VirKeyValue("#\n3","Alpha3", width1, height1),new VirKeyValue("$\n4","Alpha4", width1, height1),new VirKeyValue("%\n5","Alpha5", width1, height1),new VirKeyValue("^\n6","Alpha6", width1, height1),new VirKeyValue("&\n7","Alpha7", width1, height1),new VirKeyValue("*\n8","Alpha8", width1, height1),new VirKeyValue("(\n9","Alpha9", width1, height1),new VirKeyValue(")\n0","Alpha0", width1, height1),new VirKeyValue("_\n-","Minus", width1, height1),new VirKeyValue("+\n=","Equals", width1, height1),new VirKeyValue("←Backspace","Backspace", width120, height1),new VirKeyValue("Insert","Insert", width1, height1),new VirKeyValue("Home", "Home",width1, height1),new VirKeyValue("Page\nUp", "PageUp",width1, height1),new VirKeyValue("NumLk","Numlock", width1, height1),new VirKeyValue("/","KeypadDivide", width1, height1),new VirKeyValue("*","KeypadMultiply", width1, height1),new VirKeyValue("-","KeypadMinus", width1, height1),};dicVirKeys.Add(1, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Tab","Tab", width100, height1),new VirKeyValue("Q","Q",width1, height1),new VirKeyValue("W","W",width1, height1),new VirKeyValue("E","E",width1, height1),new VirKeyValue("R","R",width1, height1),new VirKeyValue("T","T",width1, height1),new VirKeyValue("Y","Y",width1, height1),new VirKeyValue("U","U",width1, height1),new VirKeyValue("I","I",width1, height1),new VirKeyValue("O","O",width1, height1),new VirKeyValue("P","P",width1, height1),new VirKeyValue("{\n[","LeftBracket", width1, height1),new VirKeyValue("}\n]","RightBracket", width1, height1),new VirKeyValue("|\n\\", "Backslash",70, height1),new VirKeyValue("Delete", "Delete",width1, height1),new VirKeyValue("End", "End",width1, height1),new VirKeyValue("Page\nDown","PageDown", width1, height1),new VirKeyValue("7","Keypad7",width1, height1),new VirKeyValue("8","Keypad8",width1, height1),new VirKeyValue("9","Keypad9",width1, height1),new VirKeyValue("+","KeypadPlus",width1, height1),};dicVirKeys.Add(2, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Caps\nLock","Backspace", width120, height1),new VirKeyValue("A","A", width1, height1),new VirKeyValue("S","S", width1, height1),new VirKeyValue("D","D", width1, height1),new VirKeyValue("F","F", width1, height1),new VirKeyValue("G","G", width1, height1),new VirKeyValue("H","H", width1, height1),new VirKeyValue("J","J", width1, height1),new VirKeyValue("K","K", width1, height1),new VirKeyValue("L","L", width1, height1),new VirKeyValue(":\n;","Semicolon", width1, height1),new VirKeyValue("\"\n'","Quote", width1, height1),new VirKeyValue("Enter","Enter", 104, height1),new VirKeyValue("4","Keypad4",width1, height1),new VirKeyValue("5","Keypad5",width1, height1),new VirKeyValue("6","Keypad6",width1, height1),new VirKeyValue("Enter","KeypadEnter", width1, height1),};dicVirKeys.Add(3, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Shift","LeftShift", width140, height1),new VirKeyValue("Z","Z",width1, height1),new VirKeyValue("X","X",width1, height1),new VirKeyValue("C","C",width1, height1),new VirKeyValue("V","V",width1, height1),new VirKeyValue("B","B",width1, height1),new VirKeyValue("N","N",width1, height1),new VirKeyValue("M","M",width1, height1),new VirKeyValue("<\n,","Comma", width1, height1),new VirKeyValue(">\n.","Period", width1, height1),new VirKeyValue("?\n/","Slash", width1, height1),new VirKeyValue("Shift","RightControl", width140, height1),new VirKeyValue("↑","UpArrow", width1, height1),new VirKeyValue("1","Keypad1", width1, height1),new VirKeyValue("2","Keypad2", width1, height1),new VirKeyValue("3","Keypad3", width1, height1),};dicVirKeys.Add(4, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Ctrl","LeftControl", width2, height1),new VirKeyValue("Win", "LeftWindows",width1, height1),new VirKeyValue("Alt", "LeftAlt",width1, height1),new VirKeyValue("—————Space———","Space", width3, height1),new VirKeyValue("Alt", "RightAlt",width1, height1),new VirKeyValue("Ctrl", "RightControl",width2, height1),new VirKeyValue("←","LeftArrow",width1, height1),new VirKeyValue("↓","DownArrow",width1, height1),new VirKeyValue("→","RightArrow",width1, height1),new VirKeyValue("0","Keypad0",width100, height1),new VirKeyValue(".","KeypadPeriod",width1, height1),};dicVirKeys.Add(5, tempVirKeys);}}

整体代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;// 键盘映射value值
public class VirKeyValue
{public float height;public float width;public string name;public string key;public VirKeyValue(string name, string key, float width, float height){this.name = name;this.width = width;this.height = height;this.key = key;}
}
public class VirtualKeyboardEditor : EditorWindow
{[MenuItem("工具/键盘映射值")]static void OpenWindow(){GetWindow<VirtualKeyboardEditor>().Show();}static Dictionary<int, List<VirKeyValue>> dicVirKeys;const int width1 = 50;const int width2 = 80;const int width100 = 100;const int width120 = 120;const int width140 = 138;const int width3 = 300;const int height1 = 30;private void DataInit(){if (dicVirKeys == null){dicVirKeys = new Dictionary<int, List<VirKeyValue>>();List<VirKeyValue> tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Esc","Esc", width1, height1),new VirKeyValue("F1","F1", width1, height1),new VirKeyValue("F2","F2", width1, height1),new VirKeyValue("F3","F3", width1, height1),new VirKeyValue("F4","F4", width1, height1),new VirKeyValue("F5","F5", width1, height1),new VirKeyValue("F6","F6", width1, height1),new VirKeyValue("F7","F7", width1, height1),new VirKeyValue("F8","F8", width1, height1),new VirKeyValue("F9","F9", width1, height1),new VirKeyValue("F10","F10", width1, height1),new VirKeyValue("F11","F11", width1, height1),new VirKeyValue("F12","F12", width1, height1),new VirKeyValue("Print\nScreen","Print", width1, height1),new VirKeyValue("Scroll\nLock", "ScrollLockScroll",width1, height1),new VirKeyValue("Pause","Pause", width1, height1)};dicVirKeys.Add(0, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("~\n`","BackQuote", width1, height1),new VirKeyValue("!\n1","Alpha1", width1, height1),new VirKeyValue("@\n2","Alpha2", width1, height1),new VirKeyValue("#\n3","Alpha3", width1, height1),new VirKeyValue("$\n4","Alpha4", width1, height1),new VirKeyValue("%\n5","Alpha5", width1, height1),new VirKeyValue("^\n6","Alpha6", width1, height1),new VirKeyValue("&\n7","Alpha7", width1, height1),new VirKeyValue("*\n8","Alpha8", width1, height1),new VirKeyValue("(\n9","Alpha9", width1, height1),new VirKeyValue(")\n0","Alpha0", width1, height1),new VirKeyValue("_\n-","Minus", width1, height1),new VirKeyValue("+\n=","Equals", width1, height1),new VirKeyValue("←Backspace","Backspace", width120, height1),new VirKeyValue("Insert","Insert", width1, height1),new VirKeyValue("Home", "Home",width1, height1),new VirKeyValue("Page\nUp", "PageUp",width1, height1),new VirKeyValue("NumLk","Numlock", width1, height1),new VirKeyValue("/","KeypadDivide", width1, height1),new VirKeyValue("*","KeypadMultiply", width1, height1),new VirKeyValue("-","KeypadMinus", width1, height1),};dicVirKeys.Add(1, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Tab","Tab", width100, height1),new VirKeyValue("Q","Q",width1, height1),new VirKeyValue("W","W",width1, height1),new VirKeyValue("E","E",width1, height1),new VirKeyValue("R","R",width1, height1),new VirKeyValue("T","T",width1, height1),new VirKeyValue("Y","Y",width1, height1),new VirKeyValue("U","U",width1, height1),new VirKeyValue("I","I",width1, height1),new VirKeyValue("O","O",width1, height1),new VirKeyValue("P","P",width1, height1),new VirKeyValue("{\n[","LeftBracket", width1, height1),new VirKeyValue("}\n]","RightBracket", width1, height1),new VirKeyValue("|\n\\", "Backslash",70, height1),new VirKeyValue("Delete", "Delete",width1, height1),new VirKeyValue("End", "End",width1, height1),new VirKeyValue("Page\nDown","PageDown", width1, height1),new VirKeyValue("7","Keypad7",width1, height1),new VirKeyValue("8","Keypad8",width1, height1),new VirKeyValue("9","Keypad9",width1, height1),new VirKeyValue("+","KeypadPlus",width1, height1),};dicVirKeys.Add(2, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Caps\nLock","Backspace", width120, height1),new VirKeyValue("A","A", width1, height1),new VirKeyValue("S","S", width1, height1),new VirKeyValue("D","D", width1, height1),new VirKeyValue("F","F", width1, height1),new VirKeyValue("G","G", width1, height1),new VirKeyValue("H","H", width1, height1),new VirKeyValue("J","J", width1, height1),new VirKeyValue("K","K", width1, height1),new VirKeyValue("L","L", width1, height1),new VirKeyValue(":\n;","Semicolon", width1, height1),new VirKeyValue("\"\n'","Quote", width1, height1),new VirKeyValue("Enter","Enter", 104, height1),new VirKeyValue("4","Keypad4",width1, height1),new VirKeyValue("5","Keypad5",width1, height1),new VirKeyValue("6","Keypad6",width1, height1),new VirKeyValue("Enter","KeypadEnter", width1, height1),};dicVirKeys.Add(3, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Shift","LeftShift", width140, height1),new VirKeyValue("Z","Z",width1, height1),new VirKeyValue("X","X",width1, height1),new VirKeyValue("C","C",width1, height1),new VirKeyValue("V","V",width1, height1),new VirKeyValue("B","B",width1, height1),new VirKeyValue("N","N",width1, height1),new VirKeyValue("M","M",width1, height1),new VirKeyValue("<\n,","Comma", width1, height1),new VirKeyValue(">\n.","Period", width1, height1),new VirKeyValue("?\n/","Slash", width1, height1),new VirKeyValue("Shift","RightControl", width140, height1),new VirKeyValue("↑","UpArrow", width1, height1),new VirKeyValue("1","Keypad1", width1, height1),new VirKeyValue("2","Keypad2", width1, height1),new VirKeyValue("3","Keypad3", width1, height1),};dicVirKeys.Add(4, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Ctrl","LeftControl", width2, height1),new VirKeyValue("Win", "LeftWindows",width1, height1),new VirKeyValue("Alt", "LeftAlt",width1, height1),new VirKeyValue("—————Space———","Space", width3, height1),new VirKeyValue("Alt", "RightAlt",width1, height1),new VirKeyValue("Ctrl", "RightControl",width2, height1),new VirKeyValue("←","LeftArrow",width1, height1),new VirKeyValue("↓","DownArrow",width1, height1),new VirKeyValue("→","RightArrow",width1, height1),new VirKeyValue("0","Keypad0",width100, height1),new VirKeyValue(".","KeypadPeriod",width1, height1),};dicVirKeys.Add(5, tempVirKeys);}}//用于绘制窗口内容private void OnGUI(){}
}

2-2、界面绘制

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;// 键盘映射value值
public class VirKeyValue
{public float height;public float width;public string name;public string key;public VirKeyValue(string name, string key, float width, float height){this.name = name;this.width = width;this.height = height;this.key = key;}
}
public class VirtualKeyboardEditor : EditorWindow
{[MenuItem("工具/键盘映射值")]static void OpenWindow(){GetWindow<VirtualKeyboardEditor>().Show();}static Dictionary<int, List<VirKeyValue>> dicVirKeys;const int width1 = 50;const int width2 = 80;const int width100 = 100;const int width120 = 120;const int width140 = 138;const int width3 = 300;const int height1 = 30;private void DataInit(){if (dicVirKeys == null){dicVirKeys = new Dictionary<int, List<VirKeyValue>>();List<VirKeyValue> tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Esc","Esc", width1, height1),new VirKeyValue("F1","F1", width1, height1),new VirKeyValue("F2","F2", width1, height1),new VirKeyValue("F3","F3", width1, height1),new VirKeyValue("F4","F4", width1, height1),new VirKeyValue("F5","F5", width1, height1),new VirKeyValue("F6","F6", width1, height1),new VirKeyValue("F7","F7", width1, height1),new VirKeyValue("F8","F8", width1, height1),new VirKeyValue("F9","F9", width1, height1),new VirKeyValue("F10","F10", width1, height1),new VirKeyValue("F11","F11", width1, height1),new VirKeyValue("F12","F12", width1, height1),new VirKeyValue("Print\nScreen","Print", width1, height1),new VirKeyValue("Scroll\nLock", "ScrollLockScroll",width1, height1),new VirKeyValue("Pause","Pause", width1, height1)};dicVirKeys.Add(0, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("~\n`","BackQuote", width1, height1),new VirKeyValue("!\n1","Alpha1", width1, height1),new VirKeyValue("@\n2","Alpha2", width1, height1),new VirKeyValue("#\n3","Alpha3", width1, height1),new VirKeyValue("$\n4","Alpha4", width1, height1),new VirKeyValue("%\n5","Alpha5", width1, height1),new VirKeyValue("^\n6","Alpha6", width1, height1),new VirKeyValue("&\n7","Alpha7", width1, height1),new VirKeyValue("*\n8","Alpha8", width1, height1),new VirKeyValue("(\n9","Alpha9", width1, height1),new VirKeyValue(")\n0","Alpha0", width1, height1),new VirKeyValue("_\n-","Minus", width1, height1),new VirKeyValue("+\n=","Equals", width1, height1),new VirKeyValue("←Backspace","Backspace", width120, height1),new VirKeyValue("Insert","Insert", width1, height1),new VirKeyValue("Home", "Home",width1, height1),new VirKeyValue("Page\nUp", "PageUp",width1, height1),new VirKeyValue("NumLk","Numlock", width1, height1),new VirKeyValue("/","KeypadDivide", width1, height1),new VirKeyValue("*","KeypadMultiply", width1, height1),new VirKeyValue("-","KeypadMinus", width1, height1),};dicVirKeys.Add(1, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Tab","Tab", width100, height1),new VirKeyValue("Q","Q",width1, height1),new VirKeyValue("W","W",width1, height1),new VirKeyValue("E","E",width1, height1),new VirKeyValue("R","R",width1, height1),new VirKeyValue("T","T",width1, height1),new VirKeyValue("Y","Y",width1, height1),new VirKeyValue("U","U",width1, height1),new VirKeyValue("I","I",width1, height1),new VirKeyValue("O","O",width1, height1),new VirKeyValue("P","P",width1, height1),new VirKeyValue("{\n[","LeftBracket", width1, height1),new VirKeyValue("}\n]","RightBracket", width1, height1),new VirKeyValue("|\n\\", "Backslash",70, height1),new VirKeyValue("Delete", "Delete",width1, height1),new VirKeyValue("End", "End",width1, height1),new VirKeyValue("Page\nDown","PageDown", width1, height1),new VirKeyValue("7","Keypad7",width1, height1),new VirKeyValue("8","Keypad8",width1, height1),new VirKeyValue("9","Keypad9",width1, height1),new VirKeyValue("+","KeypadPlus",width1, height1),};dicVirKeys.Add(2, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Caps\nLock","Backspace", width120, height1),new VirKeyValue("A","A", width1, height1),new VirKeyValue("S","S", width1, height1),new VirKeyValue("D","D", width1, height1),new VirKeyValue("F","F", width1, height1),new VirKeyValue("G","G", width1, height1),new VirKeyValue("H","H", width1, height1),new VirKeyValue("J","J", width1, height1),new VirKeyValue("K","K", width1, height1),new VirKeyValue("L","L", width1, height1),new VirKeyValue(":\n;","Semicolon", width1, height1),new VirKeyValue("\"\n'","Quote", width1, height1),new VirKeyValue("Enter","Enter", 104, height1),new VirKeyValue("4","Keypad4",width1, height1),new VirKeyValue("5","Keypad5",width1, height1),new VirKeyValue("6","Keypad6",width1, height1),new VirKeyValue("Enter","KeypadEnter", width1, height1),};dicVirKeys.Add(3, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Shift","LeftShift", width140, height1),new VirKeyValue("Z","Z",width1, height1),new VirKeyValue("X","X",width1, height1),new VirKeyValue("C","C",width1, height1),new VirKeyValue("V","V",width1, height1),new VirKeyValue("B","B",width1, height1),new VirKeyValue("N","N",width1, height1),new VirKeyValue("M","M",width1, height1),new VirKeyValue("<\n,","Comma", width1, height1),new VirKeyValue(">\n.","Period", width1, height1),new VirKeyValue("?\n/","Slash", width1, height1),new VirKeyValue("Shift","RightControl", width140, height1),new VirKeyValue("↑","UpArrow", width1, height1),new VirKeyValue("1","Keypad1", width1, height1),new VirKeyValue("2","Keypad2", width1, height1),new VirKeyValue("3","Keypad3", width1, height1),};dicVirKeys.Add(4, tempVirKeys);tempVirKeys = new List<VirKeyValue>{new VirKeyValue("Ctrl","LeftControl", width2, height1),new VirKeyValue("Win", "LeftWindows",width1, height1),new VirKeyValue("Alt", "LeftAlt",width1, height1),new VirKeyValue("—————Space———","Space", width3, height1),new VirKeyValue("Alt", "RightAlt",width1, height1),new VirKeyValue("Ctrl", "RightControl",width2, height1),new VirKeyValue("←","LeftArrow",width1, height1),new VirKeyValue("↓","DownArrow",width1, height1),new VirKeyValue("→","RightArrow",width1, height1),new VirKeyValue("0","Keypad0",width100, height1),new VirKeyValue(".","KeypadPeriod",width1, height1),};dicVirKeys.Add(5, tempVirKeys);}}//用于绘制窗口内容private void OnGUI(){DataInit();GUILayout.Label("Note:在开发中会遇到使用监控键盘输入的情况,但是KeyCode的值往往分不清楚,此工具就是跟键盘一一对应的Key值,不清楚的时候" +"看一眼就行了,当然,也可以点击按钮,点击后可以打印当前KeyCode值。");for (int i = 0; i < dicVirKeys.Count; i++){GUILayout.BeginVertical();OnRow(i);GUILayout.EndVertical();}}void OnRow(int index){GUILayout.BeginHorizontal();for (int i = 0; i < dicVirKeys[index].Count; i++){if (dicVirKeys[index][i].name == "↑"){GUILayout.Space(50);}else if (dicVirKeys[index][i].name == "←"){GUILayout.Space(180);}else if (dicVirKeys[index][i].name == "4"){GUILayout.Space(160);}else if (dicVirKeys[index][i].name == "1"){GUILayout.Space(60);}else if (dicVirKeys[index][i].name == "0"){GUILayout.Space(6);}GUILayout.BeginVertical();if (GUILayout.Button(dicVirKeys[index][i].name, GUILayout.Width(dicVirKeys[index][i].width), GUILayout.Height(dicVirKeys[index][i].height))){Debug.Log("当前按下的键位是 : KeyCode." + dicVirKeys[index][i].key);}GUILayout.Label(dicVirKeys[index][i].key);GUILayout.EndVertical();if (dicVirKeys[index][i].name == "Esc"){GUILayout.Space(52);}else if (dicVirKeys[index][i].name == "F4"){GUILayout.Space(36);}else if (dicVirKeys[index][i].name == "F8"){GUILayout.Space(36);}}GUILayout.EndHorizontal();}
}

然后在Untiy编辑器的Edit栏,选择工具→键盘映射值打开面板:
在这里插入图片描述

三、后记

如果觉得本篇文章有用别忘了点个关注,关注不迷路,持续分享更多Unity干货文章。


你的点赞就是对博主的支持,有问题记得留言:

博主主页有联系方式。

博主还有跟多宝藏文章等待你的发掘哦:

专栏方向简介
Unity3D开发小游戏小游戏开发教程分享一些使用Unity3D引擎开发的小游戏,分享一些制作小游戏的教程。
Unity3D从入门到进阶入门从自学Unity中获取灵感,总结从零开始学习Unity的路线,有C#和Unity的知识。
Unity3D之UGUIUGUIUnity的UI系统UGUI全解析,从UGUI的基础控件开始讲起,然后将UGUI的原理,UGUI的使用全面教学。
Unity3D之读取数据文件读取使用Unity3D读取txt文档、json文档、xml文档、csv文档、Excel文档。
Unity3D之数据集合数据集合数组集合:数组、List、字典、堆栈、链表等数据集合知识分享。
Unity3D之VR/AR(虚拟仿真)开发虚拟仿真总结博主工作常见的虚拟仿真需求进行案例讲解。
Unity3D之插件插件主要分享在Unity开发中用到的一些插件使用方法,插件介绍等
Unity3D之日常开发日常记录主要是博主日常开发中用到的,用到的方法技巧,开发思路,代码分享等
Unity3D之日常BUG日常记录记录在使用Unity3D编辑器开发项目过程中,遇到的BUG和坑,让后来人可以有些参考。

这篇关于【Unity3D编辑器开发】Unity3D中制作一个可以随时查看键盘对应KeyCode值面板,方便开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/174991

相关文章

MybatisGenerator文件生成不出对应文件的问题

《MybatisGenerator文件生成不出对应文件的问题》本文介绍了使用MybatisGenerator生成文件时遇到的问题及解决方法,主要步骤包括检查目标表是否存在、是否能连接到数据库、配置生成... 目录MyBATisGenerator 文件生成不出对应文件先在项目结构里引入“targetProje

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

Python如何使用seleniumwire接管Chrome查看控制台中参数

《Python如何使用seleniumwire接管Chrome查看控制台中参数》文章介绍了如何使用Python的seleniumwire库来接管Chrome浏览器,并通过控制台查看接口参数,本文给大家... 1、cmd打开控制台,启动谷歌并制定端口号,找不到文件的加环境变量chrome.exe --rem

Java中的Opencv简介与开发环境部署方法

《Java中的Opencv简介与开发环境部署方法》OpenCV是一个开源的计算机视觉和图像处理库,提供了丰富的图像处理算法和工具,它支持多种图像处理和计算机视觉算法,可以用于物体识别与跟踪、图像分割与... 目录1.Opencv简介Opencv的应用2.Java使用OpenCV进行图像操作opencv安装j

Debian如何查看系统版本? 7种轻松查看Debian版本信息的实用方法

《Debian如何查看系统版本?7种轻松查看Debian版本信息的实用方法》Debian是一个广泛使用的Linux发行版,用户有时需要查看其版本信息以进行系统管理、故障排除或兼容性检查,在Debia... 作为最受欢迎的 linux 发行版之一,Debian 的版本信息在日常使用和系统维护中起着至关重要的作

基于Qt开发一个简单的OFD阅读器

《基于Qt开发一个简单的OFD阅读器》这篇文章主要为大家详细介绍了如何使用Qt框架开发一个功能强大且性能优异的OFD阅读器,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 目录摘要引言一、OFD文件格式解析二、文档结构解析三、页面渲染四、用户交互五、性能优化六、示例代码七、未来发展方向八、结论摘要

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

在 VSCode 中配置 C++ 开发环境的详细教程

《在VSCode中配置C++开发环境的详细教程》本文详细介绍了如何在VisualStudioCode(VSCode)中配置C++开发环境,包括安装必要的工具、配置编译器、设置调试环境等步骤,通... 目录如何在 VSCode 中配置 C++ 开发环境:详细教程1. 什么是 VSCode?2. 安装 VSCo

使用Python制作一个PDF批量加密工具

《使用Python制作一个PDF批量加密工具》PDF批量加密‌是一种保护PDF文件安全性的方法,通过为多个PDF文件设置相同的密码,防止未经授权的用户访问这些文件,下面我们来看看如何使用Python制... 目录1.简介2.运行效果3.相关源码1.简介一个python写的PDF批量加密工具。PDF批量加密

C#图表开发之Chart详解

《C#图表开发之Chart详解》C#中的Chart控件用于开发图表功能,具有Series和ChartArea两个重要属性,Series属性是SeriesCollection类型,包含多个Series对... 目录OverviChina编程ewSeries类总结OverviewC#中,开发图表功能的控件是Char