2025-06-03 02:42:28 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Ichni.RhythmGame.Beatmap;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
using UniRx;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 将物体的z轴指向目标物体,注意,LookAt的启用期间,物体的旋转将被锁定
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class LookAt : AnimationBase
|
|
|
|
|
|
{
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#region [暴露属性字段与关联] Exposed Fields & References
|
2025-06-03 02:42:28 -04:00
|
|
|
|
public GameElement targetGameElement;
|
|
|
|
|
|
public TransformSubmodule targetTransformSubmodule;
|
|
|
|
|
|
public FlexibleBool enabling;
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#region [生命周期与工厂] Lifecycle & Factory
|
2025-06-03 02:42:28 -04:00
|
|
|
|
public static LookAt GenerateElement(string elementName, Guid id,
|
|
|
|
|
|
List<string> tags, bool isFirstGenerated, GameElement animatedObject,
|
|
|
|
|
|
GameElement lookAtTarget, FlexibleBool enabling)
|
|
|
|
|
|
{
|
2026-03-14 03:13:10 -04:00
|
|
|
|
LookAt look = Instantiate(GameManager.Instance.basePrefabs.emptyObject).AddComponent<LookAt>();
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
|
|
look.Initialize(elementName, id, tags, isFirstGenerated, animatedObject);
|
|
|
|
|
|
|
|
|
|
|
|
look.animatedObject = animatedObject;
|
|
|
|
|
|
look.enabling = enabling;
|
|
|
|
|
|
look.animationReturnType = FlexibleReturnType.Before;
|
|
|
|
|
|
|
|
|
|
|
|
look.targetGameElement = lookAtTarget;
|
|
|
|
|
|
look.targetTransformSubmodule = (animatedObject as IHaveTransformSubmodule).transformSubmodule;
|
|
|
|
|
|
//look.timeDurationSubmodule.SetDuration(-999f, 999f); //TODO: 换为(-delay, songLength)
|
|
|
|
|
|
return look;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void SetDefaultSubmodules()
|
|
|
|
|
|
{
|
|
|
|
|
|
timeDurationSubmodule = new TimeDurationSubmodule(this);
|
|
|
|
|
|
}
|
2026-04-03 10:53:11 -04:00
|
|
|
|
|
|
|
|
|
|
public override void AfterInitialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.AfterInitialize();
|
2026-06-05 04:45:57 -04:00
|
|
|
|
// 注册 Phase 7(Effect),确保在 Track/TrackFollower(Phase 4/5)和 Note(Phase 6)
|
|
|
|
|
|
// 全部更新完毕后再计算旋转覆盖,避免因位置尚未就绪导致的旋转抖动
|
|
|
|
|
|
CoreServices.UpdateScheduler.Register(UpdatePhase.Effect, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDelete()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDelete();
|
|
|
|
|
|
CoreServices.UpdateScheduler.Unregister(UpdatePhase.Effect, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ManualUpdate(float songTime, bool forceUpdate = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ManualUpdate(songTime, forceUpdate);
|
|
|
|
|
|
// 动画结束时同步注销 Phase 7
|
|
|
|
|
|
if (timeDurationSubmodule.CheckAfterEndTime(songTime))
|
|
|
|
|
|
{
|
|
|
|
|
|
CoreServices.UpdateScheduler.Unregister(UpdatePhase.Effect, this);
|
|
|
|
|
|
}
|
2026-04-03 10:53:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#endregion
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#region [核心动画逻辑] Core Animation Logic
|
2026-06-05 04:45:57 -04:00
|
|
|
|
public override void ScheduledUpdate(UpdatePhase phase, float songTime)
|
2025-07-21 05:42:20 -04:00
|
|
|
|
{
|
2026-06-05 04:45:57 -04:00
|
|
|
|
switch (phase)
|
2025-07-21 05:42:20 -04:00
|
|
|
|
{
|
2026-06-05 04:45:57 -04:00
|
|
|
|
case UpdatePhase.Animation:
|
|
|
|
|
|
base.ScheduledUpdate(phase, songTime);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UpdatePhase.Effect:
|
|
|
|
|
|
// 在所有 Track/TrackFollower/Note 位置更新完毕后覆盖旋转
|
|
|
|
|
|
if (enabling.value)
|
|
|
|
|
|
{
|
|
|
|
|
|
(animatedObject as IHaveTransformSubmodule)?.UpdateLookAt(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
2026-04-03 10:53:11 -04:00
|
|
|
|
protected override void UpdateAnimation(float songTime, bool forceUpdate)
|
2025-06-03 02:42:28 -04:00
|
|
|
|
{
|
2025-08-11 14:04:06 -04:00
|
|
|
|
if (targetGameElement is null) return;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
|
enabling.UpdateFlexibleBool(songTime);
|
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
|
if (!targetTransformSubmodule.eulerAnglesOffsetLock || enabling.value)
|
|
|
|
|
|
{
|
|
|
|
|
|
targetTransformSubmodule.eulerAnglesOffsetLock = enabling.value;
|
|
|
|
|
|
}
|
2026-04-03 10:53:11 -04:00
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
|
if (enabling.value)
|
|
|
|
|
|
{
|
|
|
|
|
|
animationReturnType = FlexibleReturnType.MiddleExecuting;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
targetTransformSubmodule.eulerAnglesDirtyMark = true;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
}
|
2025-08-11 14:04:06 -04:00
|
|
|
|
else if (animationReturnType != FlexibleReturnType.MiddleInterval)
|
2025-06-03 02:42:28 -04:00
|
|
|
|
{
|
|
|
|
|
|
animationReturnType = FlexibleReturnType.MiddleInterval;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
targetTransformSubmodule.eulerAnglesDirtyMark = true;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ApplyTimeOffset(float offset)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ApplyTimeOffset(offset);
|
|
|
|
|
|
enabling.animations.ForEach(anim => anim.ApplyTimeOffset(offset));
|
|
|
|
|
|
}
|
2026-03-14 03:13:10 -04:00
|
|
|
|
#endregion
|
2025-06-03 02:42:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|