This commit is contained in:
2026-06-09 20:20:30 +08:00
parent 40a37aa731
commit 7ee6a1cd92
34 changed files with 253 additions and 219 deletions
@@ -347,45 +347,128 @@ public class MonsterContral : MonoBehaviour
/// 为空时 2D 鱼用 up,3D 鱼用 forward。
/// </summary>
/// <param name="nextPos">下一帧目标位置</param>
//private void ApplyFacingDirection(Vector2 nextPos)
//{
// if (!isRotate) return;
// Vector2 toNext = nextPos - (Vector2)transform.position;
// if (toNext.sqrMagnitude < 0.0001f) return; // 避免零向量
// if (string.IsNullOrEmpty(forwordXYZ))
// {
// if (!is3D)
// {
// // 2D 用 up,推荐用 Quaternion.AngleAxis
// float angle = Mathf.Atan2(toNext.y, toNext.x) * Mathf.Rad2Deg;
// transform.rotation = Quaternion.AngleAxis(angle - 90f, Vector3.forward);
// }
// else
// {
// // 3D 用 forward,推荐用 LookRotation
// transform.rotation = Quaternion.LookRotation(toNext.normalized, Vector3.up);
// }
// return;
// }
// if (monsterData.fishTypeConfig.fishNumber=="11024")
// {
// }
// //if (ischild0)
// //{
// // switch (forwordXYZ)
// // {
// // case "X": transform.GetChild(0).right = toNext.normalized; break;
// // case "-X": transform.GetChild(0).right = -toNext.normalized; break;
// // case "Y": transform.GetChild(0).up = toNext.normalized; break;
// // case "-Y": transform.GetChild(0).up = -toNext.normalized; break;
// // case "Z": transform.GetChild(0).forward = toNext.normalized; break;
// // case "-Z": transform.GetChild(0).forward = -toNext.normalized; break;
// // }
// //}
// //else
// {
// switch (forwordXYZ)
// {
// case "X": transform.right = toNext.normalized; break;
// case "-X": transform.right = -toNext.normalized; break;
// case "Y": transform.up = toNext.normalized; break;
// case "-Y": transform.up = -toNext.normalized; break;
// case "Z": transform.forward = toNext.normalized; break;
// case "-Z": transform.forward = -toNext.normalized; break;
// }
// }
//}
private void ApplyFacingDirection(Vector2 nextPos)
{
if (!isRotate) return;
Vector2 toNext = nextPos - (Vector2)transform.position;
if (toNext.sqrMagnitude < 0.0001f) return;
if (toNext.sqrMagnitude < 0.0001f) return; // 避免零向量
// 处理未指定朝向轴的情况(默认行为)
if (string.IsNullOrEmpty(forwordXYZ))
{
if (!is3D)
{
// 2D 用 up,推荐用 Quaternion.AngleAxis
float angle = Mathf.Atan2(toNext.y, toNext.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle - 90f, Vector3.forward);
}
else
{
// 3D 用 forward,推荐用 LookRotation
transform.rotation = Quaternion.LookRotation(toNext.normalized, Vector3.up);
}
return;
}
if (monsterData.fishTypeConfig.fishNumber=="11024")
// 是否为子物体单独控制朝向和深度
if (ischild0)
{
Transform child = transform.GetChild(0);
Vector3 localPos = Vector3.zero;
// 父物体朝向
switch (forwordXYZ)
{
case "X": transform.right = toNext.normalized; break;
case "-X": transform.right = -toNext.normalized; break;
case "Y": transform.up = toNext.normalized; break;
case "-Y": transform.up = -toNext.normalized; break;
case "Z": transform.forward = toNext.normalized; break;
case "-Z": transform.forward = -toNext.normalized; break;
}
// 子物体深度偏移:方向正 → 偏移正,方向负 → 偏移负
switch (forwordXYZ)
{
case "X": localPos.z = depthOffset; break;
case "-X": localPos.z = -depthOffset; break;
case "Y": localPos.x = depthOffset; break;
case "-Y": localPos.x = -depthOffset; break;
case "Z": localPos.x = depthOffset; break;
case "-Z": localPos.x = -depthOffset; break;
}
child.localPosition = localPos;
}
switch (forwordXYZ)
else
{
case "X": transform.right = toNext.normalized; break;
case "-X": transform.right = -toNext.normalized; break;
case "Y": transform.up = toNext.normalized; break;
case "-Y": transform.up = -toNext.normalized; break;
case "Z": transform.forward = toNext.normalized; break;
case "-Z": transform.forward = -toNext.normalized; break;
// 控制父物体自身朝向
switch (forwordXYZ)
{
case "X": transform.right = toNext.normalized; break;
case "-X": transform.right = -toNext.normalized; break;
case "Y": transform.up = toNext.normalized; break;
case "-Y": transform.up = -toNext.normalized; break;
case "Z": transform.forward = toNext.normalized; break;
case "-Z": transform.forward = -toNext.normalized; break;
}
}
}
public bool ischild0 = false;
public int depthOffset;
// ================================================================
// 动画
// ================================================================