65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using System;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Effects.Feedback
|
||
{
|
||
/// <summary>
|
||
/// 摄像机方向影响设置,嵌入到摄像机类 Action 中。
|
||
/// 控制最终偏移/振幅是否受摄像机方向和角色朝向影响。
|
||
/// 此类为可扩展设计:新增字段不会导致已有序列化数据重置。
|
||
/// </summary>
|
||
[Serializable]
|
||
public class CameraDirectionSettings
|
||
{
|
||
/// <summary>
|
||
/// 是否将偏移从本地空间转换到摄像机方向空间。
|
||
/// 开启后,定义的振幅向量会根据摄像机的朝向进行旋转。
|
||
/// </summary>
|
||
[LabelText("Affected by Camera Direction")]
|
||
[Tooltip("将偏移从本地空间转换到摄像机方向空间")]
|
||
public bool affectedByCameraDirection;
|
||
|
||
/// <summary>
|
||
/// 是否将偏移从本地空间转换到角色朝向空间。
|
||
/// 开启后,定义的振幅向量会根据 owner(角色)的 forward 进行旋转。
|
||
/// </summary>
|
||
[LabelText("Affected by Character Direction")]
|
||
[Tooltip("将偏移从本地空间转换到角色朝向空间")]
|
||
public bool affectedByCharacterDirection;
|
||
|
||
// === 以下区域留给未来扩展 ===
|
||
// 新增字段时请在此区域添加,并提供合理的默认值,
|
||
// 以确保已有序列化资产不会被重置。
|
||
// 例如:
|
||
// public bool affectedByMovementDirection;
|
||
// public float directionBlendFactor = 1f;
|
||
|
||
/// <summary>
|
||
/// 将给定的本地空间向量根据当前设置转换到世界空间。
|
||
/// 如果两个方向都开启,角色方向优先。
|
||
/// </summary>
|
||
/// <param name="localAmplitude">本地空间下的振幅向量</param>
|
||
/// <param name="ownerTransform">角色 Transform(可能为 null)</param>
|
||
/// <returns>经方向变换后的振幅向量</returns>
|
||
public Vector3 TransformAmplitude(Vector3 localAmplitude, Transform ownerTransform)
|
||
{
|
||
if (affectedByCharacterDirection && ownerTransform != null)
|
||
{
|
||
return ownerTransform.TransformDirection(localAmplitude);
|
||
}
|
||
|
||
if (affectedByCameraDirection)
|
||
{
|
||
Camera mainCamera = Camera.main;
|
||
if (mainCamera != null)
|
||
{
|
||
return mainCamera.transform.TransformDirection(localAmplitude);
|
||
}
|
||
}
|
||
|
||
return localAmplitude;
|
||
}
|
||
}
|
||
}
|