2025-01-29 23:49:18 -05:00
|
|
|
|
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 class LookAt : AnimationBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public TransformSubmodule targetTransformSubmodule;
|
|
|
|
|
|
public BaseElement lookAtObject;
|
|
|
|
|
|
public FlexibleBool enabling;
|
|
|
|
|
|
|
2025-02-02 08:34:54 -05:00
|
|
|
|
public static LookAt GenerateElement(string elementName, Guid id,
|
|
|
|
|
|
List<string> tags, BaseElement targetObject,
|
2025-01-29 23:49:18 -05:00
|
|
|
|
BaseElement lookAtTarget, FlexibleBool enabling)
|
|
|
|
|
|
{
|
2025-02-02 08:34:54 -05:00
|
|
|
|
LookAt look = Instantiate(EditorManager.instance.basePrefabs.emptyObject).AddComponent<LookAt>();
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
2025-02-02 08:34:54 -05:00
|
|
|
|
look.Initialize(elementName, id, tags);
|
|
|
|
|
|
|
|
|
|
|
|
look.targetObject = targetObject;
|
|
|
|
|
|
look.lookAtObject = lookAtTarget;
|
|
|
|
|
|
look.enabling = enabling;
|
|
|
|
|
|
look.animationReturnType = FlexibleReturnType.Before;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
|
|
|
|
|
if (targetObject.transformSubmodule != null)
|
|
|
|
|
|
{
|
2025-02-02 08:34:54 -05:00
|
|
|
|
look.targetTransformSubmodule = targetObject.transformSubmodule;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new System.Exception("Target object does not have a TransformSubmodule");
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
|
|
|
|
|
look.SetParent(targetObject);
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
2025-02-02 08:34:54 -05:00
|
|
|
|
look.timeDurationSubmodule.SetDuration(-999f, 999f); //TODO: 换为(-delay, songLength)
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
2025-02-02 08:34:54 -05:00
|
|
|
|
return look;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|