选择可显示项
本来想做启闭的懒得做了
This commit is contained in:
@@ -41,8 +41,18 @@ namespace Ichni.Editor
|
||||
}
|
||||
public IEnumerator TryGetTab(GameElement targetElement)
|
||||
{
|
||||
|
||||
StandardInspectionElement.GenerateForLoading();
|
||||
// targetElement.ScanAndAddEnableTypes();
|
||||
// if (!targetElement.GetChildrenByTypes().Contains(targetElement))
|
||||
// {
|
||||
// var tab = EditorManager.instance.uiManager.hierarchy.GenerateTab(targetElement, null);
|
||||
// tab.SelectGameElement();
|
||||
// Destroy(tab.gameObject);
|
||||
// EditorManager.instance.uiManager.hierarchy.tabList.Remove(tab);
|
||||
// yield break;
|
||||
// }
|
||||
// EditorManager.instance.uiManager.inspector.ClearInspector();
|
||||
// EditorManager.instance.uiManager.inspector.SetInspector(targetElement);
|
||||
//StandardInspectionElement.GenerateForLoading();
|
||||
// 1. 向上找到最近的有Tab的祖先
|
||||
Stack<GameElement> stack = new Stack<GameElement>();
|
||||
GameElement current = targetElement;
|
||||
@@ -58,9 +68,17 @@ namespace Ichni.Editor
|
||||
{
|
||||
var elem = stack.Pop();
|
||||
// 只展开父Tab,不直接生成Tab
|
||||
if (elem.parentElement != null && elem.parentElement.connectedTab != null && !elem.parentElement.connectedTab.isExpanded)
|
||||
if (elem.parentElement != null && elem.parentElement.connectedTab != null)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold();
|
||||
if (!elem.parentElement.connectedTab.isExpanded)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold();
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);//合上再展开,这思路也是没谁了
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
// 等待当前elem的Tab生成
|
||||
@@ -72,15 +90,36 @@ namespace Ichni.Editor
|
||||
}
|
||||
|
||||
// 3. 等待目标Tab实例化
|
||||
while (targetElement.connectedTab == null)
|
||||
while (targetElement.connectedTab is null)
|
||||
{
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
HierarchyTab finalTab = targetElement.connectedTab;
|
||||
float Tablocalpos = (-finalTab.transform.localPosition.y) - (tabContainer.sizeDelta.y / 4f);
|
||||
float pct = Tablocalpos / tabContainer.sizeDelta.y;
|
||||
scrollRect.verticalNormalizedPosition = 1f - pct;
|
||||
|
||||
// 修正定位算法
|
||||
yield return null; // 等待布局刷新
|
||||
RectTransform tabRect = finalTab.GetComponent<RectTransform>();
|
||||
RectTransform containerRect = tabContainer;
|
||||
RectTransform viewportRect = scrollRect.viewport != null ? scrollRect.viewport : scrollRect.GetComponent<RectTransform>();
|
||||
|
||||
// Tab相对于内容顶部的距离(正值为下,负值为上)
|
||||
float tabTop = -tabRect.anchoredPosition.y;
|
||||
float tabHeight = tabRect.rect.height;
|
||||
float contentHeight = containerRect.rect.height;
|
||||
float viewportHeight = viewportRect.rect.height;
|
||||
|
||||
// 目标:让Tab居中(或尽量居中)
|
||||
float targetCenter = tabTop + tabHeight / 2f;
|
||||
float viewportCenter = viewportHeight / 2f;
|
||||
float scrollOffset = targetCenter - viewportCenter;
|
||||
|
||||
// normalizedPosition = 1 - (scrollOffset / (contentHeight - viewportHeight))
|
||||
float denominator = Mathf.Max(1f, contentHeight - viewportHeight);
|
||||
float normalized = 1f - Mathf.Clamp01(scrollOffset / denominator);
|
||||
|
||||
scrollRect.verticalNormalizedPosition = normalized;
|
||||
finalTab.SelectGameElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,24 +125,33 @@ namespace Ichni.Editor
|
||||
EditorManager.instance.uiManager.inspector.SetInspector(connectedGameElement);
|
||||
EditorManager.instance.timeline.SetTimeLine(connectedGameElement);
|
||||
}
|
||||
|
||||
private IEnumerator ienumerator = null;
|
||||
public void ExpandOrFold()
|
||||
{
|
||||
ExpandOrFold(false);
|
||||
}
|
||||
public void ExpandOrFold(bool forceAllExPand = false)
|
||||
{
|
||||
this.childTabList.RemoveAll(s => s == null);
|
||||
isExpanded = !isExpanded;
|
||||
ExpandAnim();
|
||||
if (isExpanded)
|
||||
{
|
||||
connectedGameElement.ScanAndAddEnableTypes();
|
||||
List<GameElement> FixedList = !forceAllExPand ? connectedGameElement.GetChildrenByTypes() : connectedGameElement.childElementList;
|
||||
|
||||
// float startTime = Time.realtimeSinceStartup;
|
||||
// connectedGameElement.childElementList.Sort();//TODO: 后续可以让玩家手动快速排序
|
||||
// Debug.Log("排序耗时 " + (Time.realtimeSinceStartup - startTime).ToString());
|
||||
StartCoroutine(ExpandOverTime());
|
||||
Debug.Log(FixedList.Count);
|
||||
ienumerator = ExpandOverTime(FixedList);
|
||||
StartCoroutine(ienumerator);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//expandButton.transform.Rotate(new Vector3(0, 0, 180));
|
||||
|
||||
StopCoroutine(ienumerator);
|
||||
ienumerator = null;
|
||||
for (int i = childTabList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
childTabList[i].SetExpansion(isExpanded);
|
||||
@@ -171,11 +180,11 @@ namespace Ichni.Editor
|
||||
{
|
||||
expandButton.transform.DORotate(new Vector3(0, 0, !isExpanded ? 0f : 180f), 0.2f);
|
||||
}
|
||||
private IEnumerator ExpandOverTime()//帧率过低的时候等一下再实例化
|
||||
private IEnumerator ExpandOverTime(List<GameElement> FixedList)//帧率过低的时候等一下再实例化
|
||||
{
|
||||
|
||||
float startTime = Time.realtimeSinceStartup;
|
||||
for (var index = 0; index < connectedGameElement.childElementList.Count; index++)
|
||||
for (var index = 0; index < FixedList.Count; index++)
|
||||
{
|
||||
int hasYield = 0;
|
||||
while (Time.realtimeSinceStartup - startTime > 1f / EditorManager.instance.editorSettings.frameRate * 3f && hasYield <= 2)
|
||||
@@ -183,8 +192,9 @@ namespace Ichni.Editor
|
||||
yield return null;
|
||||
hasYield += 1;
|
||||
}
|
||||
var childElement = connectedGameElement.childElementList[index];
|
||||
var childElement = FixedList[index];
|
||||
EditorManager.instance.uiManager.hierarchy.GenerateTab(childElement, connectedGameElement);
|
||||
print($"生成子Tab:{childElement.elementName},索引:{index},总数:{FixedList.Count}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
public partial class TrackRendererSubmodule : TrackSubmodule
|
||||
{
|
||||
protected int submoduleNameIndex = 0;
|
||||
protected readonly string[] submoduleName = { "Auto Orient", "Path Generator", "Tube Generator", "Surface" };
|
||||
public MeshGenerator meshGenerator;
|
||||
public MeshRenderer meshRenderer;
|
||||
public Material renderMaterial;
|
||||
@@ -42,7 +44,7 @@ namespace Ichni.RhythmGame
|
||||
this.materialThemeBundleName = materialThemeBundleName;
|
||||
this.materialName = materialName;
|
||||
Material mat = ThemeBundleManager.instance.GetObject<Material>(materialThemeBundleName, materialName);
|
||||
if(mat != null)
|
||||
if (mat != null)
|
||||
{
|
||||
renderMaterial = mat;
|
||||
meshRenderer.material = renderMaterial;
|
||||
@@ -54,7 +56,7 @@ namespace Ichni.RhythmGame
|
||||
SetEnableZWrite();
|
||||
SetEnableEmission();
|
||||
SetEmissionIntensity();
|
||||
|
||||
|
||||
if (track.trackTimeSubmodule is TrackTimeSubmoduleMovable)
|
||||
{
|
||||
meshGenerator.clipFrom = 0;
|
||||
@@ -86,9 +88,11 @@ namespace Ichni.RhythmGame
|
||||
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
|
||||
Inspector inspectorMain = EditorManager.instance.uiManager.inspector;
|
||||
|
||||
var container = inspector.GenerateContainer("Track Renderer Auto Orient");
|
||||
|
||||
var container = inspector.GenerateContainer("Track Renderer " + submoduleName[submoduleNameIndex]);
|
||||
var zWriteSettings = container.GenerateSubcontainer(3);
|
||||
|
||||
|
||||
|
||||
var zWriteToggle =
|
||||
inspector.GenerateToggle(this, zWriteSettings, "Enable ZWrite", nameof(zWrite))
|
||||
.AddListenerFunction(SetEnableZWrite);
|
||||
@@ -99,7 +103,7 @@ namespace Ichni.RhythmGame
|
||||
var emissionIntensityInputField =
|
||||
inspector.GenerateInputField(this, emissionSettings, "Emission Intensity", nameof(emissionIntensity))
|
||||
.AddListenerFunction(SetEmissionIntensity);
|
||||
|
||||
|
||||
var materialSettings = container.GenerateSubcontainer(3);
|
||||
var themeBundleDropdown = inspector
|
||||
.GenerateDropdown(this, materialSettings, "Theme Bundle", ThemeBundleManager.instance.selectedThemeBundleList, nameof(materialThemeBundleName))
|
||||
@@ -132,12 +136,12 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
meshRenderer.material.SetInt("_Emission", enableEmission ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
protected void SetEnableZWrite()
|
||||
{
|
||||
meshRenderer.material.SetInt("_ZWrite", zWrite ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
protected void SetEmissionIntensity()
|
||||
{
|
||||
meshRenderer.material.SetColor("_EmissionColor", Color.white * Mathf.Pow(2, emissionIntensity));
|
||||
@@ -164,6 +168,7 @@ namespace Ichni.RhythmGame
|
||||
this.meshRenderer.material = renderMaterial;
|
||||
this.splineRenderer.color = Color.white;
|
||||
this.splineRenderer.uvRotation = 90;
|
||||
this.submoduleNameIndex = 0; // Auto Orient is the first submodule
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
@@ -194,6 +199,7 @@ namespace Ichni.RhythmGame
|
||||
materialName = trackRendererSubmodule.materialName;
|
||||
enableEmission = trackRendererSubmodule.enableEmission;
|
||||
emissionIntensity = trackRendererSubmodule.emissionIntensity;
|
||||
|
||||
}
|
||||
|
||||
public override void ExecuteBM()
|
||||
@@ -241,6 +247,7 @@ namespace Ichni.RhythmGame
|
||||
this.meshRenderer.material = renderMaterial;
|
||||
this.pathGenerator.color = Color.white;
|
||||
this.pathGenerator.uvRotation = 90;
|
||||
this.submoduleNameIndex = 1; // Path Generator is the second submodule
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
@@ -305,7 +312,7 @@ namespace Ichni.RhythmGame
|
||||
public TubeGenerator tubeGenerator;
|
||||
public int sideCount;
|
||||
|
||||
public TrackRendererSubmoduleTubeGenerator(Track track, bool enableEmission, float emissionIntensity, bool zWrite,
|
||||
public TrackRendererSubmoduleTubeGenerator(Track track, bool enableEmission, float emissionIntensity, bool zWrite,
|
||||
int sideCount, Material material = null) :
|
||||
base(track, enableEmission, emissionIntensity, zWrite)
|
||||
{
|
||||
@@ -323,6 +330,7 @@ namespace Ichni.RhythmGame
|
||||
this.tubeGenerator.color = Color.white;
|
||||
this.tubeGenerator.uvRotation = 90;
|
||||
this.tubeGenerator.sides = sideCount;
|
||||
this.submoduleNameIndex = 2; // Tube Generator is the third submodule
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
@@ -349,6 +357,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
public class TrackRendererSubmoduleTubeGenerator_BM : Submodule_BM
|
||||
{
|
||||
|
||||
public string materialThemeBundleName;
|
||||
public string materialName;
|
||||
public bool enableEmission;
|
||||
@@ -412,10 +421,11 @@ namespace Ichni.RhythmGame
|
||||
this.surface.spline = track.trackPathSubmodule.path;
|
||||
this.surface.clipFrom = 0;
|
||||
this.surface.clipTo = 1;
|
||||
this.surface.updateMethod = SplineUser.UpdateMethod.LateUpdate;
|
||||
this.surface.updateMethod = SplineUser.UpdateMethod.Update;
|
||||
this.meshRenderer.material = renderMaterial;
|
||||
this.surface.color = Color.white;
|
||||
this.surface.uvRotation = 90;
|
||||
this.submoduleNameIndex = 3; // Surface is the fourth submodule
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
|
||||
@@ -147,7 +147,7 @@ public class SampleWindow : MovableWindow//该window高度为300,横的要在1
|
||||
TransformChanged();
|
||||
windowRect.GetComponent<CanvasGroup>().alpha = track.timeDurationSubmodule.CheckTimeInDuration(songTime) ? 1f : 0.2f;
|
||||
}
|
||||
if (selectedGameObject.GetType() != typeof(TMP_InputField) && RectTransformUtility.RectangleContainsScreenPoint(windowRect, Mouse.current.position.ReadValue()))
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(windowRect, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
DetectNote();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user