Scene面版下的GameObjects及脚本挂载的位置:
Main Camera
Directional Light
UI root
Camera
Center
UIWindow_Bag (UIWindowBag.cs)
BGParent
BG_1
BG_2
GoodsBox
Grid
sprite(+预设体(BagItem.cs)BG(sprite);Color(sprite);Icon(sprite);Num(label))
sprite
sprite
sprite
sprite
sprite
sprite
sprite
Coin
Coin_BG
Label
SaleBtn
BG
Label
UIInformation (UIInformation.cs)
BG
Name
Label
Color
Label
Level
Label
Price
Label
Message
Label
代码如下:=============================
BagDemo (Test.cs)
using UnityEngine;
using System.Collections;
//物品类型
public enum GoodsType
{
Equip, //表示装备
Drug //表示药水
}
//物品的品质
public enum GoodsColor
{
BaiSe,
LvSe,
LanSe,
ZiSe,
ChengSe
}
//物品类
public class BagClass{
public int id; //物品ID
public string icon; //物品图片名称
public string name; //物品名称
public GoodsType type; //物品类型
public GoodsColor color; //物品品质
public int count; //物品数量
public int goodsLevel; //物品等级
public string message; //物品信息
public int price; //价格
public bool isWear; //是否穿戴
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//控制整个界面的显示
public class UIWindowBag : MonoBehaviour {
//所有格子的父节点
private Transform boxParent;
//出售物品的按钮
private Transform saleBtn;
//金币
private Transform coinLabel;
//显示物品的预设体
private GameObject goods;
//程序一开始运行时最先执行
void Awake()
{
Init();
//给出售按钮添加事件
EventDelegate.Add(saleBtn.GetComponent<UIButton>().onClick,
() => {
BagManager.GetInstance().SaleGoods();
//更新前先删除已有的物品
OnDisable();
//更新物品
BagUpdate();
});
}
//窗口被激活时调用
void OnEnable()
{
BagUpdate();
}