Unity实现按键设置功能代码

一、前言

最近在学习unity2D,想做一个横版过关游戏,需要按键设置功能,让用户可以自定义方向键与攻击键等。

自己写了一个,总结如下。

二、界面效果图

在这里插入图片描述
这个是一个csv文件,准备第一列是中文按键说明,第二列是英文,第三列是日文(还没有翻译);第四列是默认按键名称,第五列是默认按键ascII码(如果用户选了恢复默认设置,就会用到);第六列是用户自己设置的按键名称,第七列是用户自己设置的按键ascII码;第八列保留,暂未使用。

在这里插入图片描述
这个是首页,如果选到了这个按钮,就是按键设置页面。

在这里插入图片描述

这个是按键设置页面,实现了按 上下/用户设置的上下移动光标,按回车/ 开始键确定,然后按另一个键进行按键修改。
(图中灰色块就是光标,还没有找图片;最后3行按钮进行了特殊处理)

三、主要部分代码

unity代码比较多,总结下主要用到的3个类。

1.FileManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.SceneManagement;
using System.Text;public class FileManager : MonoSingleTon<FileManager>
{private bool isInit =false;public TextAsset keyConfigCsv;//012列是语言,3是默认名称,4是默认ascii,56是用户设置的//这个要装第二行的数据/*wsadjkliqeuocvjk*///语言,这个不能修改,只能读取public static string[] LanguageWasd = new string[16];private static string[] LanguageWasd0 = new string[16];private static string[] LanguageWasd1 = new string[16];private static string[] LanguageWasd2 = new string[16];//默认的key的str与int,这个不能修改,只能读取public static int[] DefaultWasdNumKeys = new int[16];public static string[] DefaultWasdNumKeysStr = new string[16];//实际用的key的str与intpublic static int[] WasdNumKeys = new int[16];public static string[] WasdNumKeysStr = new string[16];//临时用的key的str与int,因为可能只修改不保存,所以用public static int[] WasdNumKeysTemp = new int[16];public static string[] WasdNumKeysStrTemp = new string[16];// Start is called before the first frame update// 这个方法会在脚本被启用时注册监听事件void OnEnable(){//Debug.Log("进入这个场景playerData");//Debug.Log("执行完毕这个场景playerData");}private void Awake(){if (!isInit){InitKeyConfig();}}void Start(){}// Update is called once per framevoid Update(){}private bool InitKeyConfig(){string path = GetKeyConfigPath();Debug.Log(path);if (File.Exists(path)){//用用户的初始化LoadKeyConfig(File.ReadAllText(path).Split("\n"));Debug.Log("使用用户的初始化");isInit = true;return false;}else{string text = keyConfigCsv.text;//把默认的文件写进本地File.WriteAllText(path, text, Encoding.UTF8);//用默认的初始化LoadKeyConfig(text.Split("\n"));//string[] dataRow = text.Split("\n");//File.WriteAllLines(path, dataRow);Debug.Log("使用默认的初始化");isInit = true;return true;}}//读取到临时变量里public void LoadKeyConfig(string[] dataRow){int language = LanguageManager.GetLanguage();//File.WriteAllLines(path, dataRow);for(int i = 0; i < dataRow.Length; i++){string[] dataCell = dataRow[i].Split(",");if (i >= 16){break;}else{LanguageWasd[i] = dataCell[language];LanguageWasd0[i] = dataCell[0];LanguageWasd1[i] = dataCell[1];LanguageWasd2[i] = dataCell[2];DefaultWasdNumKeysStr[i] = dataCell[3];DefaultWasdNumKeys[i] = int.Parse(dataCell[4]);WasdNumKeysStr[i] = dataCell[5];WasdNumKeysStrTemp[i] = dataCell[5];WasdNumKeys[i] = int.Parse(dataCell[6]);WasdNumKeysTemp[i] = int.Parse(dataCell[6]);}}}private static void SaveKeyConfig(string[] dataRow){//Application.dataPath//这个打包后就不能用了,可能没权限string path = GetKeyConfigPath();if (File.Exists(path)){//删了重新创建File.Delete(path);File.CreateText(path).Close();}else{File.CreateText(path).Close();}//List<string> datas2 = new List<string>();//datas.Add("coins,1");Debug.Log("写入数据");File.WriteAllLines(path, dataRow, Encoding.UTF8);Debug.Log("写入数据完毕");}public void ResetKeyConfig(){string text = keyConfigCsv.text;//用默认的初始化LoadKeyConfig(text.Split("\n"));//并且保存SaveKeyConfig(text.Split("\n"));//SceneManager.LoadScene(0);}public static string GetKeyConfigPath(){return Application.persistentDataPath + "/KeyConfig.csv";}public static void SaveKeyConfig(){string[] newData = new string[16];//保存文件for(int i=0; i<16; i++){newData[i] = LanguageWasd0[i] + "," + LanguageWasd1[i] + "," + LanguageWasd2[i] + ","+ DefaultWasdNumKeysStr[i] + "," + DefaultWasdNumKeys[i] + "," + WasdNumKeysStr[i] + "," + WasdNumKeys[i] + "," + ";";}SaveKeyConfig(newData);Debug.Log("保存键盘信息完毕");}}

这个类负责操作配置文件,要把内置的配置文件保存到本地配置文件中,以及读取配置文件。(要区分读取内置的还是本地的)

2.TitleScreen.cs

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;public class TitleScreen : MonoBehaviour
{TextMeshProUGUI tmpTitleText;bool calledNextScene;bool inputDetected = false;bool isTitle = true;bool isKeySetting = false;bool isLanguageSetting = false;int alphaKeyPressText = 255;bool alphaKeyPressTextShow = true;public AudioClip keyPressClip;public AudioClip keyChangeClip;[SerializeField] Image[] buttons = new Image[5];[SerializeField] Text[] buttonsText = new Text[5];private int buttonsChoosedNum = 0;private enum TitleScreenStates { WaitForInput, NextScene };TitleScreenStates titleScreenState = TitleScreenStates.WaitForInput;#if UNITY_STANDALONEstring insertKeyPressText = "PRESS ANY KEY";
#endif#if UNITY_ANDROID || UNITY_IOSstring insertKeyPressText = "TAP TO START";
#endifstring titleText =
@"<size=18><color=#ffffff{0:X2}>{1}</color></size>";private void Awake(){//tmpTitleText = GameObject.Find("TitleText").GetComponent<TextMeshProUGUI>();}// Start is called before the first frame updatevoid Start(){//tmpTitleText.alignment = TextAlignmentOptions.Center;//tmpTitleText.alignment = TextAlignmentOptions.Midline;//tmpTitleText.fontStyle = FontStyles.UpperCase;titleScreenState = TitleScreenStates.WaitForInput;if (isHaveSavePoint()){initButton(1);}else {initButton(0);}}// Update is called once per framevoid Update(){switch(titleScreenState){case TitleScreenStates.WaitForInput://buttonsText[buttonsChoosedNum].text = String.Format(titleText, alphaKeyPressText, buttonsText[buttonsChoosedNum].text);buttonsText[buttonsChoosedNum].enabled = alphaKeyPressTextShow;if (!inputDetected){ChooseButton();SelectButton();}break;case TitleScreenStates.NextScene:if (!calledNextScene){GameManager.Instance.StartNextScene();calledNextScene = true;}break;}}private IEnumerator FlashTitleText() { for(int i = 0; i < 5; i++){alphaKeyPressTextShow = true;alphaKeyPressText = 0;yield return new WaitForSeconds(0.1f);alphaKeyPressTextShow = false;alphaKeyPressText = 255;yield return new WaitForSeconds(0.1f);}alphaKeyPressTextShow = true;alphaKeyPressText = 0;yield return new WaitForSeconds(0.1f);titleScreenState = TitleScreenStates.NextScene;}private IEnumerator FlashTitleTextAndOpenKeyConfig(){for (int i = 0; i < 5; i++){alphaKeyPressTextShow = true;alphaKeyPressText = 0;yield return new WaitForSeconds(0.1f);alphaKeyPressTextShow = false;alphaKeyPressText = 255;yield return new WaitForSeconds(0.1f);}alphaKeyPressTextShow = true;alphaKeyPressText = 0;yield return new WaitForSeconds(0.1f);//退出的时候,需要改为接受输入KeyConfigScript.Instance.Show(() => { inputDetected = false;Debug.Log("回调方法"); });}private bool isHaveSavePoint() {return false;}private void ChooseButton() {if (  Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[0])  ){if (buttonsChoosedNum > 0){buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum--;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();}else{PlayChangeButton();}}if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[1]) ){if (buttonsChoosedNum < buttons.Length - 1){buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum++;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();}else{PlayChangeButton();}}}private void SelectButton() { if( Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[13])  ){if (buttonsChoosedNum == 0){inputDetected = true;StartCoroutine(FlashTitleText());SoundManager.Instance.Play(keyPressClip);} else if (buttonsChoosedNum == 1) {inputDetected = true;SoundManager.Instance.Play(keyPressClip);}else if (buttonsChoosedNum == 2){inputDetected = true;SoundManager.Instance.Play(keyPressClip);}else if (buttonsChoosedNum == 3){inputDetected = true;SoundManager.Instance.Play(keyPressClip);StartCoroutine(FlashTitleTextAndOpenKeyConfig());}else if (buttonsChoosedNum == 4){Application.Quit();}}}private void PlayChangeButton() { if(keyChangeClip != null){SoundManager.Instance.Play(keyChangeClip);}}private void initButton(int n) {buttonsChoosedNum = n;for(int i = 0; i < buttons.Length; i++){if (i == n){buttons[i].enabled = true;}else {buttons[i].enabled = false;}}}}

这个是游戏首页用的类,主要管是否显示按键设置页面;
按键设置页面也在首页,是个Canvas对象,刚开始会隐藏,选择按键设置按钮并确定后,才会展示。

3.KeyConfigScript.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;public class KeyConfigScript : MonoBehaviour
{bool flashText = false;public static KeyConfigScript Instance = null;[SerializeField] Canvas canvas;public AudioClip keyChangeClip;public AudioClip keySelectClip;/*wsadjkliqeuocvjk*/public UnityEngine.UI.Image[] buttons = new UnityEngine.UI.Image[19];[SerializeField] Text[] buttonsText = new Text[19];[SerializeField] ScrollRect scrollRect;private Action nowScreenAction;private int buttonsChoosedNum = 0;bool alphaKeyPressTextShow = true;//检测按键bool canInput = false;bool canMove = true;private void Awake(){// If there is not already an instance of SoundManager, set it to this.if (Instance == null){Instance = this;}//If an instance already exists, destroy whatever this object is to enforce the singleton.else if (Instance != this){Destroy(gameObject);}//Set SoundManager to DontDestroyOnLoad so that it won't be destroyed when reloading our scene.DontDestroyOnLoad(gameObject);//默认隐藏Close();}private void OnEnable(){}private void initKeysObjects() {//读取下当前配置文件,获得每个按键配置的名称和值for (int i = 0; i < buttons.Length; i++){if (i >= 16){buttons[i].enabled = false;}else{buttonsText[i].text = FileManager.LanguageWasd[i] + ":" + FileManager.WasdNumKeysStr[i];//初始化方法,只有0才是if (i == 0){buttons[i].enabled = true;}else{buttons[i].enabled = false;}}}}private void ChooseButton(){if ( Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[0]) ){if (buttonsChoosedNum > 0){buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum--;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();ScrollUpOrDown(buttonsChoosedNum, false);}else{//移动到最后一个buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum = buttons.Length - 1;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();}}if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[1]) ){if (buttonsChoosedNum < buttons.Length - 1){buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum++;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();ScrollUpOrDown(buttonsChoosedNum, true);}else{//移动到第一个buttons[buttonsChoosedNum].enabled = false;buttonsChoosedNum = 0;buttons[buttonsChoosedNum].enabled = true;PlayChangeButton();}}}private void SelectButton(){//如果是可以移动状态if (canMove){//如果按下选择键if (  Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown((KeyCode)FileManager.WasdNumKeys[13])  ) {//播放声音PlaySelectButton();//关闭移动canMove = false;//如果是这些键,特殊处理然后返回switch (buttonsChoosedNum){case 16:StartCoroutine(FlashTitleTextSecond(Reset));return;case 17:StartCoroutine(FlashTitleTextSecond(SaveAndClose));return;case 18:StartCoroutine(FlashTitleTextSecond(Close));return;}//如果是普通键//闪烁标志位打开flashText = true;//字幕闪烁StartCoroutine(FlashTitleText());}}else{BeforeSettingKey();}}private void BeforeSettingKey(){if (Input.anyKeyDown){//需要看这个键能不能设置bool canSetting = false;foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode))){if (Input.GetKeyDown(key)){// 检查按键是否为可打印字符if ((key >= KeyCode.A && key <= KeyCode.Z) || (key >= KeyCode.Alpha0 && key <= KeyCode.Alpha9)){// 将字符转换为 ASCII 码string keyStr = key.ToString();//char keyChar = keyStr[0];int asciiValue = (int)key;Debug.Log($"按下的键 {key} 对应的 ASCII 码值是:{asciiValue}");SettingKey(keyStr, asciiValue);canSetting = true;break;}else{// 非字母数字键(你可以根据需求处理这些按键)Debug.Log($"按下了非字符键:{key}");if (key == KeyCode.Space){SettingKey("Space", 32);canSetting = true;break;}else if (key == KeyCode.Return){SettingKey("Enter", 13);canSetting = true;break;}else if (key == KeyCode.UpArrow){SettingKey("Up", 273);canSetting = true;break;}else if (key == KeyCode.DownArrow){SettingKey("Down", 274);canSetting = true;break;}else if (key == KeyCode.LeftArrow){SettingKey("Left", 276);canSetting = true;break;}else if (key == KeyCode.RightArrow){SettingKey("Right", 275);canSetting = true;break;}}}}//如果可以设置,再进行后续操作if (canSetting){//停止闪烁StartCoroutine(ResetTitleText());}}}private void SettingKey(string str, int ascII){//更新设置的信息FileManager.WasdNumKeysStrTemp[buttonsChoosedNum] = str;FileManager.WasdNumKeysTemp[buttonsChoosedNum] = ascII;//更新按键文本信息buttonsText[buttonsChoosedNum].text = FileManager.LanguageWasd[buttonsChoosedNum] + ":"+ str;}private IEnumerator FlashTitleText(){while (flashText) { alphaKeyPressTextShow = true;yield return new WaitForSeconds(0.1f);alphaKeyPressTextShow = false;yield return new WaitForSeconds(0.1f);}}private IEnumerator FlashTitleTextSecond(Func<bool> func){for (int i=0; i<5; i++){alphaKeyPressTextShow = true;yield return new WaitForSeconds(0.1f);alphaKeyPressTextShow = false;yield return new WaitForSeconds(0.1f);}alphaKeyPressTextShow = true;yield return new WaitForSeconds(0.1f);//闪烁完毕后才能移动canMove = true;//闪烁完毕后执行func();}private IEnumerator ResetTitleText(){flashText = false;yield return new WaitForSeconds(0.2f);alphaKeyPressTextShow = true;buttonsText[buttonsChoosedNum].enabled = true;canMove = true;}private void PlayChangeButton(){if (keyChangeClip != null){SoundManager.Instance.Play(keyChangeClip);}}private void PlaySelectButton(){if (keySelectClip != null){SoundManager.Instance.Play(keySelectClip);}}//先从配置文件读取配置信息void Start(){}// Update is called once per framevoid Update(){if (canInput){buttonsText[buttonsChoosedNum].enabled = alphaKeyPressTextShow;if (canMove){ChooseButton();}SelectButton();}}//翻页,现在不用private void ScrollUpOrDown(int count, bool isDown){/*if(count == 8 && isDown){scrollRect.normalizedPosition = new Vector2(0, 0);}else if (count == 7 && !isDown) {scrollRect.normalizedPosition = new Vector2(0, 1);}*/}public void Show(Action action) {//翻页,现在不用//scrollRect.normalizedPosition = new Vector2(0, 0);alphaKeyPressTextShow = true;buttonsChoosedNum = 0;initKeysObjects();this.nowScreenAction = action;Debug.Log("show Key Config");canvas.enabled = true;canInput = true;}private bool Reset(){for (int i = 0; i < 16; i++){//先把text内容改了buttonsText[i].text = FileManager.LanguageWasd[i] + ":" + FileManager.DefaultWasdNumKeysStr[i];//然后把临时数组改了FileManager.WasdNumKeysStrTemp[i] = FileManager.DefaultWasdNumKeysStr[i];FileManager.WasdNumKeysTemp[i] = FileManager.DefaultWasdNumKeys[i];}return true;}private bool Save(){for (int i = 0; i < 16; i++){//给实际用的赋值FileManager.WasdNumKeysStr[i] = FileManager.WasdNumKeysStrTemp[i];FileManager.WasdNumKeys[i] = FileManager.WasdNumKeysTemp[i];}//写入文件FileManager.SaveKeyConfig();return true;}private bool SaveAndClose(){Save();Close();return true;}public bool Close() {canvas.enabled = false;canInput = false;//上一个屏幕,改为接受输入if(nowScreenAction != null){nowScreenAction();}return true;//nowScreenManager.GetComponent<TitleScreen>().inputDetected = false;}}

这个类就是按键设置页面用的类,有光标上下移动功能、按钮选择后让字幕闪烁的功能、再次按键后设置新按键功能。

四、备注

unity代码比较复杂,直接复制粘贴是无法使用的,每人的场景元素也不一样,很多变量会不存在,仅供参考。

以上就是个人编写的设置按键的代码,大致逻辑如下:

1.游戏启动后,先判断有没有本地配置文件,如果有、就读取本地配置文件并初始化;如果没有,就用内置配置文件初始化,并把内置配置文件保存到本地。

2.进入按键选择页面时,上下方向键移动光标,按回车可以选择按键,此时按键闪烁,再按另一个键可以设置为新按键。

3.有恢复默认设置功能,有保存并退出功能,有直接退出功能;如果选保存并退出,才把设置的临时按键数组赋值到实际使用的按键数组,并保存到本地配置文件。

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

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

相关文章

独立开发浏览器插件:案例与启示

浏览器插件&#xff08;Browser Extension&#xff09;作为提升用户浏览体验的重要工具&#xff0c;近年来吸引了许多独立开发者的关注。从广告拦截到生产力工具&#xff0c;再到个性化定制功能&#xff0c;浏览器插件的开发为个人开发者提供了一个低成本、高潜力的创业机会。本…

Deep Sleep 96小时:一场没有硝烟的科技保卫战

2025年1月28日凌晨3点&#xff0c;当大多数人还沉浸在梦乡时&#xff0c;一场没有硝烟的战争悄然打响。代号“Deep Sleep”的服务器突遭海量数据洪流冲击&#xff0c;警报声响彻机房&#xff0c;一场针对中国关键信息基础设施的网络攻击来势汹汹&#xff01; 面对美国发起的这场…

基于STM32景区环境监测系统的设计与实现(论文+源码)

1系统方案设计 根据系统功能的设计要求&#xff0c;展开基于STM32景区环境监测系统设计。如图2.1所示为系统总体设计框图。系统以STM32单片机作为系统主控模块&#xff0c;通过DHT11传感器、MQ传感器、声音传感器实时监测景区环境中的温湿度、空气质量以及噪音数据。系统监测环…

Docker 部署教程jenkins

Docker 部署 jenkins 教程 Jenkins 官方网站 Jenkins 是一个开源的自动化服务器&#xff0c;主要用于持续集成&#xff08;CI&#xff09;和持续交付&#xff08;CD&#xff09;过程。它帮助开发人员自动化构建、测试和部署应用程序&#xff0c;显著提高软件开发的效率和质量…

求职刷题力扣DAY34--贪心算法part05

Definition for a binary tree node. class TreeNode: def init(self, val0, leftNone, rightNone): self.val val self.left left self.right right class Solution: def minCameraCover(self, root: Optional[TreeNode]) -> int: # 三种状态0&#xff1a;没有覆盖…

八、Spring Boot 日志详解

目录 一、日志的用途 二、日志使用 2.1 打印日志 2.1.1 在程序中获取日志对象 2.1.2 使用日志对象打印日志 2.2、日志框架介绍 2.2.1 门面模式(外观模式) 2.2.2 门面模式的实现 2.2.3 SLF4J 框架介绍 2.3 日志格式的说明 2.4 日志级别 2.4.1 日志级别的分类 2.4.2…

python:求解爱因斯坦场方程

在物理学中&#xff0c;爱因斯坦的广义相对论&#xff08;General Relativity&#xff09;是描述引力如何作用于时空的理论。广义相对论由爱因斯坦在1915年提出&#xff0c;并被阿尔伯特爱因斯坦、纳森罗森和纳尔逊曼德尔斯塔姆共同发展。广义相对论的核心方程是爱因斯坦场方程…

25寒假算法刷题 | Day1 | LeetCode 240. 搜索二维矩阵 II,148. 排序链表

目录 240. 搜索二维矩阵 II题目描述题解 148. 排序链表题目描述题解 240. 搜索二维矩阵 II 点此跳转题目链接 题目描述 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target 。该矩阵具有以下特性&#xff1a; 每行的元素从左到右升序排列。每列的元素从上到…

014-STM32单片机实现矩阵薄膜键盘设计

1.功能说明 本设计主要是利用STM32驱动矩阵薄膜键盘&#xff0c;当按下按键后OLED显示屏上会对应显示当前的按键键值&#xff0c;可以将此设计扩展做成电子秤、超市收银机、计算器等需要多个按键操作的单片机应用。 2.硬件接线 模块管脚STM32单片机管脚矩阵键盘行1PA0矩阵键盘…

将ollama迁移到其他盘(eg:F盘)

文章目录 1.迁移ollama的安装目录2.修改环境变量3.验证 背景&#xff1a;在windows操作系统中进行操作 相关阅读 &#xff1a;本地部署deepseek模型步骤 1.迁移ollama的安装目录 因为ollama默认安装在C盘&#xff0c;所以只能安装好之后再进行手动迁移位置。 # 1.迁移Ollama可…

提升RAG效果:为何 JSON 格式远胜 Markdown?

在构建强大的 RAG (检索增强生成) 系统时&#xff0c;文档解析是至关重要的第一步。它直接影响着后续的检索效率和生成质量。在众多文档格式中&#xff0c;JSON (JavaScript Object Notation) 格式正逐渐展现出其相对于传统 Markdown 格式的巨大优势。本文将深入探讨 JSON 在 R…

CMake的QML项目中使用资源文件

Qt6.5的QML项目中&#xff0c;我发现QML引用资源文件并不像QtWidgets项目那样直接。 在QtWidgets的项目中&#xff0c;我们一般是创建.qrc​资源文件&#xff0c;然后创建前缀/new/prefix​&#xff0c;再往该前缀中添加一个图片文件&#xff0c;比如&#xff1a;test.png​。…

在K8S中,有哪几种控制器类型?

在Kubernetes中&#xff0c;控制器&#xff08;Controller&#xff09;是用来确保实际集群状态与所需状态保持一致的关键组件。它们监控并自动调整系统以达到预期状态&#xff0c;以下是Kubernetes中主要的几种控制器类型&#xff1a; ReplicationController&#xff08;RC&am…

680.验证回文串||

解题思路 最多删除一个字符使其成为回文串&#xff0c;首先根据回文串的特点&#xff0c;即两边互相对应。 因此判断的方法可以有两种&#xff1a; 翻转后两个字符串相同&#xff0c;是回文串使用双指针进行判断 这里需要涉及删除&#xff0c;因此使用双指针&#xff0c;l和…

SAP HCM 回溯分析

最近总有人问回溯问题&#xff0c;今天把12年总结的笔记在这共享下&#xff1a; 12年开这个图的时候总是不明白是什么原理&#xff0c;教程看N次&#xff0c;网上资料找一大堆&#xff0c;就是不明白原理&#xff0c;后来为搞明白逻辑&#xff0c;按照教材的数据一样做&#xf…

强化学习笔记(5)——PPO

PPO视频课程来源 首先理解采样期望的转换 变量x在p(x)分布下&#xff0c;函数f(x)的期望 等于f(x)乘以对应出现概率p(x)的累加 经过转换后变成 x在q(x)分布下&#xff0c;f(x)*p(x)/q(x) 的期望。 起因是&#xff1a;求最大化回报的期望&#xff0c;所以对ceta求梯度 具体举例…

如何处理 Typecho Joe 主题被抄袭或盗版的问题

在开源社区中&#xff0c;版权保护是一个非常重要的话题。如果你发现自己的主题&#xff08;如 Joe 主题&#xff09;被其他主题&#xff08;如子比主题&#xff09;抄袭或盗版&#xff0c;你可以采取以下措施来维护自己的权益。 一、确认侵权行为 在采取任何行动之前&#xf…

chatGPT写的网页版贪吃蛇小游戏

chatGPT写的网页版贪吃蛇小游戏 前言网页版贪吃蛇小游戏 前言 之前无聊&#xff0c;让ChatGPT写了一段基于html语言的贪吃蛇小游戏代码 网页版贪吃蛇小游戏 将以下内容复制到记事本&#xff0c;重命名为xxx.html即可打开浏览器游玩 这里是一个使用HTML、CSS和JavaScript编写…

Linux第105步_基于SiI9022A芯片的RGB转HDMI实验

SiI9022A是一款HDMI传输芯片&#xff0c;可以将“音视频接口”转换为HDMI或者DVI格式&#xff0c;是一个视频转换芯片。本实验基于linux的驱动程序设计。 SiI9022A支持输入视频格式有&#xff1a;xvYCC、BTA-T1004、ITU-R.656&#xff0c;内置DE发生器&#xff0c;支持SYNC格式…

人机交互系统实验三 多通道用户界面

实验目的和要求 1)了解常见的多通道用户界面 2)查找资料&#xff0c;熟悉一种多通道用户界面并写出综述 实验环境 Windows10 实验内容与过程 (一) 实验内容: 要求上网查找资料&#xff0c;熟悉一种多通道用户界面并写出综述&#xff0c;可以是眼动跟踪、手势识别、 三维…