本案例来自于siki学院,仅作笔记交流,不做任何商业用途
一个Json的样例
[
{
"id": 1,
"name": "血瓶",
"type": "Consumable",
"quality": "Common",
"descriptions": "加血",
"capacity": 10,
"buyprice": 10,
"sellprice": 5,
"hp": 10,
"mp": 5,
"sprites": "Items/hp"
}
]
一个物品管理类的单例模式 ,这里我使用??代替是否为空,用lambda表达式代替get只读属性
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
#region 单例模式
private InventoryManager() { }
private static InventoryManager instance;
public static InventoryManager Instance => instance??
(instance = GameObject.Find("InventoryManager").GetComponent<InventoryManager>());
#endregion
}