重做物品系统
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备栏
|
||||
/// 装备类型:稀有度/装备类型/次级类型/种类
|
||||
/// <br/>稀有度:普通,精良,稀有,史诗,传奇,神话
|
||||
/// <br/>装备类型:武器,护甲,饰品
|
||||
/// <br/>次级类型:单手,副手,双手,上衣,头盔,手套,腰带,鞋子,项链,戒指,手镯
|
||||
/// <br/>装备种类:剑,锤,枪,弓,斧头,盾牌,法杖,魔杖
|
||||
/// </summary>
|
||||
public class Equipment {
|
||||
/// <summary> 插槽字典 </summary>
|
||||
public Dictionary<string, InventorySlot> dictionary = new Dictionary<string, InventorySlot>();
|
||||
|
||||
/// <summary> 索引器 </summary>
|
||||
public InventorySlot this[string key] => dictionary[key];
|
||||
/// <summary> 索引器(枚举) </summary>
|
||||
public InventorySlot this[Enum key] => dictionary[key.ToString()];
|
||||
|
||||
/// <summary> 遍历数组 </summary>
|
||||
public void ForEach(Action<string, InventorySlot> action) {
|
||||
foreach (var item in dictionary) { action?.Invoke(item.Key, item.Value); }
|
||||
}
|
||||
|
||||
/// <summary> 添加插槽 </summary>
|
||||
public void AddSlot(Enum name, string type) {
|
||||
AddSlot(name.ToString(), type);
|
||||
}
|
||||
/// <summary> 添加插槽 </summary>
|
||||
public void AddSlot(string name, string type) {
|
||||
var slot = new InventorySlot();
|
||||
slot.name = name;
|
||||
slot.limits = new List<string>(type.Split("/"));
|
||||
AddSlot(slot);
|
||||
}
|
||||
/// <summary> 添加插槽 </summary>
|
||||
public void AddSlot(InventorySlot slot) {
|
||||
if (dictionary.ContainsKey(slot.name)) { return; }
|
||||
dictionary.Add(slot.name, slot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d078f2759ef3ef4bb65217dd9b2fb94
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备物品
|
||||
/// </summary>
|
||||
public class EquipmentItem : InventoryItem {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d13e432b42e13064e867855fc64ed2fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备插槽
|
||||
/// </summary>
|
||||
public class EquipmentSlot {
|
||||
/// <summary> 数量 </summary>
|
||||
public int count;
|
||||
/// <summary> 名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 物品 </summary>
|
||||
public InventoryItem item;
|
||||
/// <summary> 限制类型 </summary>
|
||||
public List<string> limits = new List<string>();
|
||||
|
||||
/// <summary> 堆叠数量 </summary>
|
||||
public int MaxStack => item != null ? item.stack : 0;
|
||||
/// <summary> 图片 </summary>
|
||||
public Sprite Sprite => item != null ? item.sprite : null;
|
||||
|
||||
/// <summary> 验证类型 </summary>
|
||||
public bool Verify(InventoryItem item) {
|
||||
string[] types = item.type.Split("/");
|
||||
return limits.All(item => types.Contains(item));
|
||||
}
|
||||
|
||||
/// <summary> 替换 </summary>
|
||||
public (InventoryItem, int) Replace(InventoryItem newItem, int count) {
|
||||
int remain = this.count;
|
||||
InventoryItem old = item;
|
||||
item = newItem;
|
||||
this.count = count;
|
||||
return (old, remain);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1d68199e9959734e85efd7a39d4d78c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user