修改框架
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &-6358681353448287529
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e891e45f4230ee04d8d329520fd39cbc, type: 3}
|
||||||
|
m_Name: "\u653B\u51FB\u529B"
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
type: 0
|
||||||
|
defaultValue: 0
|
||||||
|
minValue: 0
|
||||||
|
maxValue: 3.4028235e+38
|
||||||
|
container: {fileID: 11400000}
|
||||||
|
--- !u!114 &-1377547097575584075
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e891e45f4230ee04d8d329520fd39cbc, type: 3}
|
||||||
|
m_Name: "\u653B\u51FB\u901F\u5EA6"
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
type: 0
|
||||||
|
defaultValue: 0
|
||||||
|
minValue: 0
|
||||||
|
maxValue: 3.4028235e+38
|
||||||
|
container: {fileID: 11400000}
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 23403840a9d12654f8f15c6188728498, type: 3}
|
||||||
|
m_Name: "\u5C5E\u6027\u5BB9\u5668"
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
instances:
|
||||||
|
- {fileID: -1377547097575584075}
|
||||||
|
- {fileID: -6358681353448287529}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 09e8991e4b5a20745a227d1bc138548a
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8a4ee71d02fa8cd40aceb7f62a6efd89
|
guid: 6a2d6badedf74af4a8e4faffb6130a48
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性容器
|
||||||
|
/// </summary>
|
||||||
|
public class AttributeContainer {
|
||||||
|
/// <summary> 属性字典 </summary>
|
||||||
|
public Dictionary<string, AttributeInstance> dictionary = new Dictionary<string, AttributeInstance>();
|
||||||
|
|
||||||
|
/// <summary> 添加属性 </summary>
|
||||||
|
public void AddInstance(string attributeID, AttributeInstance instance) {
|
||||||
|
if (dictionary.ContainsKey(attributeID)) { return; }
|
||||||
|
dictionary.Add(attributeID, instance);
|
||||||
|
}
|
||||||
|
/// <summary> 添加修改器 </summary>
|
||||||
|
public void AddModifier(string attributeID, AttributeModifier mod, bool isUpdate) {
|
||||||
|
if (!dictionary.ContainsKey(attributeID)) { return; }
|
||||||
|
dictionary[attributeID].AddModifier(mod, isUpdate);
|
||||||
|
}
|
||||||
|
/// <summary> 重新计算值 </summary>
|
||||||
|
public void RecalculateValue() {
|
||||||
|
foreach (var item in dictionary) { item.Value.RecalculateValue(); }
|
||||||
|
}
|
||||||
|
/// <summary> 循环属性集合 </summary>
|
||||||
|
public void ForEach(Action<string, AttributeInstance> action) {
|
||||||
|
foreach (var item in dictionary) { action?.Invoke(item.Key, item.Value); }
|
||||||
|
}
|
||||||
|
/// <summary> 查询值 </summary>
|
||||||
|
public float FindValue(string attributeID) {
|
||||||
|
if (!dictionary.ContainsKey(attributeID)) { return 0; }
|
||||||
|
return dictionary[attributeID].currentValue;
|
||||||
|
}
|
||||||
|
/// <summary> 查询修改器 </summary>
|
||||||
|
public List<AttributeModifier> FindModifier(string attributeID) {
|
||||||
|
if (!dictionary.ContainsKey(attributeID)) { return new(); }
|
||||||
|
return dictionary[attributeID].modifiers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 112a5ce9d53f8d2408d0f882a639982c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性实例
|
||||||
|
/// </summary>
|
||||||
|
public class AttributeInstance {
|
||||||
|
/// <summary> 属性名称 </summary>
|
||||||
|
public string name;
|
||||||
|
/// <summary> 基础值 </summary>
|
||||||
|
public float baseValue;
|
||||||
|
/// <summary> 当前值 </summary>
|
||||||
|
public float currentValue;
|
||||||
|
/// <summary> 附加值% </summary>
|
||||||
|
public float additionValue;
|
||||||
|
/// <summary> 最小值 </summary>
|
||||||
|
public float minValue;
|
||||||
|
/// <summary> 最大值 </summary>
|
||||||
|
public float maxValue = float.MaxValue;
|
||||||
|
/// <summary> 属性类型 </summary>
|
||||||
|
public AttributeType type;
|
||||||
|
/// <summary> 修改器列表 </summary>
|
||||||
|
public List<AttributeModifier> modifiers = new List<AttributeModifier>();
|
||||||
|
|
||||||
|
/// <summary> 添加修改器 </summary>
|
||||||
|
public void AddModifier(AttributeModifier mod, bool isUpdate) {
|
||||||
|
modifiers.Add(mod);
|
||||||
|
if (isUpdate) { RecalculateValue(); }
|
||||||
|
}
|
||||||
|
/// <summary> 添加修改器 </summary>
|
||||||
|
public void AddModifier(List<AttributeModifier> mods, bool isUpdate) {
|
||||||
|
modifiers.AddRange(mods);
|
||||||
|
if (isUpdate) { RecalculateValue(); }
|
||||||
|
}
|
||||||
|
/// <summary> 重新计算值 </summary>
|
||||||
|
public void RecalculateValue() {
|
||||||
|
currentValue = baseValue;
|
||||||
|
modifiers.ForEach(mod => currentValue = mod.Fixed(currentValue));
|
||||||
|
additionValue = 1;
|
||||||
|
modifiers.ForEach(mod => additionValue = mod.Addition(additionValue));
|
||||||
|
currentValue = currentValue * additionValue;
|
||||||
|
currentValue = Mathf.Clamp(currentValue, minValue, maxValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3552e7ce95869d341adbe3a4b2a98851
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性调整
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AttributeModifier {
|
||||||
|
/// <summary> 固定值 </summary>
|
||||||
|
public abstract float Fixed(float input);
|
||||||
|
/// <summary> 附加值% </summary>
|
||||||
|
public abstract float Addition(float input);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2a544851e744f1540b431f2506157f18
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性附加
|
||||||
|
/// </summary>
|
||||||
|
public class AttributeSystem : Module<AttributeSystem> {
|
||||||
|
/// <summary> 修改事件 </summary>
|
||||||
|
public static event Action<AttributeSystem> OnChange;
|
||||||
|
/// <summary> 附加字典 </summary>
|
||||||
|
public Dictionary<string, AttributeContainer> dictionary = new Dictionary<string, AttributeContainer>();
|
||||||
|
|
||||||
|
/// <summary> 应用修改 </summary>
|
||||||
|
public void Apply() => OnChange?.Invoke(this);
|
||||||
|
/// <summary> 添加容器 </summary>
|
||||||
|
public void AddInstance(string containerID, AttributeContainer container) {
|
||||||
|
if (dictionary.ContainsKey(containerID)) { return; }
|
||||||
|
dictionary.Add(containerID, container);
|
||||||
|
OnChange?.Invoke(this);
|
||||||
|
}
|
||||||
|
/// <summary> 添加修改器 </summary>
|
||||||
|
public void AddModifier(string containerID, string attributeID, AttributeModifier mod, bool isUpdate) {
|
||||||
|
if (!dictionary.ContainsKey(containerID)) { return; }
|
||||||
|
dictionary[containerID].AddModifier(attributeID, mod, isUpdate);
|
||||||
|
OnChange?.Invoke(this);
|
||||||
|
}
|
||||||
|
/// <summary> 重新计算值 </summary>
|
||||||
|
public void RecalculateValue() {
|
||||||
|
foreach (var item in dictionary) { item.Value.RecalculateValue(); }
|
||||||
|
}
|
||||||
|
/// <summary> 查询容器 </summary>
|
||||||
|
public AttributeContainer FindContainer(string containerID) {
|
||||||
|
if (!dictionary.ContainsKey(containerID)) { return new(); }
|
||||||
|
return dictionary[containerID];
|
||||||
|
}
|
||||||
|
/// <summary> 查询容器 </summary>
|
||||||
|
public bool TryContainer(string containerID, out AttributeContainer container) {
|
||||||
|
container = null;
|
||||||
|
if (!dictionary.ContainsKey(containerID)) { return false; }
|
||||||
|
container = dictionary[containerID];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 828a59f9caabfb340aa07273f42ccfa4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性类型
|
||||||
|
/// </summary>
|
||||||
|
public enum AttributeType {
|
||||||
|
/// <summary> 浮点数值 </summary>
|
||||||
|
Float,
|
||||||
|
/// <summary> 整数值 </summary>
|
||||||
|
Integer,
|
||||||
|
/// <summary> 布尔值 </summary>
|
||||||
|
Boolean,
|
||||||
|
/// <summary> 百分比值 </summary>
|
||||||
|
Percentage
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdb0856dce49d2a4cae5b351eed7ef48
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 681e43f413713dd46914cb6348821756
|
guid: 01e61c86999f6aa40aa7742bb891014e
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性容器 - 常量
|
||||||
|
/// </summary>
|
||||||
|
[CreateAssetMenu(menuName = "MuHua/属性模块/属性容器")]
|
||||||
|
public class ConstAttributeContainer : ScriptableObject {
|
||||||
|
/// <summary> 属性列表 </summary>
|
||||||
|
[HideInInspector]
|
||||||
|
public List<ConstAttributeInstance> instances;
|
||||||
|
|
||||||
|
/// <summary> 转换数据 </summary>
|
||||||
|
public AttributeContainer To() {
|
||||||
|
AttributeContainer container = new AttributeContainer();
|
||||||
|
instances.ForEach(obj => container.AddInstance(obj.name, obj.To()));
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 23403840a9d12654f8f15c6188728498
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性实例 - 常量
|
||||||
|
/// </summary>
|
||||||
|
[CreateAssetMenu(menuName = "MuHua/属性模块/属性实例")]
|
||||||
|
public class ConstAttributeInstance : ScriptableObject {
|
||||||
|
/// <summary> 属性类型 </summary>
|
||||||
|
public AttributeType type;
|
||||||
|
/// <summary> 默认值 </summary>
|
||||||
|
public float defaultValue;
|
||||||
|
/// <summary> 最小值 </summary>
|
||||||
|
public float minValue;
|
||||||
|
/// <summary> 最大值 </summary>
|
||||||
|
public float maxValue = float.MaxValue;
|
||||||
|
|
||||||
|
/// <summary> 属性容器 </summary>
|
||||||
|
[HideInInspector]
|
||||||
|
public ConstAttributeContainer container;
|
||||||
|
|
||||||
|
/// <summary> 转换数据 </summary>
|
||||||
|
public AttributeInstance To() {
|
||||||
|
AttributeInstance instance = new AttributeInstance();
|
||||||
|
instance.type = type;
|
||||||
|
instance.name = name;
|
||||||
|
instance.baseValue = defaultValue;
|
||||||
|
instance.currentValue = defaultValue;
|
||||||
|
instance.minValue = minValue;
|
||||||
|
instance.maxValue = maxValue;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e891e45f4230ee04d8d329520fd39cbc
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d96c081aa34edfb4d9197a0bfb23858c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性容器 - 自定义编辑器
|
||||||
|
/// </summary>
|
||||||
|
[CustomEditor(typeof(ConstAttributeContainer))]
|
||||||
|
public class ConstAttributeContainerEditor : Editor {
|
||||||
|
|
||||||
|
private ConstAttributeContainer container;
|
||||||
|
|
||||||
|
private void Awake() => container = target as ConstAttributeContainer;
|
||||||
|
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
if (GUILayout.Button("创建属性")) { GenerateAttribute(); }
|
||||||
|
if (GUILayout.Button("删除属性")) { DeleteInstance(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 创建属性实例 </summary>
|
||||||
|
private void GenerateAttribute() {
|
||||||
|
ConstAttributeInstance instance = CreateInstance<ConstAttributeInstance>();
|
||||||
|
instance.container = container;
|
||||||
|
// 加入容器
|
||||||
|
container.instances.Add(instance);
|
||||||
|
AssetDatabase.AddObjectToAsset(instance, container);
|
||||||
|
EditorUtility.SetDirty(instance);
|
||||||
|
EditorUtility.SetDirty(container);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
/// <summary> 删除全部实例 </summary>
|
||||||
|
private void DeleteInstance() {
|
||||||
|
for (int i = container.instances.Count; i-- > 0;) {
|
||||||
|
ConstAttributeInstance instance = container.instances[i];
|
||||||
|
container.instances.Remove(instance);
|
||||||
|
Undo.DestroyObjectImmediate(instance);
|
||||||
|
}
|
||||||
|
EditorUtility.SetDirty(container);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8ae6bbae674e19448216fd6b41cd012
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性实例 - 自定义编辑器
|
||||||
|
/// </summary>
|
||||||
|
[CustomEditor(typeof(ConstAttributeInstance))]
|
||||||
|
public class ConstAttributeInstanceEditor : Editor {
|
||||||
|
|
||||||
|
private ConstAttributeInstance instance;
|
||||||
|
|
||||||
|
private void Awake() => instance = target as ConstAttributeInstance;
|
||||||
|
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
if (instance.container == null) { return; }
|
||||||
|
EditorGUILayout.Space(20);
|
||||||
|
|
||||||
|
// 输入字段修改 name
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
string newName = EditorGUILayout.TextField("属性名称", instance.name);
|
||||||
|
if (EditorGUI.EndChangeCheck()) { ModifyName(newName); }
|
||||||
|
// 按钮功能
|
||||||
|
if (GUILayout.Button("删除属性")) { DeleteInstance(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 修改名字 </summary>
|
||||||
|
private void ModifyName(string newName) {
|
||||||
|
instance.name = newName;
|
||||||
|
Undo.RecordObject(instance, "修改属性名称");
|
||||||
|
EditorUtility.SetDirty(instance);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
/// <summary> 删除实例 </summary>
|
||||||
|
private void DeleteInstance() {
|
||||||
|
ConstAttributeContainer container = instance.container;
|
||||||
|
container.instances.Remove(instance);
|
||||||
|
EditorUtility.SetDirty(container);
|
||||||
|
Undo.DestroyObjectImmediate(instance);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1e2db82f02928494990b89396707863b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 51f470ac3872ca44f9c8d012857bda7b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+5
-3
@@ -3,9 +3,11 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 装备 - 物品
|
/// 装备
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataEquipment : DataItem {
|
public class Equipment : InventoryItem {
|
||||||
/// <summary> 装备类型 (类型1/类型2) </summary>
|
/// <summary> 装备类型 (类型1/类型2) </summary>
|
||||||
public string type;
|
public string type;
|
||||||
}
|
/// <summary> 词缀列表 </summary>
|
||||||
|
public List<EquipmentAffix> affixes = new List<EquipmentAffix>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 装备词缀
|
||||||
|
/// </summary>
|
||||||
|
public class EquipmentAffix {
|
||||||
|
/// <summary> 名字 </summary>
|
||||||
|
public string name;
|
||||||
|
/// <summary> 数值 </summary>
|
||||||
|
public float value;
|
||||||
|
/// <summary> 最大值 </summary>
|
||||||
|
public float minValue;
|
||||||
|
/// <summary> 最小值 </summary>
|
||||||
|
public float maxValue = float.MaxValue;
|
||||||
|
/// <summary> 属性类型 </summary>
|
||||||
|
public AttributeType attributeType;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9eb47618daf43564cbc94b780e6b03f0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 装备栏
|
||||||
|
/// </summary>
|
||||||
|
public class EquipmentColumn {
|
||||||
|
/// <summary> 插槽字典 </summary>
|
||||||
|
public Dictionary<string, EquipmentSlot> dictionary = new Dictionary<string, EquipmentSlot>();
|
||||||
|
|
||||||
|
/// <summary> 索引器 </summary>
|
||||||
|
public EquipmentSlot this[string key] => dictionary[key];
|
||||||
|
|
||||||
|
public EquipmentColumn() {
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.主手, VerifyWeapon));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.副手, VerifyDeputy));
|
||||||
|
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.上衣, (equipment) => VerifyCommon(equipment, ArmorType.上衣.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.头盔, (equipment) => VerifyCommon(equipment, ArmorType.头盔.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.手套, (equipment) => VerifyCommon(equipment, ArmorType.手套.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.腰带, (equipment) => VerifyCommon(equipment, ArmorType.腰带.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.鞋子, (equipment) => VerifyCommon(equipment, ArmorType.鞋子.ToString())));
|
||||||
|
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.项链, (equipment) => VerifyCommon(equipment, AccessoryType.项链.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.戒指1, (equipment) => VerifyCommon(equipment, AccessoryType.戒指.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.戒指2, (equipment) => VerifyCommon(equipment, AccessoryType.戒指.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.手镯1, (equipment) => VerifyCommon(equipment, AccessoryType.手镯.ToString())));
|
||||||
|
AddSlot(new EquipmentSlot(EquipmentSlotType.手镯2, (equipment) => VerifyCommon(equipment, AccessoryType.手镯.ToString())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsKey(string key) => dictionary.ContainsKey(key);
|
||||||
|
/// <summary> 添加插槽 </summary>
|
||||||
|
public void AddSlot(EquipmentSlot slot) => dictionary.Add(slot.name, slot);
|
||||||
|
|
||||||
|
/// <summary> 通用校验 </summary>
|
||||||
|
public static bool VerifyCommon(Equipment equipment, string type) {
|
||||||
|
string[] types = equipment.type.Split("/");
|
||||||
|
if (types[0] == type) { return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary> 主手校验 </summary>
|
||||||
|
public static bool VerifyWeapon(Equipment equipment) {
|
||||||
|
string[] type = equipment.type.Split("/");
|
||||||
|
if (type[0] == WeaponType.单手.ToString()) { return true; }
|
||||||
|
if (type[0] == WeaponType.双手.ToString()) { return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary> 副手校验 </summary>
|
||||||
|
public static bool VerifyDeputy(Equipment equipment) {
|
||||||
|
string[] type = equipment.type.Split("/");
|
||||||
|
if (type[0] == WeaponType.副手.ToString()) { return true; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插槽类型
|
||||||
|
/// </summary>
|
||||||
|
public enum EquipmentSlotType {
|
||||||
|
主手, 副手, 上衣, 项链,
|
||||||
|
头盔, 手套, 腰带, 鞋子,
|
||||||
|
戒指1, 戒指2, 手镯1, 手镯2
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 装备插槽
|
||||||
|
/// </summary>
|
||||||
|
public class EquipmentSlot {
|
||||||
|
/// <summary> 名字 </summary>
|
||||||
|
public string name;
|
||||||
|
/// <summary> 物品 </summary>
|
||||||
|
public Equipment item;
|
||||||
|
/// <summary> 装备验证 </summary>
|
||||||
|
public Func<Equipment, bool> verify;
|
||||||
|
|
||||||
|
public EquipmentSlot(EquipmentSlotType slot, Func<Equipment, bool> verify) {
|
||||||
|
name = slot.ToString();
|
||||||
|
this.verify = verify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 设置 </summary>
|
||||||
|
public void Settings(InventoryItem item) {
|
||||||
|
if (item is Equipment equipment) { this.item = equipment; }
|
||||||
|
else { this.item = null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f1d68199e9959734e85efd7a39d4d78c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e0cd838d2a0877c4780133f6dcb808f3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+8
-8
@@ -2,6 +2,12 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 饰品类型
|
||||||
|
/// </summary>
|
||||||
|
public enum AccessoryType {
|
||||||
|
戒指, 手镯, 项链
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 饰品 - 物品常量
|
/// 饰品 - 物品常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -10,17 +16,11 @@ public class ConstAccessory : ConstEquipment {
|
|||||||
/// <summary> 饰品类型 </summary>
|
/// <summary> 饰品类型 </summary>
|
||||||
public AccessoryType type;
|
public AccessoryType type;
|
||||||
|
|
||||||
public override DataItem To() {
|
public override InventoryItem To() {
|
||||||
DataEquipment item = new DataEquipment();
|
Equipment item = new Equipment();
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.sprite = sprite;
|
item.sprite = sprite;
|
||||||
item.type = type.ToString();
|
item.type = type.ToString();
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// 饰品类型
|
|
||||||
/// </summary>
|
|
||||||
public enum AccessoryType {
|
|
||||||
戒指, 手镯, 项链
|
|
||||||
}
|
|
||||||
+8
-8
@@ -2,6 +2,12 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 护甲类型
|
||||||
|
/// </summary>
|
||||||
|
public enum ArmorType {
|
||||||
|
上衣, 头盔, 手套, 腰带, 鞋子
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 护甲 - 物品常量
|
/// 护甲 - 物品常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -10,17 +16,11 @@ public class ConstArmor : ConstEquipment {
|
|||||||
/// <summary> 护甲类型 </summary>
|
/// <summary> 护甲类型 </summary>
|
||||||
public ArmorType type;
|
public ArmorType type;
|
||||||
|
|
||||||
public override DataItem To() {
|
public override InventoryItem To() {
|
||||||
DataEquipment item = new DataEquipment();
|
Equipment item = new Equipment();
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.sprite = sprite;
|
item.sprite = sprite;
|
||||||
item.type = type.ToString();
|
item.type = type.ToString();
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// 护甲类型
|
|
||||||
/// </summary>
|
|
||||||
public enum ArmorType {
|
|
||||||
上衣, 头盔, 手套, 腰带, 鞋子
|
|
||||||
}
|
|
||||||
+1
-1
@@ -5,6 +5,6 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 装备 - 物品常量
|
/// 装备 - 物品常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConstEquipment : ConstItem {
|
public class ConstEquipment : ConstInventoryItem {
|
||||||
|
|
||||||
}
|
}
|
||||||
+8
-8
@@ -2,6 +2,12 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 武器类型
|
||||||
|
/// </summary>
|
||||||
|
public enum WeaponType {
|
||||||
|
单手, 副手, 双手
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 武器 - 物品常量
|
/// 武器 - 物品常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -10,17 +16,11 @@ public class ConstWeapon : ConstEquipment {
|
|||||||
/// <summary> 武器类型 </summary>
|
/// <summary> 武器类型 </summary>
|
||||||
public WeaponType type;
|
public WeaponType type;
|
||||||
|
|
||||||
public override DataItem To() {
|
public override InventoryItem To() {
|
||||||
DataEquipment item = new DataEquipment();
|
Equipment item = new Equipment();
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.sprite = sprite;
|
item.sprite = sprite;
|
||||||
item.type = type.ToString();
|
item.type = type.ToString();
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// 武器类型
|
|
||||||
/// </summary>
|
|
||||||
public enum WeaponType {
|
|
||||||
单手, 副手, 双手
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f49fabc8e03afc44bb1b5ea3fca16255
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ConstWeaponEditor : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b2c69e4ee377a7f48934adc2c8d6359f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ce2626e82921eb14992661fc763dc7b5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI装备栏
|
||||||
|
/// </summary>
|
||||||
|
public class UIEquipmentColumn : ModuleUIPanel {
|
||||||
|
|
||||||
|
public EquipmentColumn equipment;
|
||||||
|
/// <summary> 插槽字典 </summary>
|
||||||
|
public Dictionary<string, UIEquipmentSlot> dictionary = new Dictionary<string, UIEquipmentSlot>();
|
||||||
|
|
||||||
|
public UIEquipmentColumn(VisualElement element) : base(element) {
|
||||||
|
InitialSlot(1, EquipmentSlotType.主手);
|
||||||
|
InitialSlot(2, EquipmentSlotType.副手);
|
||||||
|
InitialSlot(3, EquipmentSlotType.上衣);
|
||||||
|
InitialSlot(4, EquipmentSlotType.项链);
|
||||||
|
|
||||||
|
InitialSlot(5, EquipmentSlotType.戒指1);
|
||||||
|
InitialSlot(6, EquipmentSlotType.戒指2);
|
||||||
|
InitialSlot(7, EquipmentSlotType.手镯1);
|
||||||
|
InitialSlot(8, EquipmentSlotType.手镯2);
|
||||||
|
|
||||||
|
InitialSlot(9, EquipmentSlotType.头盔);
|
||||||
|
InitialSlot(10, EquipmentSlotType.手套);
|
||||||
|
InitialSlot(11, EquipmentSlotType.腰带);
|
||||||
|
InitialSlot(12, EquipmentSlotType.鞋子);
|
||||||
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Settings(EquipmentColumn equipment) {
|
||||||
|
if (this.equipment != null) { Dispose(); }
|
||||||
|
this.equipment = equipment;
|
||||||
|
if (equipment == null) { return; }
|
||||||
|
foreach (var item in dictionary) { Settings(item.Key, item.Value); }
|
||||||
|
}
|
||||||
|
public void Settings(string key, UIEquipmentSlot uISlot) {
|
||||||
|
if (!equipment.ContainsKey(key)) { return; }
|
||||||
|
EquipmentSlot slot = equipment[key];
|
||||||
|
uISlot.Settings(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitialSlot(int index, EquipmentSlotType type) {
|
||||||
|
VisualElement element = Q<VisualElement>($"EquipmentSlot{index}");
|
||||||
|
UIEquipmentSlot uiSlot = new UIEquipmentSlot(element);
|
||||||
|
dictionary.Add(type.ToString(), uiSlot);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI装备插槽
|
||||||
|
/// </summary>
|
||||||
|
public class UIEquipmentSlot : ModuleUIPanel, InventoryDrag {
|
||||||
|
|
||||||
|
public EquipmentSlot value;
|
||||||
|
|
||||||
|
public Label CountLabel => Q<Label>("Count");
|
||||||
|
public VisualElement Image => Q<VisualElement>("Image");
|
||||||
|
|
||||||
|
public int Count => 1;
|
||||||
|
public InventoryItem Item => value.item;
|
||||||
|
public VisualElement Anchor => element;
|
||||||
|
|
||||||
|
public UIEquipmentSlot(VisualElement element) : base(element) {
|
||||||
|
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||||
|
element.RegisterCallback<MouseOverEvent>(MouseOverEvent);
|
||||||
|
element.RegisterCallback<MouseLeaveEvent>(MouseLeaveEvent);
|
||||||
|
element.RegisterCallback<ClickEvent>(ClickEvent);
|
||||||
|
}
|
||||||
|
private void MouseDownEvent(MouseDownEvent evt) {
|
||||||
|
UIPopupManager.I.inventoryDrag.Settings(this);
|
||||||
|
Image.EnableInClassList("equipment-image-drag", true);
|
||||||
|
}
|
||||||
|
private void MouseOverEvent(MouseOverEvent evt) {
|
||||||
|
if (!Verify()) { return; }
|
||||||
|
UIPopupManager.I.inventoryDrag.EnterContainer(this);
|
||||||
|
}
|
||||||
|
private void MouseLeaveEvent(MouseLeaveEvent evt) {
|
||||||
|
UIPopupManager.I.inventoryDrag.ExitContainer(this);
|
||||||
|
}
|
||||||
|
private void ClickEvent(ClickEvent evt) {
|
||||||
|
// Debug.Log("sss");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Settings(EquipmentSlot value) {
|
||||||
|
this.value = value;
|
||||||
|
UpdatePreview();
|
||||||
|
}
|
||||||
|
public void Settings(InventoryItem item, int count) {
|
||||||
|
value.Settings(item);
|
||||||
|
UpdatePreview();
|
||||||
|
}
|
||||||
|
public void Cancel() {
|
||||||
|
Image.EnableInClassList("equipment-image-drag", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePreview() {
|
||||||
|
Sprite sprite = value == null || value.item == null ? null : value.item.sprite;
|
||||||
|
Image.style.backgroundImage = new StyleBackground(sprite);
|
||||||
|
}
|
||||||
|
private bool Verify() {
|
||||||
|
InventoryDrag container = UIPopupManager.I.inventoryDrag.container;
|
||||||
|
if (container == null) { return false; }
|
||||||
|
if (container.Item is Equipment equipment) { return value.verify.Invoke(equipment); }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 99dc774aaeb03bc44b6607bd012c0e6e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ccf9ef6e831628349a83b354e196e98d
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 材料 - 物品
|
/// 材料 - 物品
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataMaterial : DataItem {
|
public class DataMaterial : InventoryItem {
|
||||||
/// <summary> 最大堆叠数 </summary>
|
/// <summary> 最大堆叠数 </summary>
|
||||||
public int maxStack;
|
public int maxStack;
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9871787cca5a9e54fab450c7d3674d69
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+2
-2
@@ -6,11 +6,11 @@ using UnityEngine;
|
|||||||
/// 材料 - 物品常量
|
/// 材料 - 物品常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CreateAssetMenu(menuName = "MuHua/物品系统/材料")]
|
[CreateAssetMenu(menuName = "MuHua/物品系统/材料")]
|
||||||
public class ConstMaterial : ConstItem {
|
public class ConstMaterial : ConstInventoryItem {
|
||||||
/// <summary> 最大堆叠数 </summary>
|
/// <summary> 最大堆叠数 </summary>
|
||||||
public int maxStack = 99;
|
public int maxStack = 99;
|
||||||
|
|
||||||
public override DataItem To() {
|
public override InventoryItem To() {
|
||||||
DataMaterial item = new DataMaterial();
|
DataMaterial item = new DataMaterial();
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.sprite = sprite;
|
item.sprite = sprite;
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
using System;
|
|
||||||
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];
|
|
||||||
|
|
||||||
public bool ContainsKey(string key) => dictionary.ContainsKey(key);
|
|
||||||
/// <summary> 添加插槽 </summary>
|
|
||||||
public void AddSlot(EquipmentSlot slot) => dictionary.Add(slot.name, slot);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 插槽类型
|
|
||||||
/// </summary>
|
|
||||||
public enum SlotType {
|
|
||||||
库存, 主手, 副手, 上衣, 头盔, 手套, 腰带, 鞋子, 项链, 戒指1, 戒指2, 手镯1, 手镯2
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public abstract class EquipmentSlot {
|
|
||||||
/// <summary> 名字 </summary>
|
|
||||||
public string name;
|
|
||||||
/// <summary> 物品 </summary>
|
|
||||||
public DataEquipment item;
|
|
||||||
|
|
||||||
public EquipmentSlot(SlotType slot) => name = slot.ToString();
|
|
||||||
|
|
||||||
/// <summary> 设置 </summary>
|
|
||||||
public void Settings(DataItem item, int count) {
|
|
||||||
if (item is DataEquipment equipment) { this.item = equipment; }
|
|
||||||
else { this.item = null; }
|
|
||||||
}
|
|
||||||
public abstract bool Verify(DataEquipment equipment);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 武器 - 装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public class WeaponSlot : EquipmentSlot {
|
|
||||||
/// <summary> 副手插槽 </summary>
|
|
||||||
public DeputySlot deputy;
|
|
||||||
|
|
||||||
public WeaponSlot(SlotType slot) : base(slot) { }
|
|
||||||
|
|
||||||
public override bool Verify(DataEquipment equipment) {
|
|
||||||
string[] type = equipment.type.Split("/");
|
|
||||||
if (type[0] == WeaponType.单手.ToString()) { return true; }
|
|
||||||
if (type[0] == WeaponType.双手.ToString()) { return true; }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 副手 - 装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public class DeputySlot : EquipmentSlot {
|
|
||||||
/// <summary> 主手插槽 </summary>
|
|
||||||
public WeaponSlot weapon;
|
|
||||||
|
|
||||||
public DeputySlot(SlotType slot) : base(slot) { }
|
|
||||||
|
|
||||||
public override bool Verify(DataEquipment equipment) {
|
|
||||||
string[] type = equipment.type.Split("/");
|
|
||||||
if (type[0] == WeaponType.副手.ToString()) { return true; }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 护甲 - 装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public class ArmorSlot : EquipmentSlot {
|
|
||||||
/// <summary> 护甲类型 </summary>
|
|
||||||
public string armorType;
|
|
||||||
|
|
||||||
public ArmorSlot(SlotType slot, ArmorType armor) : base(slot) => armorType = armor.ToString();
|
|
||||||
|
|
||||||
public override bool Verify(DataEquipment equipment) {
|
|
||||||
string[] type = equipment.type.Split("/");
|
|
||||||
if (type[0] == armorType) { return true; }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 饰品 - 装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public class AccessorySlot : EquipmentSlot {
|
|
||||||
/// <summary> 饰品类型 </summary>
|
|
||||||
public string accessoryType;
|
|
||||||
|
|
||||||
public AccessorySlot(SlotType slot, AccessoryType accessory) : base(slot) => accessoryType = accessory.ToString();
|
|
||||||
|
|
||||||
public override bool Verify(DataEquipment equipment) {
|
|
||||||
string[] type = equipment.type.Split("/");
|
|
||||||
if (type[0] == accessoryType) { return true; }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ public class Inventory {
|
|||||||
public void ForEach(Action<InventorySlot> action) => slots.ForEach(action);
|
public void ForEach(Action<InventorySlot> action) => slots.ForEach(action);
|
||||||
|
|
||||||
/// <summary> 添加物品 </summary>
|
/// <summary> 添加物品 </summary>
|
||||||
public void AddItem(DataItem item, int count) {
|
public void AddItem(InventoryItem item, int count) {
|
||||||
int remain = MergeToSlots(item, count);
|
int remain = MergeToSlots(item, count);
|
||||||
// 如果还有剩余,按照MaxStack分批放入空位
|
// 如果还有剩余,按照MaxStack分批放入空位
|
||||||
if (remain > 0) { AddToSlots(item, remain, true); }
|
if (remain > 0) { AddToSlots(item, remain, true); }
|
||||||
@@ -36,13 +36,13 @@ public class Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 添加物品 </summary>
|
/// <summary> 添加物品 </summary>
|
||||||
public void AddToSlots(DataItem item, int count, bool isWhile) {
|
public void AddToSlots(InventoryItem item, int count, bool isWhile) {
|
||||||
(bool isComplete, int remain) = AddToSlots(item, count);
|
(bool isComplete, int remain) = AddToSlots(item, count);
|
||||||
if (!isComplete || remain == 0 || !isWhile) { return; }
|
if (!isComplete || remain == 0 || !isWhile) { return; }
|
||||||
AddToSlots(item, remain, isWhile);
|
AddToSlots(item, remain, isWhile);
|
||||||
}
|
}
|
||||||
/// <summary> 添加到插槽 bool = 是否添加成功,int = 余量 </summary>
|
/// <summary> 添加到插槽 bool = 是否添加成功,int = 余量 </summary>
|
||||||
public (bool, int) AddToSlots(DataItem item, int count) {
|
public (bool, int) AddToSlots(InventoryItem item, int count) {
|
||||||
InventorySlot emptySlot = slots.FirstOrDefault(s => s.item == null);
|
InventorySlot emptySlot = slots.FirstOrDefault(s => s.item == null);
|
||||||
if (emptySlot == null) { return (false, count); }
|
if (emptySlot == null) { return (false, count); }
|
||||||
int addCount = Mathf.Min(count, item.MaxStack);
|
int addCount = Mathf.Min(count, item.MaxStack);
|
||||||
@@ -51,7 +51,7 @@ public class Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 合并到插槽 </summary>
|
/// <summary> 合并到插槽 </summary>
|
||||||
public int MergeToSlots(DataItem item, int count) {
|
public int MergeToSlots(InventoryItem item, int count) {
|
||||||
// 查询所有可合并的插槽
|
// 查询所有可合并的插槽
|
||||||
List<InventorySlot> sameSlots = slots.Where(slot => slot.Same(item)).ToList();
|
List<InventorySlot> sameSlots = slots.Where(slot => slot.Same(item)).ToList();
|
||||||
// 合并到已有插槽
|
// 合并到已有插槽
|
||||||
@@ -66,33 +66,3 @@ public class Inventory {
|
|||||||
count -= addCount;
|
count -= addCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// 库存插槽
|
|
||||||
/// </summary>
|
|
||||||
public class InventorySlot {
|
|
||||||
/// <summary> 数量 </summary>
|
|
||||||
public int count;
|
|
||||||
/// <summary> 物品 </summary>
|
|
||||||
public DataItem item;
|
|
||||||
|
|
||||||
// /// <summary> 图片 </summary>
|
|
||||||
public Sprite Sprite => item != null ? item.sprite : null;
|
|
||||||
// /// <summary> 堆叠数量 </summary>
|
|
||||||
public int MaxStack => item != null ? item.MaxStack : 0;
|
|
||||||
|
|
||||||
public InventorySlot() { }
|
|
||||||
|
|
||||||
public InventorySlot(DataItem item, int count) {
|
|
||||||
this.item = item;
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
/// <summary> 设置 </summary>
|
|
||||||
public void Settings(DataItem item, int count) {
|
|
||||||
this.item = item;
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
/// <summary> 是否相同 </summary>
|
|
||||||
public bool Same(DataItem obj) {
|
|
||||||
return item != null && item.name == obj.name && count < MaxStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 项目拖拽
|
||||||
|
/// </summary>
|
||||||
|
public interface InventoryDrag {
|
||||||
|
/// <summary> 数量 </summary>
|
||||||
|
public int Count { get; }
|
||||||
|
/// <summary> 物品 </summary>
|
||||||
|
public InventoryItem Item { get; }
|
||||||
|
/// <summary> 锚点 </summary>
|
||||||
|
public VisualElement Anchor { get; }
|
||||||
|
|
||||||
|
/// <summary> 取消拖拽 </summary>
|
||||||
|
public void Cancel();
|
||||||
|
/// <summary> 设置物品 </summary>
|
||||||
|
public void Settings(InventoryItem item, int count);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cc8dab09130da0a43bcd57ddecde2332
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 物品
|
/// 物品
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataItem {
|
public class InventoryItem {
|
||||||
/// <summary> 名字 </summary>
|
/// <summary> 名字 </summary>
|
||||||
public string name;
|
public string name;
|
||||||
/// <summary> 图片 </summary>
|
/// <summary> 图片 </summary>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 库存插槽
|
||||||
|
/// </summary>
|
||||||
|
public class InventorySlot {
|
||||||
|
/// <summary> 数量 </summary>
|
||||||
|
public int count;
|
||||||
|
/// <summary> 物品 </summary>
|
||||||
|
public InventoryItem item;
|
||||||
|
|
||||||
|
// /// <summary> 图片 </summary>
|
||||||
|
public Sprite Sprite => item != null ? item.sprite : null;
|
||||||
|
// /// <summary> 堆叠数量 </summary>
|
||||||
|
public int MaxStack => item != null ? item.MaxStack : 0;
|
||||||
|
|
||||||
|
public InventorySlot() { }
|
||||||
|
|
||||||
|
public InventorySlot(InventoryItem item, int count) {
|
||||||
|
this.item = item;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
/// <summary> 设置 </summary>
|
||||||
|
public void Settings(InventoryItem item, int count) {
|
||||||
|
this.item = item;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
/// <summary> 是否相同 </summary>
|
||||||
|
public bool Same(InventoryItem obj) {
|
||||||
|
return item != null && item.name == obj.name && count < MaxStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ddb28431ab55e034386cfe8f66c0d9f5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 9871787cca5a9e54fab450c7d3674d69
|
guid: 48193b9c6d7c6af4088a00876ccaa1c3
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
|
|||||||
+3
-3
@@ -6,13 +6,13 @@ using UnityEngine;
|
|||||||
/// 物品 - 常量
|
/// 物品 - 常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CreateAssetMenu(menuName = "MuHua/物品系统/物品")]
|
[CreateAssetMenu(menuName = "MuHua/物品系统/物品")]
|
||||||
public class ConstItem : ScriptableObject {
|
public class ConstInventoryItem : ScriptableObject {
|
||||||
/// <summary> 图片 </summary>
|
/// <summary> 图片 </summary>
|
||||||
public Sprite sprite;
|
public Sprite sprite;
|
||||||
|
|
||||||
/// <summary> 数据转换 </summary>
|
/// <summary> 数据转换 </summary>
|
||||||
public virtual DataItem To() {
|
public virtual InventoryItem To() {
|
||||||
DataItem item = new DataItem();
|
InventoryItem item = new InventoryItem();
|
||||||
item.name = name;
|
item.name = name;
|
||||||
item.sprite = sprite;
|
item.sprite = sprite;
|
||||||
return item;
|
return item;
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
using MuHua;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UI装备栏
|
|
||||||
/// </summary>
|
|
||||||
public class UIEquipment : ModuleUIPanel {
|
|
||||||
|
|
||||||
public Equipment equipment;
|
|
||||||
/// <summary> 插槽字典 </summary>
|
|
||||||
public Dictionary<string, UIEquipmentSlot> dictionary = new Dictionary<string, UIEquipmentSlot>();
|
|
||||||
|
|
||||||
public UIEquipment(VisualElement element) : base(element) {
|
|
||||||
InitialSlot(1, SlotType.主手);
|
|
||||||
InitialSlot(2, SlotType.副手);
|
|
||||||
InitialSlot(3, SlotType.上衣);
|
|
||||||
InitialSlot(4, SlotType.项链);
|
|
||||||
|
|
||||||
InitialSlot(4, SlotType.戒指1);
|
|
||||||
InitialSlot(4, SlotType.戒指2);
|
|
||||||
InitialSlot(4, SlotType.手镯1);
|
|
||||||
InitialSlot(4, SlotType.手镯2);
|
|
||||||
|
|
||||||
InitialSlot(4, SlotType.头盔);
|
|
||||||
InitialSlot(4, SlotType.手套);
|
|
||||||
InitialSlot(4, SlotType.腰带);
|
|
||||||
InitialSlot(4, SlotType.鞋子);
|
|
||||||
}
|
|
||||||
public void Dispose() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Settings(Equipment equipment) {
|
|
||||||
if (this.equipment != null) { Dispose(); }
|
|
||||||
this.equipment = equipment;
|
|
||||||
if (equipment == null) { return; }
|
|
||||||
foreach (var item in dictionary) {
|
|
||||||
if (!equipment.ContainsKey(item.Key)) { continue; }
|
|
||||||
EquipmentSlot slot = equipment[item.Key];
|
|
||||||
item.Value.Settings(slot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitialSlot(int index, SlotType type) {
|
|
||||||
VisualElement element = Q<VisualElement>($"EquipmentSlot{index}");
|
|
||||||
UIEquipmentSlot uiSlot = new UIEquipmentSlot(element);
|
|
||||||
dictionary.Add(type.ToString(), uiSlot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// UI装备插槽
|
|
||||||
/// </summary>
|
|
||||||
public class UIEquipmentSlot : ModuleUIPanel, DragContainer {
|
|
||||||
|
|
||||||
public EquipmentSlot value;
|
|
||||||
|
|
||||||
public Label CountLabel => Q<Label>("Count");
|
|
||||||
public VisualElement Image => Q<VisualElement>("Image");
|
|
||||||
|
|
||||||
public int Count => 1;
|
|
||||||
public DataItem Item => value.item;
|
|
||||||
public VisualElement Anchor => element;
|
|
||||||
|
|
||||||
public UIEquipmentSlot(VisualElement element) : base(element) {
|
|
||||||
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
|
||||||
element.RegisterCallback<MouseOverEvent>(MouseOverEvent);
|
|
||||||
element.RegisterCallback<MouseLeaveEvent>(MouseLeaveEvent);
|
|
||||||
element.RegisterCallback<ClickEvent>(ClickEvent);
|
|
||||||
}
|
|
||||||
private void MouseDownEvent(MouseDownEvent evt) {
|
|
||||||
UIPopupManager.I.dragItem.Settings(this);
|
|
||||||
Image.EnableInClassList("equipment-image-drag", true);
|
|
||||||
}
|
|
||||||
private void MouseOverEvent(MouseOverEvent evt) {
|
|
||||||
if (!Verify()) { return; }
|
|
||||||
UIPopupManager.I.dragItem.EnterContainer(this);
|
|
||||||
}
|
|
||||||
private void MouseLeaveEvent(MouseLeaveEvent evt) {
|
|
||||||
UIPopupManager.I.dragItem.ExitContainer(this);
|
|
||||||
}
|
|
||||||
private void ClickEvent(ClickEvent evt) {
|
|
||||||
// Debug.Log("sss");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Settings(EquipmentSlot value) {
|
|
||||||
this.value = value;
|
|
||||||
UpdatePreview();
|
|
||||||
}
|
|
||||||
public void Settings(DataItem item, int count) {
|
|
||||||
value.Settings(item, count);
|
|
||||||
UpdatePreview();
|
|
||||||
}
|
|
||||||
public void Cancel() {
|
|
||||||
Image.EnableInClassList("equipment-image-drag", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePreview() {
|
|
||||||
Sprite sprite = value == null || value.item == null ? null : value.item.sprite;
|
|
||||||
Image.style.backgroundImage = new StyleBackground(sprite);
|
|
||||||
}
|
|
||||||
private bool Verify() {
|
|
||||||
DragContainer container = UIPopupManager.I.dragItem.container;
|
|
||||||
if (container == null) { return false; }
|
|
||||||
if (container.Item is DataEquipment equipment) { return value.Verify(equipment); }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,50 +36,3 @@ public class UIInventory : ModuleUIPanel {
|
|||||||
items.Create(inventory.slots);
|
items.Create(inventory.slots);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// UI库存插槽
|
|
||||||
/// </summary>
|
|
||||||
public class UIInventorySlot : ModuleUIItem<InventorySlot>, DragContainer {
|
|
||||||
|
|
||||||
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 UIInventorySlot(InventorySlot value, VisualElement element) : base(value, element) {
|
|
||||||
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.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Settings(DataItem item, int count) {
|
|
||||||
value.Settings(item, count);
|
|
||||||
UpdatePreview();
|
|
||||||
}
|
|
||||||
public void Cancel() {
|
|
||||||
Image.EnableInClassList("inventory-image-drag", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePreview() {
|
|
||||||
CountLabel.text = value.count.ToString();
|
|
||||||
CountLabel.EnableInClassList("inventory-count-hide", value.count <= 1);
|
|
||||||
Image.style.backgroundImage = new StyleBackground(value.Sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+8
-24
@@ -7,7 +7,7 @@ using MuHua;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI拖拽物品
|
/// UI拖拽物品
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIDragItem : ModuleUIPanel, UIControl {
|
public class UIInventoryDrag : ModuleUIPanel, UIControl {
|
||||||
/// <summary> 画布 </summary>
|
/// <summary> 画布 </summary>
|
||||||
public VisualElement canvas;
|
public VisualElement canvas;
|
||||||
/// <summary> 是否启用 </summary>
|
/// <summary> 是否启用 </summary>
|
||||||
@@ -17,15 +17,15 @@ public class UIDragItem : ModuleUIPanel, UIControl {
|
|||||||
/// <summary> 偏移位置 </summary>
|
/// <summary> 偏移位置 </summary>
|
||||||
public Vector2 offsetPosition;
|
public Vector2 offsetPosition;
|
||||||
/// <summary> 物品容器 </summary>
|
/// <summary> 物品容器 </summary>
|
||||||
public DragContainer container;
|
public InventoryDrag container;
|
||||||
/// <summary> 目标容器 </summary>
|
/// <summary> 目标容器 </summary>
|
||||||
public DragContainer targetContainer;
|
public InventoryDrag targetContainer;
|
||||||
|
|
||||||
public Label Count => Q<Label>("Count");
|
public Label Count => Q<Label>("Count");
|
||||||
public VisualElement Image => Q<VisualElement>("Image");
|
public VisualElement Image => Q<VisualElement>("Image");
|
||||||
public VisualElement Preview => Q<VisualElement>("Preview");
|
public VisualElement Preview => Q<VisualElement>("Preview");
|
||||||
|
|
||||||
public UIDragItem(VisualElement element, VisualElement canvas) : base(element) {
|
public UIInventoryDrag(VisualElement element, VisualElement canvas) : base(element) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
ModuleUI.AddControl(this);
|
ModuleUI.AddControl(this);
|
||||||
canvas.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
canvas.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||||
@@ -39,7 +39,7 @@ public class UIDragItem : ModuleUIPanel, UIControl {
|
|||||||
// 交换物品
|
// 交换物品
|
||||||
if (container == null || targetContainer == null) { return; }
|
if (container == null || targetContainer == null) { return; }
|
||||||
int count = targetContainer.Count;
|
int count = targetContainer.Count;
|
||||||
DataItem item = targetContainer.Item;
|
InventoryItem item = targetContainer.Item;
|
||||||
targetContainer.Settings(container.Item, container.Count);
|
targetContainer.Settings(container.Item, container.Count);
|
||||||
container.Settings(item, count);
|
container.Settings(item, count);
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public class UIDragItem : ModuleUIPanel, UIControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 设置容器 </summary>
|
/// <summary> 设置容器 </summary>
|
||||||
public void Settings(DragContainer container) {
|
public void Settings(InventoryDrag container) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
isEnable = container.Item != null;
|
isEnable = container.Item != null;
|
||||||
@@ -65,11 +65,11 @@ public class UIDragItem : ModuleUIPanel, UIControl {
|
|||||||
if (isEnable) { UpdatePreview(); }
|
if (isEnable) { UpdatePreview(); }
|
||||||
}
|
}
|
||||||
/// <summary> 进入容器 </summary>
|
/// <summary> 进入容器 </summary>
|
||||||
public void EnterContainer(DragContainer container) {
|
public void EnterContainer(InventoryDrag container) {
|
||||||
targetContainer = container;
|
targetContainer = container;
|
||||||
}
|
}
|
||||||
/// <summary> 退出容器 </summary>
|
/// <summary> 退出容器 </summary>
|
||||||
public void ExitContainer(DragContainer container) {
|
public void ExitContainer(InventoryDrag container) {
|
||||||
if (targetContainer == container) { targetContainer = null; }
|
if (targetContainer == container) { targetContainer = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,19 +81,3 @@ public class UIDragItem : ModuleUIPanel, UIControl {
|
|||||||
Image.style.backgroundImage = new StyleBackground(container.Item.sprite);
|
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 Settings(DataItem item, int count);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI库存插槽
|
||||||
|
/// </summary>
|
||||||
|
public class UIInventorySlot : ModuleUIItem<InventorySlot>, InventoryDrag {
|
||||||
|
|
||||||
|
public Label CountLabel => Q<Label>("Count");
|
||||||
|
public VisualElement Image => Q<VisualElement>("Image");
|
||||||
|
|
||||||
|
public int Count => value.count;
|
||||||
|
public InventoryItem Item => value.item;
|
||||||
|
public VisualElement Anchor => element;
|
||||||
|
|
||||||
|
public UIInventorySlot(InventorySlot value, VisualElement element) : base(value, element) {
|
||||||
|
UpdatePreview();
|
||||||
|
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||||
|
element.RegisterCallback<MouseOverEvent>(MouseOverEvent);
|
||||||
|
element.RegisterCallback<MouseLeaveEvent>(MouseLeaveEvent);
|
||||||
|
element.RegisterCallback<ClickEvent>(ClickEvent);
|
||||||
|
}
|
||||||
|
private void MouseDownEvent(MouseDownEvent evt) {
|
||||||
|
UIPopupManager.I.inventoryDrag.Settings(this);
|
||||||
|
Image.EnableInClassList("inventory-image-drag", true);
|
||||||
|
}
|
||||||
|
private void MouseOverEvent(MouseOverEvent evt) {
|
||||||
|
UIPopupManager.I.inventoryDrag.EnterContainer(this);
|
||||||
|
}
|
||||||
|
private void MouseLeaveEvent(MouseLeaveEvent evt) {
|
||||||
|
UIPopupManager.I.inventoryDrag.ExitContainer(this);
|
||||||
|
}
|
||||||
|
private void ClickEvent(ClickEvent evt) {
|
||||||
|
// Debug.Log("sss");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Settings(InventoryItem item, int count) {
|
||||||
|
value.Settings(item, count);
|
||||||
|
UpdatePreview();
|
||||||
|
}
|
||||||
|
public void Cancel() {
|
||||||
|
Image.EnableInClassList("inventory-image-drag", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePreview() {
|
||||||
|
CountLabel.text = value.count.ToString();
|
||||||
|
CountLabel.EnableInClassList("inventory-count-hide", value.count <= 1);
|
||||||
|
Image.style.backgroundImage = new StyleBackground(value.Sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef816982615753c4c9d3ebcf38d51598
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -8,7 +8,7 @@ using MuHua;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AssetsManager : ModuleSingle<AssetsManager> {
|
public class AssetsManager : ModuleSingle<AssetsManager> {
|
||||||
|
|
||||||
public List<ConstItem> items;
|
public List<ConstInventoryItem> items;
|
||||||
|
|
||||||
protected override void Awake() => NoReplace(false);
|
protected override void Awake() => NoReplace(false);
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -20,14 +20,14 @@ public class ManagerItem : ModuleSingle<ManagerItem> {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ItemReward {
|
public class ItemReward {
|
||||||
/// <summary> 物品列表 </summary>
|
/// <summary> 物品列表 </summary>
|
||||||
public List<DataItem> items;
|
public List<InventoryItem> items;
|
||||||
|
|
||||||
public void Settings<T>(List<T> list) where T : ConstItem {
|
public void Settings<T>(List<T> list) where T : ConstInventoryItem {
|
||||||
items = new List<DataItem>();
|
items = new List<InventoryItem>();
|
||||||
list.ForEach(obj => items.Add(obj.To()));
|
list.ForEach(obj => items.Add(obj.To()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public (DataItem, int) Get(int max = 1) {
|
public (InventoryItem, int) Get(int max = 1) {
|
||||||
int count = Random.Range(1, max + 1);
|
int count = Random.Range(1, max + 1);
|
||||||
int index = Random.Range(0, items.Count);
|
int index = Random.Range(0, items.Count);
|
||||||
return (items[index], count);
|
return (items[index], count);
|
||||||
@@ -9,7 +9,7 @@ using MuHua;
|
|||||||
public class SingleManager : ModuleSingle<SingleManager> {
|
public class SingleManager : ModuleSingle<SingleManager> {
|
||||||
|
|
||||||
public Inventory inventory;
|
public Inventory inventory;
|
||||||
public Equipment equipment;
|
public EquipmentColumn equipment;
|
||||||
|
|
||||||
public ItemReward materialReward;
|
public ItemReward materialReward;
|
||||||
public ItemReward equipmentReward;
|
public ItemReward equipmentReward;
|
||||||
@@ -18,27 +18,7 @@ public class SingleManager : ModuleSingle<SingleManager> {
|
|||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
inventory = new Inventory(40);
|
inventory = new Inventory(40);
|
||||||
equipment = new Equipment();
|
equipment = new EquipmentColumn();
|
||||||
|
|
||||||
WeaponSlot weaponSlot = new WeaponSlot(SlotType.主手);
|
|
||||||
DeputySlot deputySlot = new DeputySlot(SlotType.副手);
|
|
||||||
weaponSlot.deputy = deputySlot;
|
|
||||||
deputySlot.weapon = weaponSlot;
|
|
||||||
|
|
||||||
equipment.AddSlot(weaponSlot);
|
|
||||||
equipment.AddSlot(deputySlot);
|
|
||||||
|
|
||||||
equipment.AddSlot(new ArmorSlot(SlotType.上衣, ArmorType.上衣));
|
|
||||||
equipment.AddSlot(new ArmorSlot(SlotType.头盔, ArmorType.头盔));
|
|
||||||
equipment.AddSlot(new ArmorSlot(SlotType.手套, ArmorType.手套));
|
|
||||||
equipment.AddSlot(new ArmorSlot(SlotType.腰带, ArmorType.腰带));
|
|
||||||
equipment.AddSlot(new ArmorSlot(SlotType.鞋子, ArmorType.鞋子));
|
|
||||||
|
|
||||||
equipment.AddSlot(new AccessorySlot(SlotType.项链, AccessoryType.项链));
|
|
||||||
equipment.AddSlot(new AccessorySlot(SlotType.戒指1, AccessoryType.戒指));
|
|
||||||
equipment.AddSlot(new AccessorySlot(SlotType.戒指2, AccessoryType.戒指));
|
|
||||||
equipment.AddSlot(new AccessorySlot(SlotType.手镯1, AccessoryType.手镯));
|
|
||||||
equipment.AddSlot(new AccessorySlot(SlotType.手镯2, AccessoryType.手镯));
|
|
||||||
|
|
||||||
materialReward = new ItemReward();
|
materialReward = new ItemReward();
|
||||||
materialReward.Settings(ManagerItem.I.materials);
|
materialReward.Settings(ManagerItem.I.materials);
|
||||||
@@ -53,11 +33,11 @@ public class SingleManager : ModuleSingle<SingleManager> {
|
|||||||
|
|
||||||
|
|
||||||
private void RewardMaterial() {
|
private void RewardMaterial() {
|
||||||
(DataItem item, int count) = materialReward.Get(10);
|
(InventoryItem item, int count) = materialReward.Get(10);
|
||||||
inventory.AddItem(item, count);
|
inventory.AddItem(item, count);
|
||||||
}
|
}
|
||||||
private void RewardEquipment() {
|
private void RewardEquipment() {
|
||||||
(DataItem item, int count) = equipmentReward.Get(1);
|
(InventoryItem item, int count) = equipmentReward.Get(1);
|
||||||
inventory.AddItem(item, count);
|
inventory.AddItem(item, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ using MuHua;
|
|||||||
public class UIBackpackPage : ModuleUIPage {
|
public class UIBackpackPage : ModuleUIPage {
|
||||||
public VisualTreeAsset inventorySlot;
|
public VisualTreeAsset inventorySlot;
|
||||||
|
|
||||||
private UIEquipment equipment;
|
|
||||||
private UIInventory inventory;
|
private UIInventory inventory;
|
||||||
|
private UIEquipmentColumn equipment;
|
||||||
|
|
||||||
public override VisualElement Element => root.Q<VisualElement>("BackpackPage");
|
public override VisualElement Element => root.Q<VisualElement>("BackpackPage");
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public class UIBackpackPage : ModuleUIPage {
|
|||||||
public VisualElement Inventory => Q<VisualElement>("Inventory");
|
public VisualElement Inventory => Q<VisualElement>("Inventory");
|
||||||
|
|
||||||
protected void Awake() {
|
protected void Awake() {
|
||||||
equipment = new UIEquipment(Equipment);
|
equipment = new UIEquipmentColumn(Equipment);
|
||||||
inventory = new UIInventory(Inventory, inventorySlot);
|
inventory = new UIInventory(Inventory, inventorySlot);
|
||||||
|
|
||||||
ModuleUI.OnJumpPage += ModuleUI_OnJumpPage;
|
ModuleUI.OnJumpPage += ModuleUI_OnJumpPage;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class UIPopupManager : ModuleUISingle<UIPopupManager> {
|
|||||||
/// <summary> 项目模板 </summary>
|
/// <summary> 项目模板 </summary>
|
||||||
public VisualTreeAsset itemTreeAsset;
|
public VisualTreeAsset itemTreeAsset;
|
||||||
|
|
||||||
public UIDragItem dragItem;
|
public UIInventoryDrag inventoryDrag;
|
||||||
public UIShortcutMenu shortcutMenu;
|
public UIShortcutMenu shortcutMenu;
|
||||||
|
|
||||||
public override VisualElement Element => root.Q<VisualElement>("Popup");
|
public override VisualElement Element => root.Q<VisualElement>("Popup");
|
||||||
@@ -23,7 +23,7 @@ public class UIPopupManager : ModuleUISingle<UIPopupManager> {
|
|||||||
|
|
||||||
protected override void Awake() {
|
protected override void Awake() {
|
||||||
NoReplace(false);
|
NoReplace(false);
|
||||||
dragItem = new UIDragItem(DragItem, root);
|
inventoryDrag = new UIInventoryDrag(DragItem, root);
|
||||||
shortcutMenu = new UIShortcutMenu(ShortcutMenu, menuTreeAsset, itemTreeAsset);
|
shortcutMenu = new UIShortcutMenu(ShortcutMenu, menuTreeAsset, itemTreeAsset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user