做不出来
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Opsive.Shared.Editor.UIElements;
|
||||
using Opsive.Shared.Editor.UIElements.Controls;
|
||||
using Opsive.Shared.Editor.UIElements.Controls.Types;
|
||||
using Cielonos.MainGame.Characters.AI;
|
||||
|
||||
namespace Cielonos.MainGame.Characters.AI.Editor
|
||||
{
|
||||
[ControlType(typeof(CheckAttribute))]
|
||||
public class CheckAttributeControl : TypeControlBase
|
||||
{
|
||||
public override bool UseLabel => false;
|
||||
|
||||
protected override VisualElement GetControl(TypeControlInput input)
|
||||
{
|
||||
var task = input.Value as CheckAttribute;
|
||||
if (task == null) return new Label("[CheckAttribute] 节点引用无效");
|
||||
|
||||
var container = new VisualElement();
|
||||
|
||||
var baseAttrContainer = new VisualElement();
|
||||
|
||||
// 动态显示隐藏逻辑
|
||||
Action updateVisibilities = () => {
|
||||
if (task.compareMode == AttributeCompareMode.Percentage)
|
||||
{
|
||||
baseAttrContainer.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseAttrContainer.style.display = DisplayStyle.None;
|
||||
}
|
||||
};
|
||||
|
||||
// 1. 添加常规控制字段
|
||||
AddField(input, task, "attributeName", container);
|
||||
AddField(input, task, "compareMode", container, updateVisibilities);
|
||||
|
||||
// 2. 百分比分母属性配置字段
|
||||
AddField(input, task, "percentBaseAttribute", baseAttrContainer);
|
||||
container.Add(baseAttrContainer);
|
||||
|
||||
// 3. 比较判断及比较值字段
|
||||
AddField(input, task, "isBiggerThan", container);
|
||||
AddField(input, task, "biggerThanValue", container);
|
||||
AddField(input, task, "isSmallerThan", container);
|
||||
AddField(input, task, "smallerThanValue", container);
|
||||
AddField(input, task, "isEqual", container);
|
||||
AddField(input, task, "equalValue", container);
|
||||
|
||||
// 4. 初始化可见性
|
||||
updateVisibilities();
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private void AddField(TypeControlInput input, CheckAttribute task, string fieldName, VisualElement container, Action postChangeAction = null)
|
||||
{
|
||||
FieldInspectorView.AddField(input.UnityObject, task, fieldName, container, (object newValue) =>
|
||||
{
|
||||
if (newValue != null)
|
||||
{
|
||||
if (newValue is CheckAttribute)
|
||||
{
|
||||
// Opsive 通过底层 Binding 更新了该 Task 对象,无需手动赋值
|
||||
}
|
||||
else
|
||||
{
|
||||
FieldInfo fieldInfo = typeof(CheckAttribute).GetField(fieldName);
|
||||
if (fieldInfo != null)
|
||||
{
|
||||
if (fieldInfo.FieldType.IsEnum)
|
||||
{
|
||||
try
|
||||
{
|
||||
fieldInfo.SetValue(task, Enum.ToObject(fieldInfo.FieldType, newValue));
|
||||
}
|
||||
catch
|
||||
{
|
||||
fieldInfo.SetValue(task, newValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldInfo.SetValue(task, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input.OnChangeEvent(task);
|
||||
postChangeAction?.Invoke();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f22bb5b924e17b245a8eb0201de79c84
|
||||
Reference in New Issue
Block a user