当前位置:网站首页>Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
2022-07-25 11:22:00 【InfoQ】
- CSDN Home page
- GitHub Open source address
- Unity3D Plug in sharing
- Jane book address
- My personal blog
- QQ Group :1040082875
One 、 Preface
Two 、 Set up the scene
2-1 Prefabrication



using UnityEngine;
using UnityEngine.UI;
public class PersonItem : MonoBehaviour
{
public Text ID;
public Text Name;
public Text Sex;
public Text Age;
public Text Post;
public Text Work;
public Button ViewInfo;
public Image Backgroud;
}


2-2 New personnel pop-up


2-2 Display personnel details pop-up


3、 ... and 、 Implementation code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PersonControl : MonoBehaviour
{
public PersonItem PersonItemParfabs;// Personnel prefabrication
public Transform PersonParent;// Personnel parent node
public GameObject PopupAddInfo;// Popup Add information
public InputField InputName;
public Dropdown DropSex;
public InputField InputAge;
public InputField InputPost;
public InputField InputWorkExp;
public Button BtnAddInfo;// Popup Add information to all components
public GameObject PopupShowInfol;// Popup display information
public Text Name;
public Text Sex;
public Text Age;
public Text Post;
public Text WorkExp;// All components of the information to be displayed in the pop-up window
public Button AddPerson;// Add people button
private int ID = 0;
void Start()
{
// Initialize and close all pop-up windows
PopupAddInfo.SetActive(false);
PopupShowInfol.SetActive(false);
// Add button event
AddPerson.onClick.AddListener(() =>
{
PopupAddInfo.SetActive(true);
});
BtnAddInfo.onClick.AddListener(AddInfoEvent);
}
private void AddInfoEvent()
{
ID++;
PersonItem item = Instantiate(PersonItemParfabs, Vector3.zero, Quaternion.identity, PersonParent);
item.ID.text = ID.ToString();
item.Name.text = InputName.text;
item.Sex.text = DropSex.captionText.text;
item.Age.text = InputAge.text;
item.Post.text = InputPost.text;
item.Work.text = InputWorkExp.text;
item.ViewInfo.onClick.AddListener(() => ShowInfo(item.Name.text, item.Sex.text, item.Age.text, item.Post.text, item.Work.text));
item.Backgroud.color = ID % 2 == 1 ? Color.blue : Color.red;// Distinguish by parity Is the background presentation blue or red A ternary expression is used
PopupAddInfo.SetActive(false);
}
private void ShowInfo(string name, string sex, string age, string post, string work)
{
PopupShowInfol.SetActive(true);
Name.text = name;
Sex.text = sex;
Age.text = age;
Post.text = post;
WorkExp.text = work;
}
}




Four 、 an account of happenings after the event being told
边栏推荐
猜你喜欢

玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧

mysql高级语句(一)(总有一个人的出现,让你的生活不再继续糟糕)

SQL语言(四)
Learn NLP with Transformer (Chapter 4)

There is a newline problem when passing shell script parameters \r

用Unity不会几个插件怎么能行?Unity各类插件及教程推荐

Esp32c3 based on the example tutorial of esp32 Rainmaker development under Arduino framework

Learn NLP with Transformer (Chapter 5)

一篇看懂:IDEA 使用scala 编写wordcount程序 并生成jar包 实测

游戏背包系统,“Inventory Pro插件”,研究学习-----妈妈再也不用担心我不会做背包了(Unity3D)
随机推荐
The most detailed MySQL index analysis (mind map is attached at the end of the article)
web移动端:touchmove实现局部滚动
LVS负载均衡之LVS-NAT搭建Web群集
Learn NLP with Transformer (Chapter 2)
The most complete detailed tutorial on importing ad into lichuanyuan device packaging Library in history (always white and always cool)
API supplement of JDBC
feign客户端请求之LoadBalancerLifecycle生命周期
BGP federal experiment
HCIA experiment (07) comprehensive experiment
Hcip experiment (04)
史上最全的立创元器件封装库导入AD详细教程(一直白嫖一直爽)
shell-第八章练习
上周热点回顾(7.18-7.24)
Learning Weekly - total issue 63 - an open source local code snippet management tool
Digital twin everything can be seen | connecting the real world and digital space
The B2B2C multi merchant system has rich functions and is very easy to open!!!
游戏背包系统,“Inventory Pro插件”,研究学习-----妈妈再也不用担心我不会做背包了(Unity3D)
三万字速通Servlet
HCIP(12)
学习路之PHP--Phpstudy 提示 Mysqld.Exe: Error While Setting Value ‘NO_ENGINE_SUBSTITUTION 错误的解决办法