选择可显示项
本来想做启闭的懒得做了
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dreamteck.Splines;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
@@ -161,10 +162,54 @@ namespace Ichni.RhythmGame
|
||||
}
|
||||
}
|
||||
|
||||
public abstract partial class GameElement
|
||||
public abstract partial class GameElement//Editor 专
|
||||
{
|
||||
public class EnableType : IBaseElement
|
||||
{
|
||||
public Type type;
|
||||
public bool enable;
|
||||
|
||||
public BaseElement_BM matchedBM { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
};
|
||||
public List<EnableType> enableTypes;
|
||||
|
||||
/// <summary>
|
||||
/// 扫描childElementList中的类型并加入enableTypes(去重,兼容性好)
|
||||
/// </summary>
|
||||
public void ScanAndAddEnableTypes()
|
||||
{
|
||||
// 初始化enableTypes列表
|
||||
if (enableTypes == null)
|
||||
enableTypes = new List<EnableType>();
|
||||
|
||||
// 记录已存在的类型,避免重复
|
||||
HashSet<Type> existingTypes = new HashSet<Type>();
|
||||
foreach (var et in enableTypes)
|
||||
{
|
||||
if (et != null && et.type != null)
|
||||
existingTypes.Add(et.type);
|
||||
}
|
||||
|
||||
// 遍历所有子元素类型,若未添加则加入enableTypes
|
||||
foreach (var child in childElementList)
|
||||
{
|
||||
var childType = child.GetType();
|
||||
if (!existingTypes.Contains(childType))
|
||||
{
|
||||
enableTypes.Add(new EnableType
|
||||
{
|
||||
type = childType,
|
||||
enable = true
|
||||
});
|
||||
existingTypes.Add(childType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetUpInspector() //被点击时设置第一层Inspector
|
||||
{
|
||||
ScanAndAddEnableTypes();
|
||||
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
|
||||
var container = inspector.GenerateContainer("Element Info");
|
||||
|
||||
@@ -177,6 +222,30 @@ namespace Ichni.RhythmGame
|
||||
inspector.GenerateCompositeParameterWindow(this, "Tags List", nameof(tags)).SetAsStringList();
|
||||
});
|
||||
|
||||
// 只用反射方式生成enableTypes的UI
|
||||
if (enableTypes != null && enableTypes.Count > 0)
|
||||
{
|
||||
var elcontainer = inspector.GenerateContainer("Enable Children DisPlay");
|
||||
var enableTypeContainer = elcontainer.GenerateSubcontainer(3);
|
||||
var type = enableTypes.GetType().GetGenericArguments()[0];
|
||||
int elcount = 0;
|
||||
for (int idx = 0; idx < enableTypes.Count; idx++)
|
||||
{
|
||||
elcount++;
|
||||
if (elcount > 3)
|
||||
{
|
||||
elcount = 0;
|
||||
enableTypeContainer = elcontainer.GenerateSubcontainer(3);
|
||||
}
|
||||
var et = enableTypes[idx];
|
||||
inspector.GenerateToggle(
|
||||
et,
|
||||
enableTypeContainer,
|
||||
et.type.Name,
|
||||
nameof(et.enable) // 传递字段名字符串
|
||||
);
|
||||
}
|
||||
}
|
||||
//次级模块
|
||||
foreach (var submodule in submoduleList)
|
||||
{
|
||||
@@ -207,6 +276,30 @@ namespace Ichni.RhythmGame
|
||||
|
||||
return gameElements;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据enableTypes筛选子元素(只返回enable为true的类型对应的子元素)
|
||||
/// </summary>
|
||||
public List<GameElement> GetChildrenByTypes()
|
||||
{
|
||||
if (enableTypes == null || enableTypes.Count == 0)
|
||||
return new List<GameElement>();
|
||||
|
||||
var enabledTypes = new HashSet<Type>();
|
||||
foreach (var et in enableTypes)
|
||||
{
|
||||
if (et.enable) enabledTypes.Add(et.type);
|
||||
}
|
||||
// 问题1:只匹配类型本身,不能处理继承关系(如子类/接口)
|
||||
// 问题2:如果childElementList有null元素会抛异常
|
||||
// 问题3:如果enableTypes有重复type,没影响但没必要
|
||||
|
||||
// 更健壮的写法如下(支持继承和接口,避免null):
|
||||
return childElementList.FindAll(child =>
|
||||
child != null && enabledTypes.Any(t => t.IsAssignableFrom(child.GetType()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Beatmap
|
||||
|
||||
Reference in New Issue
Block a user