当前位置:网站首页>Fabrication d'un sac à dos simple fairygui
Fabrication d'un sac à dos simple fairygui
2022-07-06 12:38:00 【Sq Liu】
FairyGUIFabrication de sacs à dos simples
Aperçu des effets:
Un.、Créer un nouveau projet
Renommer
2.、 Faire des fenêtres de sac à dos
1、 Composant conteneur du nouveau sac à dos (BagWindow)
2、 Nouveau composant de cadre de fenêtre (WindowFrame)
3、 Importer des ressources matérielles
4、InWindowFrameOpération centrale
(1) Glissez dans l'arrière - plan du sac à dos
Et van0Renommer enBG( C'est l'arrière - plan du sac à dos )
(2) Nouveau bouton d'arrêt (ButtonClose)
(3) Nouveau dessin comme occupation (dragArea——Zone de traînée)
5、InBagWindowOpération centrale
(1)Oui.WindowFrameGlisser dansBagWindow, Et définir la taille de ses composants
(2) Glisser dans la liste pour transporter des objets de jeu
(3) Faire une grille dans la liste ——Nouveau boutonItem
(4)ÉditionItem
Glisser dans la carte de fond
Glisser dansTitle
Glisser dans le chargeur
6、InMainOpération centrale
(1) Créer un bouton d'affichage d'image ItemView
(2)C'est exact.ItemView Faites quelques améliorations
(3) Nouveau bouton pop - up du sac à dos BagButton
(4)Double - clicBagButton Bouton pour l'éditer
7、RetourBagWindow,Assigner une valeur à
Renommer, Faites quelques petits changements .
Trois、 Package Export Publishing
Quatre、UnityAffichage en
1、NouveauUnityProjets
2、 Télécharger le FairyGUI
Lors de l'importation après téléchargement ,Il faut faire attention,- Oui.ExamplesEn bas.BagSupprimer. Parce qu'il n'a pas été supprimé lors de l'importation précédente , Ce qui a conduit à des phénomènes étranges .
3、UnityAffichage en
Cinq、Contrôle du Code
1、 Créer deux nouveaux scripts
L'un est un script de fenêtre de sac à dos BagWindow, L'un est le script principal Bag.
2、Modifier le script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class BagWindow : Window
{
public BagWindow()
{
}
protected override void OnInit()
{
this.contentPane = UIPackage.CreateObject("Bag", "BagWindow").asCom;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class Bag : MonoBehaviour
{
private GComponent mainUI;
private GButton playerView;
private BagWindow bagWindow;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
playerView = mainUI.GetChild("playerView").asButton;
playerView.onClick.Add(UseItem);
bagWindow = new BagWindow();
mainUI.GetChild("bagButton").onClick.Add(() => {
bagWindow.Show(); });
}
// Update is called once per frame
void Update()
{
}
private void UseItem()
{
}
}
3、Effets de fonctionnement
4、 Charger le contenu du sac à dos
(1)Changez.BagWindow Nom de la liste dans :itemList,EtItemViewÀ l'intérieur.title, Et republié
(2) Continuer à coder les fonctions de mise en oeuvre
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class BagWindow : Window
{
private GList list;
private GButton playerView;
public BagWindow(GButton targetButton)
{
playerView = targetButton;
}
protected override void OnInit()
{
this.contentPane = UIPackage.CreateObject("Bag", "BagWindow").asCom;
list = this.contentPane.GetChild("itemList").asList;
list.itemRenderer = RenderListItem;
list.numItems = 20;
for (int i = 0; i < list.numItems - 10; i++)
{
GButton button = list.GetChildAt(i).asButton;
button.onClick.Add(() => {
ClickItem(button); });
}
}
private void RenderListItem(int index, GObject obj)
{
GButton button = obj.asButton;
button.icon = UIPackage.GetItemURL("Bag", "i" + index);
button.title = index.ToString();
}
private void ClickItem(GButton button)
{
playerView.title = button.title;
playerView.icon = button.icon;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class Bag : MonoBehaviour
{
private GComponent mainUI;
private GButton playerView;
private BagWindow bagWindow;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
playerView = mainUI.GetChild("playerView").asButton;
playerView.onClick.Add(UseItem);
bagWindow = new BagWindow(playerView);
bagWindow.SetXY(121, 63); // Définir la position initiale de la fenêtre contextuelle du sac à dos
mainUI.GetChild("bagButton").onClick.Add(() => {
bagWindow.Show(); });
}
private void UseItem()
{
playerView.icon = null;
playerView.title = "Blanc";
}
}
Six、Résultats finaux
边栏推荐
- Get the position of the nth occurrence of the string
- MySQL performance tuning - dirty page refresh
- 单片机蓝牙无线烧录
- SSD technical features
- (the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
- Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
- JS variable types and common type conversions
- Expected value (EV)
- (课设第一套)1-4 消息传递接口 (100 分)(模拟:线程)
- Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
猜你喜欢
ORA-02030: can only select from fixed tables/views
MySQL takes up too much memory solution
Vulnhub target: hacknos_ PLAYER V1.1
[Red Treasure Book Notes simplified version] Chapter 12 BOM
Unity scene jump and exit
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
C programming exercise
基于Redis的分布式ID生成器
Page performance optimization of video scene
Vscode basic configuration
随机推荐
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
MySQL error warning: a long semaphore wait
Pat 1097 duplication on a linked list (25 points)
Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
Arduino get random number
基于Redis的分布式ID生成器
[Leetcode15]三数之和
InnoDB dirty page refresh mechanism checkpoint in MySQL
JS变量类型以及常用类型转换
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
[Offer29] 排序的循环链表
程序设计大作业:教务管理系统(C语言)
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
SVN更新后不出现红色感叹号
Types de variables JS et transformations de type communes
(一)R语言入门指南——数据分析的第一步
Esp8266 connect onenet (old mqtt mode)
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Vscode basic configuration