修改属性系统
This commit is contained in:
@@ -1,39 +1,5 @@
|
||||
%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: 9999
|
||||
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: 9999
|
||||
container: {fileID: 11400000}
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -44,8 +10,60 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 23403840a9d12654f8f15c6188728498, type: 3}
|
||||
m_Name: "\u5C5E\u6027\u5BB9\u5668"
|
||||
m_Name: "\u7269\u54C1\u5C5E\u6027"
|
||||
m_EditorClassIdentifier:
|
||||
instances:
|
||||
- {fileID: -1377547097575584075}
|
||||
- {fileID: -6358681353448287529}
|
||||
- {fileID: 6610366098165316818}
|
||||
- {fileID: 2362838488679916709}
|
||||
- {fileID: 4633682211995004289}
|
||||
--- !u!114 &2362838488679916709
|
||||
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: "\u9632\u5FA1"
|
||||
m_EditorClassIdentifier:
|
||||
type: 0
|
||||
defaultValue: 0
|
||||
minValue: 0
|
||||
maxValue: 9999
|
||||
container: {fileID: 11400000}
|
||||
--- !u!114 &4633682211995004289
|
||||
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: "\u9B54\u6CD5\u503C"
|
||||
m_EditorClassIdentifier:
|
||||
type: 3
|
||||
defaultValue: 0
|
||||
minValue: 0
|
||||
maxValue: 100
|
||||
container: {fileID: 11400000}
|
||||
--- !u!114 &6610366098165316818
|
||||
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"
|
||||
m_EditorClassIdentifier:
|
||||
type: 0
|
||||
defaultValue: 0
|
||||
minValue: 0
|
||||
maxValue: 9999
|
||||
container: {fileID: 11400000}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e8991e4b5a20745a227d1bc138548a
|
||||
guid: d07fad53a94189c42bcebe454bc4dde0
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
@@ -16,41 +16,38 @@ namespace MuHuaEditor {
|
||||
private UIAttributeList attributeList;
|
||||
|
||||
public VisualElement AttributeList => Q<VisualElement>("AttributeList");
|
||||
public Button Button1 => Q<Button>("Button1");// 创建属性
|
||||
public Button Button2 => Q<Button>("Button2");// 删除全部
|
||||
|
||||
public override void Initial() {
|
||||
attributeList = new UIAttributeList(AttributeList, AttributeTemplate);
|
||||
attributeList.Initial(value.instances);
|
||||
attributeList.Initial(value);
|
||||
AddControl(attributeList);
|
||||
|
||||
Button1.clicked += GenerateAttribute;
|
||||
Button2.clicked += DeleteInstance;
|
||||
}
|
||||
|
||||
|
||||
// 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();
|
||||
// }
|
||||
private void GenerateAttribute() {
|
||||
AttributeInstanceConst instance = CreateInstance<AttributeInstanceConst>();
|
||||
instance.container = value;
|
||||
// 加入容器
|
||||
value.instances.Add(instance);
|
||||
AssetDatabase.AddObjectToAsset(instance, value);
|
||||
EditorUtility.SetDirty(instance);
|
||||
EditorUtility.SetDirty(value);
|
||||
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();
|
||||
// }
|
||||
|
||||
private void DeleteInstance() {
|
||||
for (int i = value.instances.Count; i-- > 0;) {
|
||||
AttributeInstanceConst instance = value.instances[i];
|
||||
value.instances.Remove(instance);
|
||||
Undo.DestroyObjectImmediate(instance);
|
||||
}
|
||||
EditorUtility.SetDirty(value);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor;
|
||||
using MuHua;
|
||||
|
||||
namespace MuHuaEditor {
|
||||
/// <summary>
|
||||
/// 属性实例 - 自定义编辑器
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(AttributeInstanceConst))]
|
||||
public class AttributeInstanceConstEditor : Editor {
|
||||
public class AttributeInstanceConstEditor : ModuleUIEditor<AttributeInstanceConst> {
|
||||
|
||||
private AttributeInstanceConst instance;
|
||||
public UIAttributePanel attributePanel;
|
||||
|
||||
private void Awake() => instance = target as AttributeInstanceConst;
|
||||
public VisualElement AttributePanel => Q<VisualElement>("AttributePanel");
|
||||
public FloatField Min => Q<FloatField>("Min");
|
||||
public FloatField Max => Q<FloatField>("Max");
|
||||
public Button button => Q<Button>("Button");
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
base.OnInspectorGUI();
|
||||
if (instance.container == null) { return; }
|
||||
EditorGUILayout.Space(20);
|
||||
public override void Initial() {
|
||||
attributePanel = new UIAttributePanel(value, AttributePanel);
|
||||
|
||||
// 输入字段修改 name
|
||||
EditorGUI.BeginChangeCheck();
|
||||
string newName = EditorGUILayout.TextField("属性名称", instance.name);
|
||||
if (EditorGUI.EndChangeCheck()) { ModifyName(newName); }
|
||||
// 按钮功能
|
||||
if (GUILayout.Button("删除属性")) { DeleteInstance(); }
|
||||
Min.SetValueWithoutNotify(value.minValue);
|
||||
Max.SetValueWithoutNotify(value.maxValue);
|
||||
|
||||
Min.RegisterCallback<FocusOutEvent>(evt => ModifyMin());
|
||||
Max.RegisterCallback<FocusOutEvent>(evt => ModifyMax());
|
||||
|
||||
button.clicked += DeleteInstance;
|
||||
}
|
||||
|
||||
/// <summary> 修改名字 </summary>
|
||||
private void ModifyName(string newName) {
|
||||
instance.name = newName;
|
||||
Undo.RecordObject(instance, "修改属性名称");
|
||||
EditorUtility.SetDirty(instance);
|
||||
/// <summary> 修改最小值 </summary>
|
||||
private void ModifyMin() { value.minValue = Min.value; Dirty(); }
|
||||
/// <summary> 修改最大值 </summary>
|
||||
private void ModifyMax() { value.maxValue = Max.value; Dirty(); }
|
||||
|
||||
/// <summary> 保存资源 </summary>
|
||||
private void Dirty() {
|
||||
EditorUtility.SetDirty(value);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
/// <summary> 删除实例 </summary>
|
||||
private void DeleteInstance() {
|
||||
AttributeContainerConst container = instance.container;
|
||||
container.instances.Remove(instance);
|
||||
AttributeContainerConst container = value.container;
|
||||
container.instances.Remove(value);
|
||||
EditorUtility.SetDirty(container);
|
||||
Undo.DestroyObjectImmediate(instance);
|
||||
Undo.DestroyObjectImmediate(value);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ guid: 1e2db82f02928494990b89396707863b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
defaultReferences:
|
||||
- VisualTreeAsset: {fileID: 9197481963319205126, guid: 01bc614c0c779d148afa254dbde22ec8, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor;
|
||||
using MuHua;
|
||||
|
||||
namespace MuHuaEditor {
|
||||
@@ -9,106 +10,114 @@ namespace MuHuaEditor {
|
||||
/// 属性 - UI列表
|
||||
/// </summary>
|
||||
public class UIAttributeList : ModuleUIPanel, UIControl {
|
||||
/// <summary> 模板资源 </summary>
|
||||
public VisualTreeAsset templateAsset;
|
||||
/// <summary> 移动目标 </summary>
|
||||
public VisualElement moving;
|
||||
/// <summary> 拖拽预览 </summary>
|
||||
public VisualElement preview;
|
||||
/// <summary> 鼠标位置 </summary>
|
||||
/// <summary> 项目预览 </summary>
|
||||
public UIItem previewItem;
|
||||
/// <summary> 鼠标偏移 </summary>
|
||||
public Vector2 mousePosition;
|
||||
/// <summary> 位置偏移 </summary>
|
||||
public Vector2 positionOffset;
|
||||
/// <summary> 偏移位置 </summary>
|
||||
public Vector2 offsetPosition;
|
||||
public Vector2 mouseOffset;
|
||||
/// <summary> 属性列表 </summary>
|
||||
public AttributeContainerConst container;
|
||||
/// <summary> 项目列表 </summary>
|
||||
public ModuleUIItems<UIItem, AttributeInstanceConst> items;
|
||||
|
||||
public UIAttributeList(VisualElement element, VisualTreeAsset templateAsset) : base(element) {
|
||||
this.templateAsset = templateAsset;
|
||||
items = new ModuleUIItems<UIItem, AttributeInstanceConst>(element, templateAsset,
|
||||
(data, element) => new UIItem(data, element, this));
|
||||
|
||||
element.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||
element.RegisterCallback<MouseMoveEvent>(FloatingFunc);
|
||||
}
|
||||
private void MouseUpEvent(MouseUpEvent evt) {
|
||||
if (preview == null) { return; }
|
||||
preview.parent.Remove(preview);
|
||||
preview = null;
|
||||
moving.EnableInClassList("acce-hide", false);
|
||||
if (previewItem == null) { return; }
|
||||
previewItem.Dispose();
|
||||
|
||||
EditorUtility.SetDirty(container);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
private void FloatingFunc(MouseMoveEvent evt) {
|
||||
mousePosition = evt.mousePosition;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
if (preview == null) { return; }
|
||||
preview.transform.position = mousePosition - offsetPosition;
|
||||
preview.transform.position = positionOffset + mousePosition - mouseOffset;
|
||||
int insertIndex = GetInsertIndex(element, preview);
|
||||
int oldIndex = element.IndexOf(moving);
|
||||
// 修正插入索引
|
||||
// Debug.Log($"{insertIndex} , {oldIndex}");
|
||||
if (insertIndex > oldIndex) insertIndex--;
|
||||
if (oldIndex != insertIndex) { MovePreviewElement(oldIndex, insertIndex); }
|
||||
}
|
||||
|
||||
public void Dispose() => items.Release();
|
||||
|
||||
/// <summary> 初始化 </summary>
|
||||
public void Initial(List<AttributeInstanceConst> list) {
|
||||
items.Create(list);
|
||||
public void Initial(AttributeContainerConst container) {
|
||||
this.container = container;
|
||||
items.Create(container.instances);
|
||||
}
|
||||
/// <summary> 设置值 </summary>
|
||||
// public void Settings(T value) => callback?.Invoke(value);
|
||||
public void Settings(VisualElement moving, AttributeInstanceConst value) {
|
||||
this.moving = moving;
|
||||
moving.EnableInClassList("acce-hide", true);
|
||||
|
||||
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;
|
||||
preview = templateAsset.Instantiate();
|
||||
previewItem = new UIItem(value, preview);
|
||||
items.element.Add(preview);
|
||||
|
||||
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;
|
||||
preview.EnableInClassList("acce-preview", true);
|
||||
// Debug.Log($"{preview.transform.position} , {preview.worldBound.position} , {moving.worldBound.position}");
|
||||
mouseOffset = mousePosition;
|
||||
// preview.transform.position的默认值
|
||||
positionOffset = moving.worldBound.position - preview.worldBound.position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取插入索引
|
||||
/// </summary>
|
||||
/// <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];
|
||||
for (int i = 0; i < parent.childCount - 1; i++) {
|
||||
VisualElement child = parent[i];
|
||||
if (child == preview) continue;
|
||||
if (previewCenter.y < child.worldBound.center.y) {
|
||||
insertIndex = i;
|
||||
break;
|
||||
}
|
||||
if (previewCenter.y - 10 < child.worldBound.center.y) { insertIndex = i; break; }
|
||||
insertIndex = i + 1;
|
||||
}
|
||||
return insertIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移动预览元素到新位置
|
||||
/// </summary>
|
||||
/// <summary> 移动预览元素到新位置 </summary>
|
||||
private void MovePreviewElement(int oldIndex, int newIndex) {
|
||||
VisualElement temp = element[oldIndex];
|
||||
// element.RemoveAt(oldIndex);
|
||||
element.Insert(newIndex, temp);
|
||||
|
||||
AttributeInstanceConst instanceConst = container.instances[oldIndex];
|
||||
container.instances.RemoveAt(oldIndex);
|
||||
container.instances.Insert(newIndex, instanceConst);
|
||||
}
|
||||
|
||||
/// <summary> UI项 </summary>
|
||||
public class UIItem : ModuleUIItem<AttributeInstanceConst> {
|
||||
public readonly UIAttributeList parent;
|
||||
public UIAttributePanel attributePanel;
|
||||
|
||||
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) : base(value, element) {
|
||||
attributePanel = new UIAttributePanel(value, element);
|
||||
}
|
||||
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}";
|
||||
attributePanel = new UIAttributePanel(value, element);
|
||||
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||
element.RegisterCallback<MouseUpEvent>(MouseUpEvent);
|
||||
}
|
||||
public override void DefaultState() {
|
||||
// Button.EnableInClassList("button-s", false);
|
||||
@@ -118,9 +127,7 @@ namespace MuHuaEditor {
|
||||
// Button.EnableInClassList("button-s", true);
|
||||
}
|
||||
|
||||
private void MouseDownEvent(MouseDownEvent evt) => parent.MouseDownEvent(element);
|
||||
|
||||
private void MouseUpEvent(MouseUpEvent evt) => parent.MouseUpEvent();
|
||||
private void MouseDownEvent(MouseDownEvent evt) => parent.Settings(element, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 属性面板
|
||||
/// </summary>
|
||||
public class UIAttributePanel : ModuleUIPanel {
|
||||
|
||||
private AttributeInstanceConst value;
|
||||
|
||||
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 Toggle Boolean => Q<Toggle>("Boolean");
|
||||
|
||||
public UIAttributePanel(AttributeInstanceConst value, VisualElement element) : base(element) {
|
||||
this.value = value;
|
||||
Initial();
|
||||
Name.RegisterCallback<FocusOutEvent>(evt => ModifyName());
|
||||
Type.RegisterValueChangedCallback(evt => ModifyType((AttributeType)evt.newValue));
|
||||
Value.RegisterCallback<FocusOutEvent>(evt => ModifyValue());
|
||||
Boolean.RegisterValueChangedCallback(evt => ModifyBoolean());
|
||||
}
|
||||
|
||||
public void Initial() {
|
||||
Name.SetValueWithoutNotify(value.name);
|
||||
Type.Init(value.type);
|
||||
Value.SetValueWithoutNotify(value.defaultValue);
|
||||
Boolean.value = value.defaultValue > 0;
|
||||
|
||||
if (value.type == AttributeType.Boolean) {
|
||||
Value.style.display = DisplayStyle.None;
|
||||
}
|
||||
else { Boolean.style.display = DisplayStyle.None; }
|
||||
|
||||
if (value.type == AttributeType.Percentage) {
|
||||
Range.text = $"{value.minValue}% ~ {value.maxValue}%";
|
||||
}
|
||||
else { Range.text = $"{value.minValue} ~ {value.maxValue}"; }
|
||||
}
|
||||
|
||||
/// <summary> 修改名字 </summary>
|
||||
private void ModifyName() { value.name = Name.value; Dirty(); }
|
||||
/// <summary> 修改类型 </summary>
|
||||
private void ModifyType(AttributeType type) {
|
||||
if (type == AttributeType.Float) { value.InitialFloat(); }
|
||||
if (type == AttributeType.Integer) { value.InitialInteger(); }
|
||||
if (type == AttributeType.Boolean) { value.InitialBoolean(); }
|
||||
if (type == AttributeType.Percentage) { value.InitialPercentage(); }
|
||||
if (value.type == AttributeType.Boolean) {
|
||||
Value.style.display = DisplayStyle.None;
|
||||
}
|
||||
else { Boolean.style.display = DisplayStyle.None; }
|
||||
Dirty();
|
||||
}
|
||||
/// <summary> 修改默认值 </summary>
|
||||
private void ModifyValue() { value.defaultValue = Value.value; Dirty(); }
|
||||
/// <summary> 修改布尔值 </summary>
|
||||
private void ModifyBoolean() { value.defaultValue = Boolean.value ? 1 : 0; Dirty(); }
|
||||
|
||||
/// <summary> 保存资源 </summary>
|
||||
private void Dirty() {
|
||||
EditorUtility.SetDirty(value);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aeb4c96a0ef14c4f9cb2b8afdfc091c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,7 +9,7 @@ using UnityEngine;
|
||||
public class AttributeContainerConst : ScriptableObject {
|
||||
/// <summary> 属性列表 </summary>
|
||||
[HideInInspector]
|
||||
public List<AttributeInstanceConst> instances;
|
||||
public List<AttributeInstanceConst> instances = new List<AttributeInstanceConst>();
|
||||
|
||||
/// <summary> 转换数据 </summary>
|
||||
public AttributeContainer To() {
|
||||
|
||||
@@ -20,6 +20,31 @@ public class AttributeInstanceConst : ScriptableObject {
|
||||
[HideInInspector]
|
||||
public AttributeContainerConst container;
|
||||
|
||||
public void InitialFloat() {
|
||||
type = AttributeType.Float;
|
||||
defaultValue = 0;
|
||||
minValue = 0;
|
||||
maxValue = 9999;
|
||||
}
|
||||
public void InitialInteger() {
|
||||
type = AttributeType.Integer;
|
||||
defaultValue = 0;
|
||||
minValue = 0;
|
||||
maxValue = 9999;
|
||||
}
|
||||
public void InitialBoolean() {
|
||||
type = AttributeType.Boolean;
|
||||
defaultValue = 0;
|
||||
minValue = 0;
|
||||
maxValue = 1;
|
||||
}
|
||||
public void InitialPercentage() {
|
||||
type = AttributeType.Percentage;
|
||||
defaultValue = 0;
|
||||
minValue = 0;
|
||||
maxValue = 100;
|
||||
}
|
||||
|
||||
/// <summary> 转换数据 </summary>
|
||||
public AttributeInstance To() {
|
||||
AttributeInstance instance = new AttributeInstance();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
.acce-preview {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.acce-hide {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
+3
-5
@@ -2,15 +2,13 @@
|
||||
<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" class="acce-preview" />
|
||||
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" class="acce-hide" />
|
||||
<ui:Instance template="AttributeTemplate" name="AttributeTemplate" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="ButtonGroup" style="flex-direction: row;">
|
||||
<ui:VisualElement name="ButtonGroup" style="flex-direction: row; justify-content: space-between;">
|
||||
<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
@@ -3,6 +3,7 @@
|
||||
<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:Toggle name="Boolean" style="flex-grow: 1;" />
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b88d603d14ca15f4e9bbd6ebc99e332f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51817b5555c3c584f846b2c05b877f72
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
||||
+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">
|
||||
<Style src="project://database/Assets/ModuleCore/ModuleAttribute/UI%20Toolkit/AttributeInstanceConstEditor/AttributeInstanceConstEditor.uss?fileID=7433441132597879392&guid=51817b5555c3c584f846b2c05b877f72&type=3#AttributeInstanceConstEditor" />
|
||||
<ui:VisualElement name="AttributePanel" 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:Toggle name="Boolean" style="flex-grow: 1;" />
|
||||
<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: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:FloatField value="42.2" name="Min" style="flex-grow: 1; margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px;" />
|
||||
<ui:Label tabindex="-1" text="min ~ max" parse-escape-sequences="true" display-tooltip-when-elided="true" 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:FloatField value="42.2" name="Max" style="flex-grow: 1; margin-top: 2px; margin-right: 2px; margin-bottom: 2px; margin-left: 2px;" />
|
||||
</ui:VisualElement>
|
||||
<ui:Button text="删除" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Button" 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:UXML>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01bc614c0c779d148afa254dbde22ec8
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
Reference in New Issue
Block a user