Files
ichni_Official/Assets/Scripts/Game/Animations/Transform/LookAt.cs
SoulliesOfficial 1bc9af280b 同步
2026-04-03 10:53:11 -04:00

92 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame.Beatmap;
using UniRx;
using UnityEngine;
namespace Ichni.RhythmGame
{
/// <summary>
/// 将物体的z轴指向目标物体注意LookAt的启用期间物体的旋转将被锁定
/// </summary>
public partial class LookAt : AnimationBase
{
#region [] Exposed Fields & References
public GameElement targetGameElement;
public TransformSubmodule targetTransformSubmodule;
public FlexibleBool enabling;
#endregion
#region [] Lifecycle & Factory
public static LookAt GenerateElement(string elementName, Guid id,
List<string> tags, bool isFirstGenerated, GameElement animatedObject,
GameElement lookAtTarget, FlexibleBool enabling)
{
LookAt look = Instantiate(GameManager.Instance.basePrefabs.emptyObject).AddComponent<LookAt>();
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);
}
public override void AfterInitialize()
{
base.AfterInitialize();
}
#endregion
#region [] Core Animation Logic
void LateUpdate()
{
if (enabling.value)
{
(animatedObject as IHaveTransformSubmodule)?.UpdateLookAt(this);
}
}
protected override void UpdateAnimation(float songTime, bool forceUpdate)
{
if (targetGameElement is null) return;
enabling.UpdateFlexibleBool(songTime);
if (!targetTransformSubmodule.eulerAnglesOffsetLock || enabling.value)
{
targetTransformSubmodule.eulerAnglesOffsetLock = enabling.value;
}
if (enabling.value)
{
animationReturnType = FlexibleReturnType.MiddleExecuting;
targetTransformSubmodule.eulerAnglesDirtyMark = true;
}
else if (animationReturnType != FlexibleReturnType.MiddleInterval)
{
animationReturnType = FlexibleReturnType.MiddleInterval;
targetTransformSubmodule.eulerAnglesDirtyMark = true;
}
}
public override void ApplyTimeOffset(float offset)
{
base.ApplyTimeOffset(offset);
enabling.animations.ForEach(anim => anim.ApplyTimeOffset(offset));
}
#endregion
}
}