改,加,TrackGlobalColorChange

Signed-off-by: TRAfoer <lhf190@outlook.com>
This commit is contained in:
2025-10-01 20:41:06 +08:00
parent 25a458dd8c
commit b29654e423
37 changed files with 630986 additions and 21442 deletions

View File

@@ -617,6 +617,51 @@ namespace Ichni.Editor
pathnode.Refresh();
}
}
public static void FloorAnim()
{
if (inspector.connectedGameElement == null)
{
LogWindow.Log("Please select a Element first!");
return;
}
List<AnimationBase> elements = inspector.connectedGameElement.GetAllGameElementsFromThis().OfType<AnimationBase>().ToList();
// 预先缓存属性信息(如果在循环外部知道具体类型)
var propertiesToCheck = typeof(GameElement).GetProperties()
.Where(p => p.PropertyType == typeof(FlexibleFloat))
.ToArray();
foreach (var element in elements)
{
bool needsRefresh = false;
foreach (var prop in propertiesToCheck)
{
var ff = prop.GetValue(element) as FlexibleFloat;
if (ff?.animations?.Count > 0 && ff.animations[0] != null)
{
var firstAnimation = ff.animations[0];
if (firstAnimation.startTime > 0)
{
ff.animations.Insert(0, new AnimatedFloat(
0,
Math.Min(firstAnimation.startTime, 1),
firstAnimation.startValue,
firstAnimation.startValue,
AnimationCurveType.Linear
));
needsRefresh = true;
Debug.Log($"Added 0 keyframe to {element.elementName}'s {prop.Name}");
}
}
}
if (needsRefresh)
{
element.Refresh();
element.animatedObject?.Refresh(); // 使用空条件运算符
}
}
}
}
}

View File

@@ -0,0 +1,179 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.Editor;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class TrackGlobalColorChange : AnimationBase
{
public FlexibleFloat colorR, colorG, colorB, colorA;
public static TrackGlobalColorChange GenerateElement(string elementName, System.Guid id,
List<string> tags, bool isFirstGenerated, GameElement animatedObject,
FlexibleFloat colorR, FlexibleFloat colorG, FlexibleFloat colorB, FlexibleFloat colorA)
{
if (animatedObject is not Track)
{
Debug.LogError("Animated Object is Not Track");
throw new System.ArgumentException("Animated Object is Not Track");
}
TrackGlobalColorChange trackGlobalColorChange = Instantiate(EditorManager.instance.basePrefabs.emptyObject)
.AddComponent<TrackGlobalColorChange>();
trackGlobalColorChange.Initialize(elementName, id, tags, isFirstGenerated, animatedObject);
trackGlobalColorChange.animatedObject = animatedObject;
trackGlobalColorChange.colorR = colorR;
trackGlobalColorChange.colorG = colorG;
trackGlobalColorChange.colorB = colorB;
trackGlobalColorChange.colorA = colorA;
trackGlobalColorChange.animationReturnType = FlexibleReturnType.Before;
//trackGlobalColorChange.timeDurationSubmodule.SetDuration(colorR, colorG, colorB, colorA);
return trackGlobalColorChange;
}
public override void SetDefaultSubmodules()
{
timeDurationSubmodule = new TimeDurationSubmodule(this);
}
protected override void UpdateAnimation(float songTime)
{
colorR.UpdateFlexibleFloat(songTime);
colorG.UpdateFlexibleFloat(songTime);
colorB.UpdateFlexibleFloat(songTime);
colorA.UpdateFlexibleFloat(songTime);
if (colorR.returnType is FlexibleReturnType.MiddleExecuting ||
colorG.returnType is FlexibleReturnType.MiddleExecuting ||
colorB.returnType is FlexibleReturnType.MiddleExecuting ||
colorA.returnType is FlexibleReturnType.MiddleExecuting)
{
animationReturnType = FlexibleReturnType.MiddleExecuting;
Color color = new Color(colorR.value, colorG.value, colorB.value, colorA.value);
((Track)animatedObject).trackRendererSubmodule.meshGenerator.color = color;
}
else if (colorR.isSwitchingReturnType || colorG.isSwitchingReturnType || colorB.isSwitchingReturnType || colorA.isSwitchingReturnType)
{
animationReturnType = FlexibleReturnType.MiddleExecuting;
Color color = new Color(colorR.value, colorG.value, colorB.value, colorA.value);
((Track)animatedObject).trackRendererSubmodule.meshGenerator.color = color;
}
else
{
if (!EditorManager.instance.musicPlayer.isPlaying && animationReturnType != FlexibleReturnType.MiddleInterval)
{
Color color = new Color(colorR.value, colorG.value, colorB.value, colorA.value);
((Track)animatedObject).trackRendererSubmodule.meshGenerator.color = color;
animationReturnType = FlexibleReturnType.After;
}
else
{
animationReturnType = FlexibleReturnType.Before;
}
}
}
public override void ApplyTimeOffset(float offset)
{
base.ApplyTimeOffset(offset);
foreach (var item in colorR.animations) item.ApplyTimeOffset(offset);
foreach (var item in colorG.animations) item.ApplyTimeOffset(offset);
foreach (var item in colorB.animations) item.ApplyTimeOffset(offset);
foreach (var item in colorA.animations) item.ApplyTimeOffset(offset);
}
public override Vector3 getValue(float time)
{
float r = colorR.GetValue(time);
float g = colorG.GetValue(time);
float b = colorB.GetValue(time);
float a = colorA.GetValue(time);
return new Vector3(r, g, b);
}
public override void Refresh()
{
base.Refresh();
if (colorR.animations.Count == 0 && colorG.animations.Count == 0 && colorB.animations.Count == 0 && colorA.animations.Count == 0)
{
((Track)animatedObject).trackRendererSubmodule.meshGenerator.color = Color.white;
}
else
{
UpdateAnimation(EditorManager.instance.songInformation.songTime);
}
}
public override void SetUpInspector()
{
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
base.SetUpInspector();
var container = inspector.GenerateContainer("Track Global Color Change");
var subcontainer = container.GenerateSubcontainer(3);
var colorRButton = inspector.GenerateButton(this, subcontainer, "Color R", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Color R", nameof(colorR)).SetAsFlexibleFloat();
});
var colorGButton = inspector.GenerateButton(this, subcontainer, "Color G", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Color G", nameof(colorG)).SetAsFlexibleFloat();
});
var colorBButton = inspector.GenerateButton(this, subcontainer, "Color B", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Color B", nameof(colorB)).SetAsFlexibleFloat();
});
var colorAButton = inspector.GenerateButton(this, subcontainer, "Color A", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Color A", nameof(colorA)).SetAsFlexibleFloat();
});
var graphicEditor = inspector.GenerateButton(this, subcontainer, "GraphicEditor", () =>
{
inspector.GenerateGraphicalFlexibleFloatWindow(this, "Track Global Color Change",
new FlexibleFloat[] { colorR, colorG, colorB, colorA }, new string[] { "ColorR", "ColorG", "ColorB", "ColorA" });
});
}
public override void SaveBM()
{
matchedBM = new Beatmap.TrackGlobalColorChange_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
colorR.ConvertToBM(), colorG.ConvertToBM(), colorB.ConvertToBM(), colorA.ConvertToBM());
}
}
}
namespace Ichni.RhythmGame.Beatmap
{
public class TrackGlobalColorChange_BM : AnimationBase_BM
{
public FlexibleFloat_BM colorR, colorG, colorB, colorA;
public TrackGlobalColorChange_BM()
{
}
public TrackGlobalColorChange_BM(string elementName, Guid elementGuid, List<string> tags,
GameElement_BM attachedElement, FlexibleFloat_BM colorR, FlexibleFloat_BM colorG, FlexibleFloat_BM colorB, FlexibleFloat_BM colorA)
: base(elementName, elementGuid, tags, attachedElement)
{
this.colorR = colorR;
this.colorG = colorG;
this.colorB = colorB;
this.colorA = colorA;
}
public override GameElement DuplicateBM(GameElement attached)
{
return TrackGlobalColorChange.GenerateElement(elementName, Guid.NewGuid(), tags, true, attached,
colorR.ConvertToGameType(), colorG.ConvertToGameType(), colorB.ConvertToGameType(), colorA.ConvertToGameType());
}
public override void ExecuteBM()
{
matchedElement = TrackGlobalColorChange.GenerateElement(elementName, elementGuid, tags, false, GetElement(attachedElementGuid),
colorR.ConvertToGameType(), colorG.ConvertToGameType(), colorB.ConvertToGameType(), colorA.ConvertToGameType());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6851ca77cda521469be038d4232a719
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -188,6 +188,9 @@ namespace Ichni.RhythmGame
}); //Particle Tracker
StandardInspectionElement.GenerateForTransform(this, generateContainer); //关于有Transform的元素
inspector.GenerateButton(this, particleSubcontainer, "Track Global Color Change",
() => { TrackGlobalColorChange.GenerateElement("New Track Global Color Change", Guid.NewGuid(), new List<string>(), true, this, new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat()); }); //变量容器
// var animationSubcontainer = generateContainer.GenerateSubcontainer(3);
// var displacementButton = inspector.GenerateButton(this, animationSubcontainer, "Displacement", () =>
// {

View File

@@ -136,8 +136,6 @@ public partial class EventPoint : MonoBehaviour
FatherTab.FatherWindow.VisibleArea.SetActive(true);
FatherTab.FatherWindow.animationCurveTypeDropdown.AddOptions(enumNameList);
FatherTab.FatherWindow.animationCurveTypeDropdown.value = (int)animatedFloat.animationCurveType;
// 更新文本
FatherTab.FatherWindow.StartText.text = animatedFloat.startTime.ToString();
FatherTab.FatherWindow.EndText.text = animatedFloat.endTime.ToString();

View File

@@ -43,11 +43,11 @@ public class NotefabContoler : MonoBehaviour
}
public void Update()
{
if (sampleWindow.isExpand && RectTransformUtility.RectangleContainsScreenPoint(this.GetComponent<RectTransform>(), Mouse.current.position.ReadValue()))
if (RectTransformUtility.RectangleContainsScreenPoint(this.GetComponent<RectTransform>(), Mouse.current.position.ReadValue()))
{
if (Mouse.current.leftButton.wasPressedThisFrame)
{
StartCoroutine(Moving());
if (sampleWindow.isExpand) StartCoroutine(Moving());
if (EditorManager.instance.uiManager.inspector.connectedGameElement != noteBase) EditorManager.instance.uiManager.hierarchy.FindTab(noteBase);
}
}

View File

@@ -45,7 +45,7 @@ namespace Ichni.RhythmGame
public GameObject highPassFilterEffect;
[Title("Inspector相关")] public GameObject inspectorSecondaryWindow;
[Title("编辑器描边Material")] public Material outlineShaderMaterial;
[Title("DynamicUI相关-Simple")] public GameObject dynamicUIContainer;
public GameObject dynamicUISubcontainer;
public GameObject inputField;

View File

@@ -100,6 +100,7 @@ namespace Ichni
}
public float CurrentFrameRate;
public TMP_Text FPStext;
public TMP_Text UIText;
private IEnumerator StartFrameRate()
{
int frameCount = 0;
@@ -115,6 +116,7 @@ namespace Ichni
yield return null;
}
}
private void Update()
{
if (isLoaded) projectManager.autoSaveManager.UpdateAutoSave();
@@ -131,7 +133,7 @@ namespace Ichni
{
projectManager.loadManager.LoadExport(projectName);
}
musicPlayer.audioSource.clip = songInformation.song;
beatmapContainer.gameElementList.ForEach(gameElement =>
{

View File

@@ -23,11 +23,11 @@ namespace Ichni.Editor
private List<SelectionConnector> lastHitConnectors = new List<SelectionConnector>();
private int currentSelectIndex = 0;
private Vector2 lastMousePosition;
private bool cachedIsPointerOverUI;
private GameObject cachedHoveredUI;
private int uiCheckFrameInterval = 3; // 每3帧检查一次
private int frameCount;
private int frameCount = 0;
private const int uiCheckFrameInterval = 5; // 每隔多少帧强制检查一次UI
private void Awake()
{
@@ -46,17 +46,9 @@ namespace Ichni.Editor
Vector2 currentMousePosition = Mouse.current.position.ReadValue();
if (currentMousePosition != lastMousePosition || frameCount % uiCheckFrameInterval == 0)
{
isPointerOverUI = IsPointerOverUI(out hoveredUI);
lastMousePosition = currentMousePosition;
cachedIsPointerOverUI = isPointerOverUI;
cachedHoveredUI = hoveredUI;
isPointerOverUI = IsPointerOverUI(out hoveredUI);
}
else
{
isPointerOverUI = cachedIsPointerOverUI;
hoveredUI = cachedHoveredUI;
}
SceneCameraOperation();
MusicPlayerOperation();
TracksOperation();
@@ -314,17 +306,13 @@ namespace Ichni.Editor
public partial class InputListener
{
private TMP_Text UIText => EditorManager.instance.UIText;
public bool IsPointerOverUI(out GameObject hoveredUI)
{
hoveredUI = null;
// 快速检查 - 使用Unity内置方法
if (!EventSystem.current.IsPointerOverGameObject())
return false;
// 详细检查 - 只有当快速检查通过时才执行
if (eventSystem == null || graphicRaycasters.Count == 0)
return false;
if (Mouse.current == null) return false;
pointerEventData = new PointerEventData(eventSystem)
{
@@ -333,21 +321,55 @@ namespace Ichni.Editor
List<RaycastResult> allResults = new List<RaycastResult>();
// 只对最上层的Canvas进行检测
foreach (var raycaster in graphicRaycasters.Where(r => r.gameObject.activeInHierarchy))
// 使用EventSystem的RaycastAll来确保检测所有UI
EventSystem.current.RaycastAll(pointerEventData, allResults);
// 或者手动检测所有GraphicRaycaster
foreach (var raycaster in FindObjectsOfType<GraphicRaycaster>())
{
if (!raycaster.enabled || !raycaster.gameObject.activeInHierarchy)
continue;
List<RaycastResult> results = new List<RaycastResult>();
raycaster.Raycast(pointerEventData, results);
if (results.Count > 0)
{
// 找到最前面的结果后立即返回
results.Sort((a, b) => b.sortingOrder.CompareTo(a.sortingOrder));
hoveredUI = results[0].gameObject;
return true;
}
allResults.AddRange(results);
}
// 移除无效结果
allResults.RemoveAll(r =>
r.gameObject == null ||
!r.gameObject.activeInHierarchy ||
!r.gameObject.GetComponent<RectTransform>());
if (allResults.Count > 0)
{
// 完整排序
allResults.Sort((a, b) =>
{
// 先按sorting layer
int layerCompare = SortingLayer.GetLayerValueFromID(b.sortingLayer)
.CompareTo(SortingLayer.GetLayerValueFromID(a.sortingLayer));
if (layerCompare != 0) return layerCompare;
// 再按sorting order
int orderCompare = b.sortingOrder.CompareTo(a.sortingOrder);
if (orderCompare != 0) return orderCompare;
// 最后按depth
return b.depth.CompareTo(a.depth);
});
hoveredUI = allResults[0].gameObject;
string text = $"UI: {hoveredUI.name}, Layer: {SortingLayer.IDToName(allResults[0].sortingLayer)}, Order: {allResults[0].sortingOrder}";
if (UIText.text != text)
{
UIText.text = text;
}
return true;
}
UIText.text = "No UI";
return false;
}
}

View File

@@ -11,7 +11,7 @@ namespace Ichni.Editor
public class OperationManager
{
public List<GameElement> currentSelectedElements { get; private set; }
public TempOutlineModule TempOutlineModule = new TempOutlineModule();
public CopyPasteDeleteModule CopyPasteDeleteModule;
public FindingModule FindingModule;
@@ -59,7 +59,30 @@ namespace Ichni.Editor
currentSelectedElements.Clear();
}
}
public class TempOutlineModule
{
public List<GameElement> outlinedElements;
public Material outlineMaterial => EditorManager.instance.basePrefabs.outlineShaderMaterial;
public TempOutlineModule()
{
outlinedElements = new List<GameElement>();
}
public void AddOutline(GameElement gameElement)
{
outlinedElements.Add(gameElement);
}
public void RemoveOutline(GameElement gameElement)
{
outlinedElements.Remove(gameElement);
}
public void ClearOutline()
{
outlinedElements.Clear();
}
}
public class FindingModule
{
public GameElement FindGameElementByName(string elementName)