当前位置:网站首页>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
边栏推荐
- Idea problem record
- (课设第一套)1-4 消息传递接口 (100 分)(模拟:线程)
- What is the maximum length of MySQL varchar field
- 2021.11.10汇编考试
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- [Nodejs] 20. Koa2 onion ring model ----- code demonstration
- [leetcode19] delete the penultimate node in the linked list
- Générateur d'identification distribué basé sur redis
- Talking about the startup of Oracle Database
- ES6 grammar summary -- Part 2 (advanced part es6~es11)
猜你喜欢
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
In 2020, the average salary of IT industry exceeded 170000, ranking first
JS function promotion and declaration promotion of VaR variable
Common properties of location
MySQL時間、時區、自動填充0的問題
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
History object
Naive Bayesian theory derivation
Guided package method in idea
NRF24L01 troubleshooting
随机推荐
Minio文件下载问题——inputstream:closed
VSCode基础配置
idea中导包方法
js 变量作用域和函数的学习笔记
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
Walk into WPF's drawing Bing Dwen Dwen
[leetcode622] design circular queue
Who says that PT online schema change does not lock the table, or deadlock
Database course design: college educational administration management system (including code)
Basic operations of databases and tables ----- view data tables
HCIP Day 12
MySQL replacement field part content
Derivation of logistic regression theory
Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
(the first set of course design) 1-4 message passing interface (100 points) (simulation: thread)
Expected value (EV)
Types de variables JS et transformations de type communes
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
(1) Introduction Guide to R language - the first step of data analysis