1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 01e61c86999f6aa40aa7742bb891014e
|
guid: ca01e5dfb1bcb40409d89324b7b30e0c
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 48193b9c6d7c6af4088a00876ccaa1c3
|
guid: 6c3f4d86bebc21a459dcdb9549d00c17
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 9871787cca5a9e54fab450c7d3674d69
|
guid: 50ec3141d8da2214eacd8fcf7ea8428b
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7f7ce98abf5cf1242bcaf87f8e07e3f9
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fd9b18780ad93c44dbede85c81c63d25
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 66704a169cf4fd94cb18d2c1d132173a
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f79ff4ff8b66add4a8beda06e918ea16
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d59370b1224756a48aae056eac6abc05
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3196c223cc5a7014f8504b1056eb06b9
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !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: 45818eb64c9b04441b20b29f0230edb7, type: 3}
|
||||||
|
m_Name: "\u5355\u624B\u5251 1"
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
sprite: {fileID: 21300000, guid: 5fd50594014b70e48bd6993443d46b32, type: 3}
|
||||||
|
type: 0
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d1ab7394c601aff4797e854bd7be57f5
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !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: 45818eb64c9b04441b20b29f0230edb7, type: 3}
|
||||||
|
m_Name: "\u5355\u624B\u5251 2"
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
sprite: {fileID: 21300000, guid: 5fd50594014b70e48bd6993443d46b32, type: 3}
|
||||||
|
type: 0
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2155d31e917f2eb45a9f62174a1698ea
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 99034827463076243a095d6e0719166c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0f196c0732ec0114cb37de3ec74740d9
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 76925090c35dc5c4ca26c94995c00e71
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7854296aa2daf7d45a34980e33061b75
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -15,7 +15,7 @@ MonoBehaviour:
|
|||||||
type: 0
|
type: 0
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
minValue: 0
|
minValue: 0
|
||||||
maxValue: 3.4028235e+38
|
maxValue: 9999
|
||||||
container: {fileID: 11400000}
|
container: {fileID: 11400000}
|
||||||
--- !u!114 &-1377547097575584075
|
--- !u!114 &-1377547097575584075
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -32,7 +32,7 @@ MonoBehaviour:
|
|||||||
type: 0
|
type: 0
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
minValue: 0
|
minValue: 0
|
||||||
maxValue: 3.4028235e+38
|
maxValue: 9999
|
||||||
container: {fileID: 11400000}
|
container: {fileID: 11400000}
|
||||||
--- !u!114 &11400000
|
--- !u!114 &11400000
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 属性容器 - 自定义编辑器
|
||||||
|
/// </summary>
|
||||||
|
[CustomEditor(typeof(AttributeContainerConst))]
|
||||||
|
public class AttributeContainerConstEditor : ModuleUIEditor<AttributeContainerConst> {
|
||||||
|
|
||||||
|
public VisualTreeAsset AttributeTemplate = default;
|
||||||
|
|
||||||
|
private UIAttributeList attributeList;
|
||||||
|
|
||||||
|
public VisualElement AttributeList => Q<VisualElement>("AttributeList");
|
||||||
|
|
||||||
|
public override void Initial() {
|
||||||
|
attributeList = new UIAttributeList(AttributeList, AttributeTemplate);
|
||||||
|
attributeList.Initial(value.instances);
|
||||||
|
AddControl(attributeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public override void OnInspectorGUI() {
|
||||||
|
// base.OnInspectorGUI();
|
||||||
|
// if (GUILayout.Button("创建属性")) { GenerateAttribute(); }
|
||||||
|
// if (GUILayout.Button("删除属性")) { DeleteInstance(); }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// <summary> 创建属性实例 </summary>
|
||||||
|
// private void GenerateAttribute() {
|
||||||
|
// AttributeInstanceConst instance = CreateInstance<AttributeInstanceConst>();
|
||||||
|
// 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;) {
|
||||||
|
// AttributeInstanceConst instance = container.instances[i];
|
||||||
|
// container.instances.Remove(instance);
|
||||||
|
// Undo.DestroyObjectImmediate(instance);
|
||||||
|
// }
|
||||||
|
// EditorUtility.SetDirty(container);
|
||||||
|
// AssetDatabase.SaveAssets();
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8ae6bbae674e19448216fd6b41cd012
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences:
|
||||||
|
- VisualTreeAsset: {fileID: 9197481963319205126, guid: 95527f76fc8930d4ab47213114a5952b, type: 3}
|
||||||
|
- AttributeTemplate: {fileID: 9197481963319205126, guid: 1749a10e5ffdea045b442dfa323e4028, type: 3}
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 属性实例 - 自定义编辑器
|
||||||
|
/// </summary>
|
||||||
|
[CustomEditor(typeof(AttributeInstanceConst))]
|
||||||
|
public class AttributeInstanceConstEditor : Editor {
|
||||||
|
|
||||||
|
private AttributeInstanceConst instance;
|
||||||
|
|
||||||
|
private void Awake() => instance = target as AttributeInstanceConst;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
AttributeContainerConst container = instance.container;
|
||||||
|
container.instances.Remove(instance);
|
||||||
|
EditorUtility.SetDirty(container);
|
||||||
|
Undo.DestroyObjectImmediate(instance);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ce2626e82921eb14992661fc763dc7b5
|
guid: dbe28b450df84584cb523a09c813e59b
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 属性 - UI列表
|
||||||
|
/// </summary>
|
||||||
|
public class UIAttributeList : ModuleUIPanel, UIControl {
|
||||||
|
/// <summary> 拖拽预览 </summary>
|
||||||
|
public VisualElement preview;
|
||||||
|
/// <summary> 鼠标位置 </summary>
|
||||||
|
public Vector2 mousePosition;
|
||||||
|
/// <summary> 偏移位置 </summary>
|
||||||
|
public Vector2 offsetPosition;
|
||||||
|
/// <summary> 项目列表 </summary>
|
||||||
|
public ModuleUIItems<UIItem, AttributeInstanceConst> items;
|
||||||
|
|
||||||
|
public UIAttributeList(VisualElement element, VisualTreeAsset templateAsset) : base(element) {
|
||||||
|
items = new ModuleUIItems<UIItem, AttributeInstanceConst>(element, templateAsset,
|
||||||
|
(data, element) => new UIItem(data, element, this));
|
||||||
|
|
||||||
|
element.RegisterCallback<MouseMoveEvent>(FloatingFunc);
|
||||||
|
}
|
||||||
|
private void FloatingFunc(MouseMoveEvent evt) {
|
||||||
|
mousePosition = evt.mousePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update() {
|
||||||
|
if (preview == null) { return; }
|
||||||
|
preview.transform.position = mousePosition - offsetPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() => items.Release();
|
||||||
|
|
||||||
|
/// <summary> 初始化 </summary>
|
||||||
|
public void Initial(List<AttributeInstanceConst> list) {
|
||||||
|
items.Create(list);
|
||||||
|
}
|
||||||
|
/// <summary> 设置值 </summary>
|
||||||
|
// public void Settings(T value) => callback?.Invoke(value);
|
||||||
|
|
||||||
|
public void MouseDownEvent(VisualElement element) {
|
||||||
|
preview = element;
|
||||||
|
offsetPosition = mousePosition;
|
||||||
|
// Debug.Log($"{preview.worldBound.position} - {mousePosition}");
|
||||||
|
// offsetPosition = preview.worldBound.position - mousePosition;
|
||||||
|
// Debug.Log($"{preview.worldBound.position} = {mousePosition} + {offsetPosition}");
|
||||||
|
}
|
||||||
|
public void MouseUpEvent() {
|
||||||
|
if (preview == null) { return; }
|
||||||
|
preview.transform.position = Vector2.zero;
|
||||||
|
|
||||||
|
int insertIndex = GetInsertIndex(element, preview);
|
||||||
|
int oldIndex = element.IndexOf(preview);
|
||||||
|
|
||||||
|
// 修正插入索引
|
||||||
|
// if (insertIndex > oldIndex) insertIndex--;
|
||||||
|
Debug.Log($"插入位置 {insertIndex} - 旧位置 {oldIndex}");
|
||||||
|
// 重新排序UI和数据
|
||||||
|
if (oldIndex != insertIndex) { MovePreviewElement(oldIndex, insertIndex); }
|
||||||
|
preview = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取插入索引
|
||||||
|
/// </summary>
|
||||||
|
private int GetInsertIndex(VisualElement parent, VisualElement preview) {
|
||||||
|
Vector2 previewCenter = preview.worldBound.center;
|
||||||
|
int insertIndex = 0;
|
||||||
|
for (int i = 0; i < parent.childCount; i++) {
|
||||||
|
var child = parent[i];
|
||||||
|
if (child == preview) continue;
|
||||||
|
if (previewCenter.y < child.worldBound.center.y) {
|
||||||
|
insertIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
insertIndex = i + 1;
|
||||||
|
}
|
||||||
|
return insertIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移动预览元素到新位置
|
||||||
|
/// </summary>
|
||||||
|
private void MovePreviewElement(int oldIndex, int newIndex) {
|
||||||
|
VisualElement temp = element[oldIndex];
|
||||||
|
// element.RemoveAt(oldIndex);
|
||||||
|
element.Insert(newIndex, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> UI项 </summary>
|
||||||
|
public class UIItem : ModuleUIItem<AttributeInstanceConst> {
|
||||||
|
public readonly UIAttributeList parent;
|
||||||
|
|
||||||
|
public Label Range => Q<Label>("Range");
|
||||||
|
public TextField Name => Q<TextField>("Name");
|
||||||
|
public EnumField Type => Q<EnumField>("Type");
|
||||||
|
public FloatField Value => Q<FloatField>("Value");
|
||||||
|
|
||||||
|
public UIItem(AttributeInstanceConst value, VisualElement element, UIAttributeList parent) : base(value, element) {
|
||||||
|
this.parent = parent;
|
||||||
|
Name.SetValueWithoutNotify(value.name);
|
||||||
|
Type.Init(value.type);
|
||||||
|
Type.SetValueWithoutNotify(value.type);
|
||||||
|
Value.SetValueWithoutNotify(value.defaultValue);
|
||||||
|
Range.text = $"{value.minValue} ~ {value.maxValue}";
|
||||||
|
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||||
|
element.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||||
|
}
|
||||||
|
public override void DefaultState() {
|
||||||
|
// Button.EnableInClassList("button-s", false);
|
||||||
|
}
|
||||||
|
public override void SelectState() {
|
||||||
|
// parent.Settings(value);
|
||||||
|
// Button.EnableInClassList("button-s", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MouseDownEvent(MouseDownEvent evt) => parent.MouseDownEvent(element);
|
||||||
|
|
||||||
|
private void MouseUpEvent(MouseUpEvent evt) => parent.MouseUpEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: cc8dab09130da0a43bcd57ddecde2332
|
guid: 82adca68fa56cb14382ebd547a8bf044
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 51b8c6d3c0b5b3d459dca741e39b455e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+2
-2
@@ -6,10 +6,10 @@ using UnityEngine;
|
|||||||
/// 属性容器 - 常量
|
/// 属性容器 - 常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CreateAssetMenu(menuName = "MuHua/属性模块/属性容器")]
|
[CreateAssetMenu(menuName = "MuHua/属性模块/属性容器")]
|
||||||
public class ConstAttributeContainer : ScriptableObject {
|
public class AttributeContainerConst : ScriptableObject {
|
||||||
/// <summary> 属性列表 </summary>
|
/// <summary> 属性列表 </summary>
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public List<ConstAttributeInstance> instances;
|
public List<AttributeInstanceConst> instances;
|
||||||
|
|
||||||
/// <summary> 转换数据 </summary>
|
/// <summary> 转换数据 </summary>
|
||||||
public AttributeContainer To() {
|
public AttributeContainer To() {
|
||||||
+3
-3
@@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
/// 属性实例 - 常量
|
/// 属性实例 - 常量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CreateAssetMenu(menuName = "MuHua/属性模块/属性实例")]
|
[CreateAssetMenu(menuName = "MuHua/属性模块/属性实例")]
|
||||||
public class ConstAttributeInstance : ScriptableObject {
|
public class AttributeInstanceConst : ScriptableObject {
|
||||||
/// <summary> 属性类型 </summary>
|
/// <summary> 属性类型 </summary>
|
||||||
public AttributeType type;
|
public AttributeType type;
|
||||||
/// <summary> 默认值 </summary>
|
/// <summary> 默认值 </summary>
|
||||||
@@ -14,11 +14,11 @@ public class ConstAttributeInstance : ScriptableObject {
|
|||||||
/// <summary> 最小值 </summary>
|
/// <summary> 最小值 </summary>
|
||||||
public float minValue;
|
public float minValue;
|
||||||
/// <summary> 最大值 </summary>
|
/// <summary> 最大值 </summary>
|
||||||
public float maxValue = float.MaxValue;
|
public float maxValue = 9999;
|
||||||
|
|
||||||
/// <summary> 属性容器 </summary>
|
/// <summary> 属性容器 </summary>
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public ConstAttributeContainer container;
|
public AttributeContainerConst container;
|
||||||
|
|
||||||
/// <summary> 转换数据 </summary>
|
/// <summary> 转换数据 </summary>
|
||||||
public AttributeInstance To() {
|
public AttributeInstance To() {
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 535afb79004b58e43a958d46e4f3eb20
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 34e0f6e731b56d54db838c594430c73b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: e4abceb9650918a419c073e86d8fc3d6
|
guid: 6f6de86e3bf3ec348a2cfde1e36e77bd
|
||||||
ScriptedImporter:
|
ScriptedImporter:
|
||||||
internalIDToNameTable: []
|
internalIDToNameTable: []
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||||
|
<ui:Template name="AttributeTemplate" src="project://database/Assets/ModuleCore/ModuleAttribute/UI%20Toolkit/AttributeContainerConstEditor/AttributeTemplate.uxml?fileID=9197481963319205126&guid=1749a10e5ffdea045b442dfa323e4028&type=3#AttributeTemplate" />
|
||||||
|
<Style src="project://database/Assets/ModuleCore/ModuleAttribute/UI%20Toolkit/AttributeContainerConstEditor/AttributeContainerConstEditor.uss?fileID=7433441132597879392&guid=6f6de86e3bf3ec348a2cfde1e36e77bd&type=3#AttributeContainerConstEditor" />
|
||||||
|
<ui:VisualElement name="AttributeList" style="flex-grow: 1;">
|
||||||
|
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||||
|
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||||
|
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||||
|
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement name="ButtonGroup" style="flex-direction: row;">
|
||||||
|
<ui:Button text="创建属性" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Button1" style="margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px;" />
|
||||||
|
<ui:Button text="删除全部属性" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Button2" style="margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px;" />
|
||||||
|
<ui:VisualElement style="flex-grow: 1;" />
|
||||||
|
<ui:Button text="删除属性" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Button3" style="margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px;" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d23b67a16b48c2243aabe57056dbfbed
|
guid: 95527f76fc8930d4ab47213114a5952b
|
||||||
ScriptedImporter:
|
ScriptedImporter:
|
||||||
internalIDToNameTable: []
|
internalIDToNameTable: []
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||||
|
<Style src="project://database/Assets/ModuleCore/ModuleAttribute/UI%20Toolkit/AttributeContainerConstEditor/AttributeContainerConstEditor.uss?fileID=7433441132597879392&guid=6f6de86e3bf3ec348a2cfde1e36e77bd&type=3#AttributeContainerConstEditor" />
|
||||||
|
<ui:VisualElement style="flex-direction: row; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; background-color: rgb(51, 51, 51); margin-top: 1px; margin-right: 1px; margin-bottom: 1px; margin-left: 1px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;">
|
||||||
|
<ui:TextField picking-mode="Ignore" value="filler text" keyboard-type="Default" name="Name" style="margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; width: 100px;" />
|
||||||
|
<ui:EnumField type="UnityEngine.TextAlignment, UnityEngine.TextRenderingModule" value="Center" name="Type" style="margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px; width: 100px;" />
|
||||||
|
<ui:FloatField value="42.2" name="Value" style="flex-grow: 1; margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px;" />
|
||||||
|
<ui:Label tabindex="-1" text="0-9999" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Range" style="width: 100px; -unity-text-align: middle-center; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1749a10e5ffdea045b442dfa323e4028
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 装备 - 编辑窗口
|
||||||
|
/// </summary>
|
||||||
|
public class EquipmentWindow : ModuleUIEditorWindow {
|
||||||
|
|
||||||
|
public VisualTreeAsset ButtonTemplate = default;
|
||||||
|
|
||||||
|
private EquipmentType currentEquipmentType;
|
||||||
|
private UIEquipmentEnum<EquipmentType> equipmentType;
|
||||||
|
private UIEquipmentEnum<WeaponType> weaponType;
|
||||||
|
private UIEquipmentEnum<ArmorType> armorType;
|
||||||
|
private UIEquipmentEnum<AccessoryType> accessoryType;
|
||||||
|
private UIEquipmentList equipmentList;
|
||||||
|
|
||||||
|
public VisualElement VEEquipmentType => Q<VisualElement>("EquipmentType");
|
||||||
|
public VisualElement VEEquipmentExtendType => Q<VisualElement>("EquipmentExtendType");
|
||||||
|
public VisualElement EquipmentList => Q<VisualElement>("EquipmentList");
|
||||||
|
|
||||||
|
[MenuItem("Window/UI Toolkit/EquipmentWindow")]
|
||||||
|
public static void ShowWindow() {
|
||||||
|
EquipmentWindow wnd = GetWindow<EquipmentWindow>();
|
||||||
|
wnd.titleContent = new GUIContent("EquipmentWindow");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initial() {
|
||||||
|
equipmentType = new UIEquipmentEnum<EquipmentType>(VEEquipmentType, ButtonTemplate, SettingsEquipmentType);
|
||||||
|
weaponType = new UIEquipmentEnum<WeaponType>(VEEquipmentExtendType, ButtonTemplate, (value) => SettingsEquipmentType(value.ToString()));
|
||||||
|
armorType = new UIEquipmentEnum<ArmorType>(VEEquipmentExtendType, ButtonTemplate, (value) => SettingsEquipmentType(value.ToString()));
|
||||||
|
accessoryType = new UIEquipmentEnum<AccessoryType>(VEEquipmentExtendType, ButtonTemplate, (value) => SettingsEquipmentType(value.ToString()));
|
||||||
|
equipmentList = new UIEquipmentList(EquipmentList, rootVisualElement, ButtonTemplate, (value) => Debug.Log(value));
|
||||||
|
AddControl(equipmentList);
|
||||||
|
|
||||||
|
equipmentType.Initial();
|
||||||
|
}
|
||||||
|
public override void OnDestroy() {
|
||||||
|
base.OnDestroy();
|
||||||
|
equipmentType.Release();
|
||||||
|
weaponType.Release();
|
||||||
|
armorType.Release();
|
||||||
|
accessoryType.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 设置装备类型 </summary>
|
||||||
|
private void SettingsEquipmentType(EquipmentType type) {
|
||||||
|
currentEquipmentType = type;
|
||||||
|
if (type == EquipmentType.武器) { weaponType.Initial(); }
|
||||||
|
if (type == EquipmentType.护甲) { armorType.Initial(); }
|
||||||
|
if (type == EquipmentType.饰品) { accessoryType.Initial(); }
|
||||||
|
}
|
||||||
|
/// <summary> 设置装备类型 </summary>
|
||||||
|
private void SettingsEquipmentType(string type) {
|
||||||
|
string path = $"Assets/AssetsEquipment/ScriptableObject/{currentEquipmentType}/{type}";
|
||||||
|
EnsureDirectoryExists(path);
|
||||||
|
List<EquipmentConst> equipments = FindConstAssets<EquipmentConst>(path);
|
||||||
|
equipmentList.Initial(equipments);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 编辑器工具
|
||||||
|
/// <summary> 查找指定文件夹下的所有 T 类型的 ScriptableObject 资源 </summary>
|
||||||
|
public static List<T> FindConstAssets<T>(string folderPath) where T : ScriptableObject {
|
||||||
|
List<T> result = new List<T>();
|
||||||
|
string filter = $"t:{typeof(T).Name}";
|
||||||
|
string[] guids = AssetDatabase.FindAssets(filter, new[] { folderPath });
|
||||||
|
foreach (string guid in guids) {
|
||||||
|
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
||||||
|
if (asset != null) { result.Add(asset); }
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/// <summary> 确保目录存在 </summary>
|
||||||
|
public static void EnsureDirectoryExists(string path) {
|
||||||
|
if (!Directory.Exists(path)) { Directory.CreateDirectory(path); }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void CreateConstWeapon() {
|
||||||
|
// 创建一个新的 ConstWeapon 资源
|
||||||
|
var asset = ScriptableObject.CreateInstance<WeaponConst>();
|
||||||
|
string path = EditorUtility.SaveFilePanelInProject(
|
||||||
|
"保存 ConstWeapon",
|
||||||
|
"NewConstWeapon.asset",
|
||||||
|
"asset",
|
||||||
|
"请选择保存 ConstWeapon 的路径"
|
||||||
|
);
|
||||||
|
if (!string.IsNullOrEmpty(path)) {
|
||||||
|
AssetDatabase.CreateAsset(asset, path);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
EditorUtility.FocusProjectWindow();
|
||||||
|
Selection.activeObject = asset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ec99af1e55d08254f8089eba7fa65bcd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences:
|
||||||
|
- m_ViewDataDictionary: {instanceID: 0}
|
||||||
|
- VisualTreeAsset: {fileID: 9197481963319205126, guid: 866ca35095f42154d97c957787b91a83, type: 3}
|
||||||
|
- ButtonTemplate: {fileID: 9197481963319205126, guid: 72d39f3bc55f0a94196e83e8bfea1857, type: 3}
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fe6d086cc2b6beb4e8d9dfe9339270f5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 装备枚举
|
||||||
|
/// </summary>
|
||||||
|
public class UIEquipmentEnum<T> : ModuleUIPanel where T : Enum {
|
||||||
|
|
||||||
|
public Action<T> callback;
|
||||||
|
public ModuleUIItems<UIItem, T> items;
|
||||||
|
|
||||||
|
public UIEquipmentEnum(VisualElement element, VisualTreeAsset templateAsset, Action<T> callback) : base(element) {
|
||||||
|
this.callback = callback;
|
||||||
|
items = new ModuleUIItems<UIItem, T>(element, templateAsset,
|
||||||
|
(data, element) => new UIItem(data, element, this));
|
||||||
|
}
|
||||||
|
/// <summary> 释放资源 </summary>
|
||||||
|
public void Release() => items.Release();
|
||||||
|
|
||||||
|
/// <summary> 初始化 </summary>
|
||||||
|
public void Initial() {
|
||||||
|
items.Create(EnumToList());
|
||||||
|
items.SelectFirst();
|
||||||
|
}
|
||||||
|
/// <summary> 设置值 </summary>
|
||||||
|
public void Settings(T value) => callback?.Invoke(value);
|
||||||
|
|
||||||
|
private List<T> EnumToList() {
|
||||||
|
var list = new List<T>();
|
||||||
|
foreach (var name in Enum.GetValues(typeof(T))) { list.Add((T)name); }
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> UI项 </summary>
|
||||||
|
public class UIItem : ModuleUIItem<T> {
|
||||||
|
public readonly UIEquipmentEnum<T> parent;
|
||||||
|
|
||||||
|
public Button Button => Q<Button>("Button");
|
||||||
|
|
||||||
|
public UIItem(T value, VisualElement element, UIEquipmentEnum<T> parent) : base(value, element) {
|
||||||
|
this.parent = parent;
|
||||||
|
Button.text = value.ToString();
|
||||||
|
Button.clicked += Select;
|
||||||
|
}
|
||||||
|
public override void DefaultState() {
|
||||||
|
Button.EnableInClassList("button-s", false);
|
||||||
|
}
|
||||||
|
public override void SelectState() {
|
||||||
|
parent.Settings(value);
|
||||||
|
Button.EnableInClassList("button-s", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d8ae6bbae674e19448216fd6b41cd012
|
guid: 1a27a9357cd2dfb46b03783e745821ff
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 装备 - UI列表
|
||||||
|
/// </summary>
|
||||||
|
public class UIEquipmentList : ModuleUIPanel, UIControl {
|
||||||
|
|
||||||
|
public Action<EquipmentConst> callback;
|
||||||
|
public UIScrollViewListV<UIItem, EquipmentConst> items;
|
||||||
|
|
||||||
|
public VisualElement ScrollView => Q<VisualElement>("ScrollView");
|
||||||
|
|
||||||
|
public UIEquipmentList(VisualElement element, VisualElement canvas, VisualTreeAsset templateAsset, Action<EquipmentConst> callback) : base(element) {
|
||||||
|
this.callback = callback;
|
||||||
|
items = new UIScrollViewListV<UIItem, EquipmentConst>(ScrollView, canvas, templateAsset,
|
||||||
|
(data, element) => new UIItem(data, element, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update() => items.Update();
|
||||||
|
|
||||||
|
public void Dispose() => items.Dispose();
|
||||||
|
|
||||||
|
/// <summary> 初始化 </summary>
|
||||||
|
public void Initial(List<EquipmentConst> equipments) {
|
||||||
|
items.Create(equipments);
|
||||||
|
items.SelectFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 设置值 </summary>
|
||||||
|
public void Settings(EquipmentConst value) => callback?.Invoke(value);
|
||||||
|
|
||||||
|
/// <summary> UI项 </summary>
|
||||||
|
public class UIItem : ModuleUIItem<EquipmentConst> {
|
||||||
|
public readonly UIEquipmentList parent;
|
||||||
|
|
||||||
|
public Button Button => Q<Button>("Button");
|
||||||
|
|
||||||
|
public UIItem(EquipmentConst value, VisualElement element, UIEquipmentList parent) : base(value, element) {
|
||||||
|
this.parent = parent;
|
||||||
|
Button.text = value.name;
|
||||||
|
Button.clicked += Select;
|
||||||
|
}
|
||||||
|
public override void DefaultState() {
|
||||||
|
Button.EnableInClassList("button-s", false);
|
||||||
|
}
|
||||||
|
public override void SelectState() {
|
||||||
|
parent.Settings(value);
|
||||||
|
Button.EnableInClassList("button-s", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ea8d2198def9909448f54d619cfc65aa
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 武器 - 自定义编辑器
|
||||||
|
/// </summary>
|
||||||
|
[CustomEditor(typeof(WeaponConst))]
|
||||||
|
public class WeaponConstEditor : Editor {
|
||||||
|
public VisualTreeAsset ButtonTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 191c3d543ef38514a8845f693eb75de3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1eaf517ccfb649341aa59df1d7d437c2
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 饰品类型
|
||||||
|
/// </summary>
|
||||||
|
public enum AccessoryType {
|
||||||
|
项链 = 0,
|
||||||
|
戒指 = 1,
|
||||||
|
手镯 = 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5bc9afb170700e64a902cc2b868b8b04
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 护甲类型
|
||||||
|
/// </summary>
|
||||||
|
public enum ArmorType {
|
||||||
|
上衣 = 0,
|
||||||
|
头盔 = 1,
|
||||||
|
手套 = 2,
|
||||||
|
腰带 = 3,
|
||||||
|
鞋子 = 4
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3851fbd666690f247b52ab57af296c62
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插槽类型
|
||||||
|
/// </summary>
|
||||||
|
public enum EquipmentSlotType {
|
||||||
|
主手 = 0,
|
||||||
|
副手 = 1,
|
||||||
|
|
||||||
|
上衣 = 10,
|
||||||
|
头盔 = 11,
|
||||||
|
手套 = 12,
|
||||||
|
腰带 = 13,
|
||||||
|
鞋子 = 14,
|
||||||
|
|
||||||
|
项链 = 20,
|
||||||
|
戒指1 = 21,
|
||||||
|
戒指2 = 22,
|
||||||
|
手镯1 = 23,
|
||||||
|
手镯2 = 24
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d79bc5d78a1f1124093253ca1cd314f2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 装备类型
|
||||||
|
/// </summary>
|
||||||
|
public enum EquipmentType {
|
||||||
|
武器 = 0,
|
||||||
|
护甲 = 1,
|
||||||
|
饰品 = 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 505a2c6d7fed9924591dfcdccbe928c9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 武器类型
|
||||||
|
/// </summary>
|
||||||
|
public enum WeaponType {
|
||||||
|
单手 = 0,
|
||||||
|
副手 = 1,
|
||||||
|
双手 = 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d1d95d68b876be4c9d6fb7d25113dee
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fa01c7c9647ebd6468b17280d5065639
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1
-1
@@ -2,7 +2,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class ConstWeaponEditor : MonoBehaviour
|
public class Accessory : MonoBehaviour
|
||||||
{
|
{
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7cfcaecd119af2f48adf5a4649d88360
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Armor : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user