当前位置:网站首页>GUI pull-down menu of unity3d evil door implementation dropdown design has no duplicate items
GUI pull-down menu of unity3d evil door implementation dropdown design has no duplicate items
2022-06-25 07:35:00 【mudapao】
** Unity3D The evil door implementation series provides some requirements for bloggers in the actual development process , Because the personal level can not be realized in a serious way, it is adopted “ evil ways ” Achieve the same effect .**
This series is only for sharing ideas , If there is an error or “ carry coals to newcastle ” The place of , Please correct me a lot .
【 summary 】
Using the combination of buttons and pull-down menus , Click the button to display the drop-down menu , Realize menu control without duplicate items .
【 Specific process 】
U3D Use dropdown Make menu effect , There will be the problem of duplicate menu titles and items . Even if you change label, It will also change to the default first option at run time .
Bloggers have checked many articles , The main thing is to play tricks on the menu style , There is no mention of this repeated problem . Therefore, it is decided to adopt the form of cooperation with the button control , Separate menu titles from options , Just a few easy steps , You can change the method “ eliminate ” Duplicate item .
1. Create... In the project canvas canvas , stay canvas Create empty menu objects in for easy management , Then select Create in the menu object UI–button and UI–dropdown, Write on demand dropdown Of options. hide dropdown Of label and arrow.
2. take dropdown Control to button Upper and button coincidence , modify button The text of the control is “ menu ”. If menu design has color , Notice that the color of the button changes to transparent , Integrate with the environment . stay button Add a mouse click event to the properties , take dropdwon Select as the control object ,Runtime only The next choice dropdown–show(). Click the button to display the menu items .

3. Next, you can use the normal binding script to dropdown Options for event listening and response . Create a Script Folders are used to manage scripts , And create... In the folder menu Script . And in menu Edit the following code in the script (case The following can be replaced by the corresponding reaction event ):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Menu : MonoBehaviour
{
// Implement multiple menu monitoring
public List<Dropdown> DropdownList;
public void EventListening()
{
switch (DropdownList[0].value)
{
case 0:
Debug.Log(" The kung pao chicken is ready ");
break;
case 1:
Debug.Log(" Mapo Tofu is ready ");
break;
case 2:
Debug.Log(" Fish flavored shredded pork is ready ");
break;
case 3:
Debug.Log(" Boiled meat slices are ready ");
break;
default:
break;
}
}
}
4. Click on the menu object , Create an empty object , Name it MenuControl, And drag the script you just created into the object .
The variables defined in the script will be displayed after dragging the script ,List Is the number of menus , Free to set . I'm going to set it to 1, And put the elements 0 Set to the menu just created _dropdown. This step is mainly used to expand menu management in the future .
5. Select menu _dropdown, Click on the bottom when the value changes + Number , take MenuControl Select as the control object ( Or drag it directly ),Runtime Only Side selection Menu–Eventlistening, The response event of the drop-down menu option can be realized .( Multiple menus are in Menu Create the corresponding... In the script listening function )
【 Realization effect 】

【 Source code Demo】
Unity Editor version :2019.4.35
https://download.csdn.net/download/mudapao/85651230
边栏推荐
- Vscode official configuration synchronization scheme
- Escape analysis of 982 golang
- The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
- 不同路径II[针对DFS的动态规划改进]
- MySQL - definition and assignment of variables
- Global variables & local variables
- 对链表进行插入排序[dummy统一操作+断链核心--被动节点]
- Design a MySQL table for message queue to store message data
- [introduction to UVM== > episode_9] ~ register model, integration of register model, general methods of register model, application scenarios of register model
- smartBugs安装小问题总结
猜你喜欢

Sqlmap advanced use – cookies

Hanxin's trick: consistent hashing

Orcad Schematic常用功能

5g private network market is in full swing, and it is crucial to solve deployment difficulties in 2022

Rotation vector (rotation matrix) and Euler angle

Sichuan earth microelectronics 8-channel isolated digital input receiver
![[batch dos-cmd command - summary and summary] - external command -cmd download command and packet capture command (WGet)](/img/00/5a5b081b78ad6a6c1c3a3c847dd315.png)
[batch dos-cmd command - summary and summary] - external command -cmd download command and packet capture command (WGet)
![Analysis on the trend of the number of national cinemas, film viewers and average ticket prices in 2021 [figure]](/img/01/594990789cbc1817dbbf61b7dd0c4c.jpg)
Analysis on the trend of the number of national cinemas, film viewers and average ticket prices in 2021 [figure]

【UVM入门 ===> Episode_9 】~ 寄存器模型、寄存器模型的集成、寄存器模型的常规方法、寄存器模型的应用场景

VectorDraw Developer Framework 10.10
随机推荐
图扑软件数字孪生 3D 风电场,智慧风电之海上风电
[Yu Yue education] engineering testing technology reference of Wenhua University
What is the difference between norflash and nandflash
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令(cd、title、mode、color、pause、chcp、exit)
关于硬件问题造成的MCU死机,过来人简单的谈一谈
College entrance examination voluntary filling, why is the major the last consideration?
高考志愿填报,为啥专业最后考虑?
Change the current count of auto increment values in MySQL- Changing the current count of an Auto Increment value in MySQL?
对链表进行插入排序[dummy统一操作+断链核心--被动节点]
VectorDraw Web Library 10.10
Debug through yalc before releasing NPM package
Let's talk about MCU crash caused by hardware problems
From perceptron to transformer, a brief history of deep learning
威迈斯新能源冲刺科创板:年营收17亿 应收账款账面价值近4亿
Sqlmap advanced use – cookies
14 BS object Node name Name attrs string get node name attribute content
线程状态变化涉及哪些常用 API
shell小技巧(一百三十四)简单的键盘输入记录器
alphassl通配符证书送一个月
我与CSDN的一年时光及大学经验分享