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

news2024/9/29 3:35:37

推荐阅读

  • 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和坑,让后来人可以有些参考。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1073431.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

十七、C语言内存函数

1 memcpy函数的使用和模拟实现 //memcpy函数的声明 void* memcpy(void* destination, const void* source, size_t num);memcpy函数可以给内存进行拷贝&#xff0c;由于不知道要拷贝的内存中存放的是哪一种类型的数据&#xff0c;所以memcpy函数的返回类型设置成了void*。 me…

【2023全网最全最火】Selenium WebDriver教程(建议收藏)

在本教程中&#xff0c;我将向您介绍 Selenium Webdriver&#xff0c;它是当今市场上使用最广泛的自动化测试框架。它是开源的&#xff0c;可与所有著名的编程语言&#xff08;如Java、Python、C&#xff03;、Ruby、Perl等&#xff09;一起使用&#xff0c;以实现浏览器活动的…

如何使用jest

最近在研究单元测试&#xff0c;虽说前端如果不是大且的项目不必要加&#xff0c;但至少得会&#xff0c;因此花了些时间研究&#xff0c;以下是我总结jest的使用。 jest是什么&#xff1f; Jest是 Facebook 的一套开源的 JavaScript 测试框架&#xff0c; 它自动集成了断言、…

bert入门

bert是什么 BERT&#xff08;Bidirectional Encoder Representations from Transformers&#xff09;是一种自然语言处理&#xff08;NLP&#xff09;中的预训练模型&#xff0c;它是基于Transformer架构的一种深度学习模型。BERT的主要目标是在大规模文本语料库上进行预训练&a…

自动求导,计算图示意图及pytorch实现

pytorch实现 x1 torch.tensor(3.0, requires_gradTrue) y1 torch.tensor(2.0, requires_gradTrue) a x1 ** 2 b 3 * a c b * y1 c.backward() print(x1.grad) print(y1.grad) print(x1.grad 6 * x1 * y1) print(y1.grad 3 * (x1 ** 2))输出为&#xff1a; tensor(36.) …

uniapp-vue3-弹出选择组件wo-pop-selector

wo-pop-selector弹出选择组件采用uniapp-vue3实现, 支持H5、微信小程序&#xff08;其他小程序未测试过&#xff0c;可自行尝试&#xff09; 可到插件市场下载尝试&#xff1a; https://ext.dcloud.net.cn/plugin?id14879 使用示例 <template><view><view c…

GBU808-ASEMI小功率开关电源GBU808

编辑&#xff1a;ll GBU808-ASEMI小功率开关电源GBU808 型号&#xff1a;GBU808 品牌&#xff1a;ASEMI 芯片个数&#xff1a;4 封装&#xff1a;GBU-4 恢复时间&#xff1a;&#xff1e;50ns 工作温度&#xff1a;-55C~150C 浪涌电流&#xff1a;200A 正向电流&#…

微信小程序报错request:fail -2:net::ERR_FAILED(生成中间证书)

微信小程序报错request:fail -2:net::ERR_FAILED-生成中间证书 前言一、检查网站ssl证书二、生成证书方法1.获取中间证书手动合并1.进入网站&#xff1a;[https://www.myssl.cn/tools/downloadchain.html](https://www.myssl.cn/tools/downloadchain.html)2.点击下一步3.手动合…

【Vue面试题十四】、说说你对vue的mixin的理解,有什么应用场景?

文章底部有个人公众号&#xff1a;热爱技术的小郑。主要分享开发知识、学习资料、毕业设计指导等。有兴趣的可以关注一下。为何分享&#xff1f; 踩过的坑没必要让别人在再踩&#xff0c;自己复盘也能加深记忆。利己利人、所谓双赢。 面试官&#xff1a;说说你对vue的mixin的理…

abap代码优化和性能调优工具

select/end select与loop类似是循环&#xff08;一个是对数据库表&#xff0c;一个是对内表&#xff09; select *效率低于select 字段1 字段2... select 主键1 主键2 主键3 非主键4效率高于select 主键1 主键2 非主键4. into table 内表效率高于into corresponding fields …

Linux动态链接库.so文件

一、动态库和静态库的区别 库是一个二进制文件&#xff0c;包含的代码可以被程序调用&#xff0c;如标准库、线程库。Windows 和 Linux下的库文件格式不兼容。 Windows环境&#xff1a;静态库是 .lib 文件&#xff0c;共享库是 .dll 文件 Linux环境&#xff1a;静态库是 .a 文…

IC工程师职场必备《经典Verilog100多个代码案例》(附下载)

对于IC行业的人员而言&#xff0c;Verilog是最基础的入门&#xff0c;用于数字电路的系统设计&#xff0c;很多的岗位都会用到&#xff0c;可对算法级、门级、开关级等多种抽象设计层次进行建模。 Verilog由于其简单的语法&#xff0c;和C语言的相似性&#xff0c;目前被各大公…

uni-app:js时间与时间戳之间的转换

运行结果 代码 <template><view></view> </template><script>export default {data() {return {}},onLoad() {//时间转换为时间戳&#xff08;十位时间戳即秒级时间戳&#xff09;const time 2023-10-01 12:34:56; // 时间格式为年-月-日 时:分…

BlowFish加解密原理与代码实现

BlowFish加解密原理与代码实现 一丶简介 ​ BlowFish 是一个对称加密的加密算法。由Bruce Schneier&#xff0c;1993年设计的。是一个免费自由使用的加密算法。 了解的必要知识 BlowFish是一个对称区块加密算法。每次加密数据为 64位 &#xff08;2个int)类型数据大小。八个…

Maven 引入外部依赖

如果我们需要引入第三方库文件到项目&#xff0c;该怎么操作呢&#xff1f; pom.xml 的 dependencies 列表列出了我们的项目需要构建的所有外部依赖项。 要添加依赖项&#xff0c;我们一般是先在 src 文件夹下添加 lib 文件夹&#xff0c;然后将你工程需要的 jar 文件复制到 …

mac(M1)卸载miniconda3

参考https://stackoverflow.com/questions/29596350/how-to-uninstall-mini-conda-python step1 因为我目前只有一个base环境&#xff0c;所以直接在这个环境中安装 anaconda-clean即可 conda install anaconda-clean然后继续输入 anaconda-clean如果不加–yes&#xff0c;那…

精品Python考务监考管理系统

《[含文档PPT源码等]精品Python考务管理系统的设计与实现》该项目含有源码、文档、PPT、配套开发软件、软件安装教程、项目发布教程等&#xff01; 软件开发环境及开发工具&#xff1a; 开发语言&#xff1a;python 使用框架&#xff1a;Django 前端技术&#xff1a;JavaSc…

SECS/GEM封装库RapidSecs开发手记HMSM

四. SECS/GEM封装库RapidSecs开发手记-基础库开发-1 https://blog.csdn.net/jxb_memory/article/details/105739410 secsgem https://www.cnpython.com/pypi/secsgem

95740-26-4|用于体内DNA合成的探针F-ara-EdU

产品简介&#xff1a;(2S)-2-Deoxy-2-fluoro-5-ethynyluridine&#xff0c;一种用于体内DNA合成的探针&#xff0c;其毒性比EdU和BrdU都小。当需要延长细胞存活时间和不受干扰的细胞周期进展时&#xff0c;非常适合进行代谢DNA标记。 CAS号&#xff1a;95740-26-4 分子式&…

2023腾讯云双11优惠活动服务器价格预测

2023腾讯云服务器双十一有活动吗&#xff1f;有的&#xff0c;双11轻量应用服务器和云服务器CVM均有活动&#xff0c;只是现在还未开启&#xff0c;一般为11月1日开始&#xff0c;活动时间持续1个月时间&#xff0c;腾讯云百科txybk.com预测一下2023年腾讯云服务器双十一优惠活…