WXGame/Blacksmith/Assets/Script/ItemDataAsset.cs

65 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
public class ItemDataAsset : ScriptableObject
{
#if UNITY_EDITOR
[MenuItem("工具/创建资源数据")]
static void CreateExampleAssetInstance()
{
var exampleAsset = CreateInstance<ItemDataAsset>();
AssetDatabase.CreateAsset(exampleAsset, "Assets/Resources/ItemDataAsset.asset");
AssetDatabase.Refresh();
}
#endif
public List<ItemResourcesData> Datas;
public List<SlotCrafting> crafting;
public List<BuyItemValue> buyItem;
public int ItemValue(int id)
{
var buy = buyItem.FirstOrDefault(data => data.id == id);
return buy!=null?buyItem.FirstOrDefault(data => data.id == id).num:0;
}
public Sprite IconSprite(int id)
{
var data = Datas.FirstOrDefault(data => data.id == id);
return data?.icon;
}
}
[Serializable]
public class ItemResourcesData
{
public int id;
public Sprite icon;
}
[Serializable]
public class SlotCrafting
{
public int id;
public List<ItemDataNum> craftID;
}
[Serializable]
public class NPCBuyData
{
public int buyID;
public int npcID;
}
[Serializable]
public class BuyItemValue
{
public int id;
public int num;
}