Files
ichni_Creator_Studio/Assets/Scripts/Animations/Transform/LookAt.cs
SoulliesOfficial bc1c5d65ef 基础内容-8
添加BM存档类
2025-02-02 21:59:43 -05:00

114 lines
4.0 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 Lean.Pool;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ichni.RhythmGame
{
/// <summary>
/// 将物体的z轴指向目标物体注意LookAt的启用期间物体的旋转将被锁定
/// </summary>
public partial class LookAt : AnimationBase
{
public TransformSubmodule targetTransformSubmodule;
public BaseElement lookAtObject;
public FlexibleBool enabling;
public static LookAt GenerateElement(string elementName, Guid id,
List<string> tags, BaseElement targetObject,
BaseElement lookAtTarget, FlexibleBool enabling)
{
LookAt look = Instantiate(EditorManager.instance.basePrefabs.emptyObject).AddComponent<LookAt>();
look.Initialize(elementName, id, tags);
look.targetObject = targetObject;
look.lookAtObject = lookAtTarget;
look.enabling = enabling;
look.animationReturnType = FlexibleReturnType.Before;
if (targetObject.transformSubmodule != null)
{
look.targetTransformSubmodule = targetObject.transformSubmodule;
}
else
{
throw new System.Exception("Target object does not have a TransformSubmodule");
}
look.SetParent(targetObject);
look.timeDurationSubmodule.SetDuration(-999f, 999f); //TODO: 换为(-delay, songLength)
return look;
}
private void Start()
{
targetTransformSubmodule = targetObject.transformSubmodule;
}
protected override void UpdateAnimation(float songTime)
{
enabling.UpdateFlexibleBool(songTime);
if (enabling.value)
{
animationReturnType = FlexibleReturnType.MiddleExecuting;
Vector3 lookingDirection =
(lookAtObject.transform.position - targetObject.transform.position).normalized;
Vector3 eulerAnglesOffset = Quaternion.LookRotation(lookingDirection).eulerAngles;
targetTransformSubmodule.eulerAnglesOffsetLock = true;
targetTransformSubmodule.currentEulerAngles = eulerAnglesOffset;
}
else
{
animationReturnType = FlexibleReturnType.MiddleInterval;
targetTransformSubmodule.eulerAnglesOffsetLock = false;
}
}
public override void SaveBM()
{
matchedBM = new Beatmap.LookAt_BM(elementName, elementGuid, tags, parentElement.matchedBM,
enabling.ConvertToBM(), lookAtObject.elementGuid);
}
}
namespace Beatmap
{
public class LookAt_BM : BaseElement_BM
{
public FlexibleBool_BM enabling;
public Guid lookAtObjectGuid;
public LookAt_BM()
{
}
public LookAt_BM(string elementName, Guid elementGuid, List<string> tags,
BaseElement_BM attachedElement, FlexibleBool_BM enabling, Guid lookAtObjectGuid) : base(elementName,
elementGuid, tags, attachedElement)
{
this.enabling = enabling;
this.lookAtObjectGuid = lookAtObjectGuid;
}
public override void ExecuteBM()
{
matchedElement = LookAt.GenerateElement(elementName, elementGuid, tags,
GetElement(attachedElementGuid), GetElement(lookAtObjectGuid), enabling.ConvertToGameType());
}
public override BaseElement DuplicateBM(BaseElement parent)
{
return LookAt.GenerateElement(elementName, elementGuid, tags, parent,
GetElement(lookAtObjectGuid), enabling.ConvertToGameType());
}
}
}
}