1
This commit is contained in:
+3
-2
@@ -5,6 +5,7 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// 装备 - 物品
|
||||
/// </summary>
|
||||
public class DataItemEquipment : DataItem {
|
||||
|
||||
public class DataEquipment : DataItem {
|
||||
/// <summary> 装备类型 </summary>
|
||||
public string type;
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// 材料 - 物品
|
||||
/// </summary>
|
||||
public class DataItemMaterial : DataItem {
|
||||
public class DataMaterial : DataItem {
|
||||
/// <summary> 最大堆叠数 </summary>
|
||||
public int maxStack;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备栏
|
||||
/// </summary>
|
||||
public class Equipment {
|
||||
/// <summary> 插槽字典 </summary>
|
||||
public Dictionary<string, EquipmentSlot> dictionary = new Dictionary<string, EquipmentSlot>();
|
||||
|
||||
/// <summary> 索引器 </summary>
|
||||
public EquipmentSlot this[string key] => dictionary[key];
|
||||
|
||||
/// <summary> 添加插槽 </summary>
|
||||
public void AddSlot(EquipmentSlot slot) => dictionary.Add(slot.name, slot);
|
||||
}
|
||||
/// <summary>
|
||||
/// 装备插槽
|
||||
/// </summary>
|
||||
public abstract class EquipmentSlot {
|
||||
/// <summary> 名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 物品 </summary>
|
||||
public DataEquipment item;
|
||||
|
||||
public EquipmentSlot(string name) => this.name = name;
|
||||
}
|
||||
/// <summary>
|
||||
/// 武器 - 装备插槽
|
||||
/// </summary>
|
||||
public class WeaponSlot : EquipmentSlot {
|
||||
/// <summary> 副手插槽 </summary>
|
||||
public DeputySlot deputy;
|
||||
|
||||
public WeaponSlot(string name) : base(name) { }
|
||||
}
|
||||
/// <summary>
|
||||
/// 副手 - 装备插槽
|
||||
/// </summary>
|
||||
public class DeputySlot : EquipmentSlot {
|
||||
/// <summary> 主手插槽 </summary>
|
||||
public WeaponSlot weapon;
|
||||
|
||||
public DeputySlot(string name) : base(name) { }
|
||||
}
|
||||
/// <summary>
|
||||
/// 护甲 - 装备插槽
|
||||
/// </summary>
|
||||
public class ArmorSlot : EquipmentSlot {
|
||||
|
||||
public ArmorSlot(string name) : base(name) { }
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 饰品 - 装备插槽
|
||||
/// </summary>
|
||||
public class AccessorySlot : EquipmentSlot {
|
||||
|
||||
public AccessorySlot(string name) : base(name) { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13afb37aea13dc94b97e8e85af77b5b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,9 +8,9 @@ using MuHua;
|
||||
/// </summary>
|
||||
public class ManagerItem : ModuleSingle<ManagerItem> {
|
||||
/// <summary> 材料列表 </summary>
|
||||
public List<ConstItemMaterial> materials;
|
||||
public List<ConstMaterial> materials;
|
||||
/// <summary> 装备列表 </summary>
|
||||
public List<ConstItemEquipment> equipments;
|
||||
public List<ConstEquipment> equipments;
|
||||
|
||||
protected override void Awake() => NoReplace(false);
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 681e43f413713dd46914cb6348821756
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 饰品 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/饰品")]
|
||||
public class ConstAccessory : ConstItem {
|
||||
/// <summary> 饰品类型 </summary>
|
||||
public AccessoryType type;
|
||||
|
||||
public override DataItem To() {
|
||||
DataEquipment item = new DataEquipment();
|
||||
item.name = name;
|
||||
item.sprite = sprite;
|
||||
item.type = type.ToString();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 饰品类型
|
||||
/// </summary>
|
||||
public enum AccessoryType {
|
||||
戒指, 手镯, 项链
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe5fcaac3685ff2408432feaa1d0999a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 护甲 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/护甲")]
|
||||
public class ConstArmor : ConstItem {
|
||||
/// <summary> 护甲类型 </summary>
|
||||
public ArmorType type;
|
||||
|
||||
public override DataItem To() {
|
||||
DataEquipment item = new DataEquipment();
|
||||
item.name = name;
|
||||
item.sprite = sprite;
|
||||
item.type = type.ToString();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 护甲类型
|
||||
/// </summary>
|
||||
public enum ArmorType {
|
||||
上衣, 头盔, 手套, 腰带, 鞋子
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33876f23eac24b14e8ba9cca9d545a4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/装备")]
|
||||
public class ConstEquipment : ConstItem {
|
||||
/// <summary> 装备类型 </summary>
|
||||
public string type;
|
||||
|
||||
public override DataItem To() {
|
||||
DataEquipment item = new DataEquipment();
|
||||
item.name = name;
|
||||
item.sprite = sprite;
|
||||
item.type = type;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 武器 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/武器")]
|
||||
public class ConstWeapon : ConstItem {
|
||||
/// <summary> 武器类型 </summary>
|
||||
public WeaponType type;
|
||||
|
||||
public override DataItem To() {
|
||||
DataEquipment item = new DataEquipment();
|
||||
item.name = name;
|
||||
item.sprite = sprite;
|
||||
item.type = type.ToString();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 武器类型
|
||||
/// </summary>
|
||||
public enum WeaponType {
|
||||
单手, 副手, 双手
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45818eb64c9b04441b20b29f0230edb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/装备")]
|
||||
public class ConstItemEquipment : ConstItem {
|
||||
|
||||
}
|
||||
+2
-2
@@ -6,12 +6,12 @@ using UnityEngine;
|
||||
/// 材料 - 物品常量
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "MuHua/物品系统/材料")]
|
||||
public class ConstItemMaterial : ConstItem {
|
||||
public class ConstMaterial : ConstItem {
|
||||
/// <summary> 最大堆叠数 </summary>
|
||||
public int maxStack = 99;
|
||||
|
||||
public override DataItem To() {
|
||||
DataItemMaterial item = new DataItemMaterial();
|
||||
DataMaterial item = new DataMaterial();
|
||||
item.name = name;
|
||||
item.sprite = sprite;
|
||||
item.maxStack = maxStack;
|
||||
@@ -9,6 +9,7 @@ using MuHua;
|
||||
public class SingleManager : ModuleSingle<SingleManager> {
|
||||
|
||||
public Inventory inventory;
|
||||
public Equipment equipment;
|
||||
|
||||
public ItemReward materialReward;
|
||||
public ItemReward equipmentReward;
|
||||
@@ -17,6 +18,22 @@ public class SingleManager : ModuleSingle<SingleManager> {
|
||||
|
||||
private void Start() {
|
||||
inventory = new Inventory(40);
|
||||
equipment = new Equipment();
|
||||
equipment.AddSlot(new WeaponSlot("主手"));
|
||||
equipment.AddSlot(new DeputySlot("副手"));
|
||||
|
||||
equipment.AddSlot(new ArmorSlot("上衣"));
|
||||
equipment.AddSlot(new ArmorSlot("头盔"));
|
||||
equipment.AddSlot(new ArmorSlot("手套"));
|
||||
equipment.AddSlot(new ArmorSlot("腰带"));
|
||||
equipment.AddSlot(new ArmorSlot("鞋子"));
|
||||
|
||||
equipment.AddSlot(new AccessorySlot("项链"));
|
||||
equipment.AddSlot(new AccessorySlot("戒指1"));
|
||||
equipment.AddSlot(new AccessorySlot("戒指2"));
|
||||
equipment.AddSlot(new AccessorySlot("手镯1"));
|
||||
equipment.AddSlot(new AccessorySlot("手镯2"));
|
||||
|
||||
materialReward = new ItemReward();
|
||||
materialReward.Settings(ManagerItem.I.materials);
|
||||
equipmentReward = new ItemReward();
|
||||
|
||||
@@ -38,23 +38,48 @@ public class UIInventory : ModuleUIPanel {
|
||||
}
|
||||
|
||||
/// <summary> UI项目 </summary>
|
||||
public class UIItem : ModuleUIItem<InventorySlot> {
|
||||
public class UIItem : ModuleUIItem<InventorySlot>, DragContainer {
|
||||
|
||||
public Label Count => Q<Label>("Count");
|
||||
public Label CountLabel => Q<Label>("Count");
|
||||
public VisualElement Image => Q<VisualElement>("Image");
|
||||
|
||||
public int Count => value.count;
|
||||
public DataItem Item => value.item;
|
||||
public VisualElement Anchor => element;
|
||||
|
||||
public UIItem(InventorySlot value, VisualElement element) : base(value, element) {
|
||||
Count.text = value.count.ToString();
|
||||
Count.EnableInClassList("inventory-count-hide", value.count <= 1);
|
||||
Image.style.backgroundImage = new StyleBackground(value.Sprite);
|
||||
UpdatePreview();
|
||||
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||
element.RegisterCallback<MouseOverEvent>(MouseOverEvent);
|
||||
element.RegisterCallback<MouseLeaveEvent>(MouseLeaveEvent);
|
||||
element.RegisterCallback<ClickEvent>(ClickEvent);
|
||||
}
|
||||
private void MouseDownEvent(MouseDownEvent evt) {
|
||||
UIPopupManager.I.dragItem.Open(value.item, value.count);
|
||||
UIPopupManager.I.dragItem.Settings(this);
|
||||
Image.EnableInClassList("inventory-image-drag", true);
|
||||
}
|
||||
private void MouseOverEvent(MouseOverEvent evt) {
|
||||
UIPopupManager.I.dragItem.EnterContainer(this);
|
||||
}
|
||||
private void MouseLeaveEvent(MouseLeaveEvent evt) {
|
||||
UIPopupManager.I.dragItem.ExitContainer(this);
|
||||
}
|
||||
private void ClickEvent(ClickEvent evt) {
|
||||
Debug.Log("sss");
|
||||
// Debug.Log("sss");
|
||||
}
|
||||
|
||||
public void Cancel() {
|
||||
Image.EnableInClassList("inventory-image-drag", false);
|
||||
}
|
||||
public void Exchange(DataItem item, int count) {
|
||||
value.Settings(item, count);
|
||||
UpdatePreview();
|
||||
}
|
||||
|
||||
private void UpdatePreview() {
|
||||
CountLabel.text = value.count.ToString();
|
||||
CountLabel.EnableInClassList("inventory-count-hide", value.count <= 1);
|
||||
Image.style.backgroundImage = new StyleBackground(value.Sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,37 +8,92 @@ using MuHua;
|
||||
/// UI拖拽物品
|
||||
/// </summary>
|
||||
public class UIDragItem : ModuleUIPanel, UIControl {
|
||||
/// <summary> 数量 </summary>
|
||||
private int count;
|
||||
/// <summary> 物品 </summary>
|
||||
private DataItem item;
|
||||
/// <summary> 画布 </summary>
|
||||
private VisualElement canvas;
|
||||
/// <summary> 是否启用 </summary>
|
||||
private bool isEnable;
|
||||
/// <summary> 鼠标位置 </summary>
|
||||
private Vector2 mousePosition;
|
||||
/// <summary> 偏移位置 </summary>
|
||||
private Vector2 offsetPosition;
|
||||
/// <summary> 物品容器 </summary>
|
||||
private DragContainer container;
|
||||
/// <summary> 目标容器 </summary>
|
||||
private DragContainer targetContainer;
|
||||
|
||||
|
||||
public Label Count => Q<Label>("Count");
|
||||
public VisualElement Image => Q<VisualElement>("Image");
|
||||
public VisualElement Preview => Q<VisualElement>("Preview");
|
||||
|
||||
public UIDragItem(VisualElement element, VisualElement canvas) : base(element) {
|
||||
this.canvas = canvas;
|
||||
ModuleUI.AddControl(this);
|
||||
canvas.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||
canvas.RegisterCallback<MouseMoveEvent>(FloatingFunc);
|
||||
}
|
||||
private void MouseUpEvent(MouseUpEvent evt) {
|
||||
if (!isEnable) { return; }
|
||||
isEnable = false;
|
||||
container?.Cancel();
|
||||
element.EnableInClassList("document-page-hide", !isEnable);
|
||||
if (container == null || targetContainer == null) { return; }
|
||||
int count = container.Count;
|
||||
DataItem item = container.Item;
|
||||
container.Exchange(targetContainer.Item, targetContainer.Count);
|
||||
targetContainer.Exchange(item, count);
|
||||
}
|
||||
private void FloatingFunc(MouseMoveEvent evt) {
|
||||
Preview.transform.position = evt.mousePosition;
|
||||
mousePosition = evt.mousePosition;
|
||||
}
|
||||
public void Update() {
|
||||
|
||||
Preview.transform.position = mousePosition + offsetPosition;
|
||||
// if (targetContainer == null) { return; }
|
||||
// Preview.transform.position = targetContainer.Anchor.worldBound.position;
|
||||
}
|
||||
public void Dispose() {
|
||||
// throw new System.NotImplementedException();
|
||||
canvas.UnregisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||
canvas.UnregisterCallback<MouseMoveEvent>(FloatingFunc);
|
||||
}
|
||||
|
||||
/// <summary> 打开菜单 </summary>
|
||||
public void Open(DataItem item, int count) {
|
||||
this.item = item;
|
||||
this.count = count;
|
||||
Count.text = count.ToString();
|
||||
Count.EnableInClassList("dragitem-count-hide", count <= 1);
|
||||
Image.style.backgroundImage = new StyleBackground(item.sprite);
|
||||
element.EnableInClassList("document-page-hide", item == null);
|
||||
/// <summary> 设置容器 </summary>
|
||||
public void Settings(DragContainer container) {
|
||||
this.container = container;
|
||||
|
||||
isEnable = container.Item != null;
|
||||
element.EnableInClassList("document-page-hide", !isEnable);
|
||||
if (isEnable) { UpdatePreview(); }
|
||||
}
|
||||
/// <summary> 进入容器 </summary>
|
||||
public void EnterContainer(DragContainer container) {
|
||||
targetContainer = container;
|
||||
}
|
||||
/// <summary> 退出容器 </summary>
|
||||
public void ExitContainer(DragContainer container) {
|
||||
if (targetContainer == container) { targetContainer = null; }
|
||||
}
|
||||
|
||||
private void UpdatePreview() {
|
||||
offsetPosition = container.Anchor.worldBound.position - mousePosition;
|
||||
|
||||
Count.text = container.Count.ToString();
|
||||
Count.EnableInClassList("dragitem-count-hide", container.Count <= 1);
|
||||
Image.style.backgroundImage = new StyleBackground(container.Item.sprite);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 项目拖拽
|
||||
/// </summary>
|
||||
public interface DragContainer {
|
||||
/// <summary> 数量 </summary>
|
||||
public int Count { get; }
|
||||
/// <summary> 物品 </summary>
|
||||
public DataItem Item { get; }
|
||||
/// <summary> 锚点 </summary>
|
||||
public VisualElement Anchor { get; }
|
||||
|
||||
/// <summary> 取消拖拽 </summary>
|
||||
public void Cancel();
|
||||
/// <summary> 交换物品 </summary>
|
||||
public void Exchange(DataItem item, int count);
|
||||
}
|
||||
Reference in New Issue
Block a user