This commit is contained in:
MuHua-123
2025-06-07 16:47:31 +08:00
parent 15b58a00f1
commit 28a7a98a6f
3 changed files with 48 additions and 19 deletions
@@ -27,23 +27,4 @@ public class ModuleCamera : ModuleSingle<ModuleCamera> {
/// <summary> 重置相机 </summary>
public void ResetCamera() => cameras.ForEach(obj => obj.ResetCamera());
/// <summary>
/// 转换方向
/// </summary>
/// <param name="forward">相机的前方</param>
/// <param name="right">相机的右方</param>
/// <param name="moveInput">输入的移动方向</param>
/// <returns>Y轴向上的平面移动方向</returns>
public static Vector3 TransferDirection(Vector3 forward, Vector3 right, Vector2 moveInput) {
// 确保前方和右方方向在水平面上
forward.y = 0;
right.y = 0;
// 归一化方向向量
forward.Normalize();
right.Normalize();
// 计算移动方向
return (forward * moveInput.y + right * moveInput.x).normalized;
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 实用工具
/// </summary>
public static class Utilities {
/// <summary> 查询场景中的第一个类型 </summary>
public static bool FindObject<T>(out T type) where T : UnityEngine.Object {
T[] types = GameObject.FindObjectsOfType<T>();
type = types.Length > 0 ? types[0] : null;
return type != null;
}
/// <summary> 查询场景中的第一个类型 </summary>
public static void FindObjects<T>(Action<T> action) where T : UnityEngine.Object {
T[] types = GameObject.FindObjectsOfType<T>();
for (int i = 0; i < types.Length; i++) { action?.Invoke(types[0]); }
}
/// <summary> 输入方向 转换成 目标的相对方向 </summary>
public static Vector3 TransferDirection(Vector3 forward, Vector3 right, Vector2 inputDirection) {
// 确保前方和右方方向在水平面上
forward.y = 0;
right.y = 0;
// 归一化方向向量
forward.Normalize();
right.Normalize();
// 计算移动方向
return (forward * inputDirection.y + right * inputDirection.x).normalized;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c7a13e831656ed54281aff0806b60da4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: