视频参考:Unity教程:背包系统:04:显示在背包里(C# code) InventoryManager_哔哩哔哩_bilibili
素材下载:
https://pan.baidu.com/s/1o7_RW_QQ1rrAbDzT69ApRw
提取码: 8s95
unity简单的背包系统笔记(二)(有视频讲解)_yanyufeichengxu的博客-CSDN博客
unity简单的背包系统笔记(三)(有视频讲解)_yanyufeichengxu的博客-CSDN博客
unity简单的背包系统笔记(四)(有视频讲解)+知识点整理合集_yanyufeichengxu的博客-CSDN博客
目录
1.创建panel(修改为居中模式:这样就可以调节长宽高)起名叫:Bag 515 415
就是弄个背景框,弄个grid lay out
-----
2.创建数据库
使用:ScriptableObject API->不用挂载在脚本上
创建Item脚本(logic:存储数据)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName ="New Item",menuName ="Inventory/New Item")]//默认名字,右键菜单叫什么名字/
/// <summary>
/// 属性
/// </summary>
public class Items : ScriptableObject
{/// <summary>
/// 物品的名字
/// </summary>
public string itemName;
/// <summary>
/// 物品的图片
/// </summary>
public Sprite itemImage;
public int ItemHeld;///数量
[TextArea]//多段描述,单行描述就不用加了
/// <summary>
/// 介绍
/// </summary>
public string ItemInfo;
/// <summary>
/// 是否可以装备上
/// </summary>
public bool equip;
}
----
创建背包脚本Inventory
创建脚本Inventory,我希望这个背包系统是一个列表他将我所有的物品都存储在一个背包中,这样就可以创建不同的背包:铁匠铺的背包,药水商的背包等等,装备武器的背包
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Inventory", menuName = "Inventory/New Inventory")]
public class Inventory : ScriptableObject
{
public List<Items> itemList = new List<Items> ();
// public Items[] itemlist;
}
这样就把item里的数据都存储到了Inventory背包里面
list数组和普通数组:
list数组常用方法
1,Capacity获取容量大