From 28a7a98a6fd374dee8340cee67689af8f4602d48 Mon Sep 17 00:00:00 2001 From: MuHua-123 <136542559+MuHua-123@users.noreply.github.com> Date: Sat, 7 Jun 2025 16:47:31 +0800 Subject: [PATCH] 1 --- .../ModuleCore/ModuleCamera/ModuleCamera.cs | 19 ---------- Assets/ModuleCore/ModuleTools/Utilities.cs | 37 +++++++++++++++++++ .../ModuleCore/ModuleTools/Utilities.cs.meta | 11 ++++++ 3 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 Assets/ModuleCore/ModuleTools/Utilities.cs create mode 100644 Assets/ModuleCore/ModuleTools/Utilities.cs.meta diff --git a/Assets/ModuleCore/ModuleCamera/ModuleCamera.cs b/Assets/ModuleCore/ModuleCamera/ModuleCamera.cs index 2c094e6..a9616cb 100644 --- a/Assets/ModuleCore/ModuleCamera/ModuleCamera.cs +++ b/Assets/ModuleCore/ModuleCamera/ModuleCamera.cs @@ -27,23 +27,4 @@ public class ModuleCamera : ModuleSingle { /// 重置相机 public void ResetCamera() => cameras.ForEach(obj => obj.ResetCamera()); - /// - /// 转换方向 - /// - /// 相机的前方 - /// 相机的右方 - /// 输入的移动方向 - /// Y轴向上的平面移动方向 - 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; - } } diff --git a/Assets/ModuleCore/ModuleTools/Utilities.cs b/Assets/ModuleCore/ModuleTools/Utilities.cs new file mode 100644 index 0000000..39bdcd2 --- /dev/null +++ b/Assets/ModuleCore/ModuleTools/Utilities.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +/// +/// 实用工具 +/// +public static class Utilities { + + /// 查询场景中的第一个类型 + public static bool FindObject(out T type) where T : UnityEngine.Object { + T[] types = GameObject.FindObjectsOfType(); + type = types.Length > 0 ? types[0] : null; + return type != null; + } + /// 查询场景中的第一个类型 + public static void FindObjects(Action action) where T : UnityEngine.Object { + T[] types = GameObject.FindObjectsOfType(); + for (int i = 0; i < types.Length; i++) { action?.Invoke(types[0]); } + } + + /// 输入方向 转换成 目标的相对方向 + 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; + } +} diff --git a/Assets/ModuleCore/ModuleTools/Utilities.cs.meta b/Assets/ModuleCore/ModuleTools/Utilities.cs.meta new file mode 100644 index 0000000..3ec4ec6 --- /dev/null +++ b/Assets/ModuleCore/ModuleTools/Utilities.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7a13e831656ed54281aff0806b60da4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: