标签:tail contains ict pos ngui box 个数 渲染 collect
···
public List<string> GetItemList() //返回仓库中的物品列表
{
List<string> list = new List<string>(_items.Keys); //返回所有Dictionary键的列表
return list;
}
public int GetItemCount(string name) //返回仓库中一个指定物品到的个数
{
if (_items.ContainsKey(name))
{
return _items[name];
}
return 0;
}
···
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///<summary>
///4.14
///显示仓库
///</summary>
public class BasicUI : MonoBehaviour
{
void OnGUI()
{
int posX = 10;
int posY = 10;
int width = 100;
int height = 30;
int buffer = 10;
List<string> itemList = Managers.Inventory.GetItemList();
if(itemList.Count == 0 ) //当仓库为空时,打印一条控制台消息
{
GUI.Box(new Rect(posX, posY, width, height), "No Items");
}
foreach (string item in itemList)
{
int count = Managers.Inventory.GetItemCount(item);
Texture2D image = Resources.Load<Texture2D>("Icons/" + item); //从Resources目录中加载资源的方法
GUI.Box(new Rect(posX, posY, width, height), new GUIContent("(" + count + ")", image));
posX += width + buffer; //循环中每次向一边偏移
}
}
}
标签:tail contains ict pos ngui box 个数 渲染 collect
原文地址:https://www.cnblogs.com/Akyy/p/10660637.html