From 3eb3f73381ec6dea7cc4e559c8c168423b9ba07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=8D=B4?= <479813005@qq.com> Date: Mon, 21 Aug 2023 21:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BC=E8=88=AA=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E8=B0=83=E8=AF=95=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RuntimeRenderer/NavMeshAgentVisualizer.cs | 122 ++++++++++++++++++ .../NavMeshAgentVisualizer.cs.meta | 11 ++ .../AnimatorExtension.cs | 5 + 3 files changed, 138 insertions(+) create mode 100644 Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs create mode 100644 Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs.meta diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs new file mode 100644 index 0000000..b610c2d --- /dev/null +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs @@ -0,0 +1,122 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; +using System.ComponentModel; + +#if DrawXXL + +namespace DrawXXL +{ + [DefaultExecutionOrder(8000)] + public class NavMeshAgentVisualizer : MonoBehaviour + { + NavMeshAgent MeshAgent; + public bool velocity = false; + // Start is called before the first frame update + void Awake() + { + MeshAgent = GetComponent(); + } + + //private void FixedUpdate() + //{ + // var oldSpeed = MeshAgent.speed; + // for (int i = 0; i < 10; i++) + // { + // MeshAgent.speed = i; + // DrawBasics.Point(MeshAgent.nextPosition, text: $"SpeedTest Speed:{MeshAgent.speed}", + // Color.cyan); + // } + // MeshAgent.speed = oldSpeed; + //} + + // Update is called once per frame + void Update() + { + if (!MeshAgent) + { + return; + } + + if (velocity) + { + DrawBasics.VectorFrom(MeshAgent.transform.position, MeshAgent.velocity, Color.blue, text: $"NavMeshAgent.velocity {MeshAgent.velocity}"); + } + + DrawBasics.PointTag(MeshAgent.destination, + $"{MeshAgent.name}.destination", + Color.red); + + DrawBasics.PointTag(MeshAgent.nextPosition, + $"NavMeshAgent.NextPosition. Speed:{MeshAgent.speed}", + Color.green); + + if (MeshAgent.path != null && MeshAgent.hasPath) + { + var c = MeshAgent.path.corners; + int length = c.Length; + if (length > 0) + { + //DrawBasics.Line(MeshAgent.transform.position, c[0], Color.green); + + for (int i = 0; i < length; i++) + { + DrawBasics.Point(c[i], Color.yellow, text: $"{i}"); + if (i < length - 1) + { + DrawBasics.Line(c[i], c[i + 1], Color.red); + } + } + + if (c[length - 1] != MeshAgent.destination) + { + DrawBasics.PointTag(c[length - 1], text: $"{MeshAgent.name}.path", Color.red); + } + } + + } + } + + //private void LateUpdate() + //{ + // //MeshAgent.Warp(transform.position); + // MeshAgent.nextPosition = transform.position; + //} + + [Editor] + public void SetUpdatePosition(bool value) + { + MeshAgent.updatePosition = value; + MeshAgent.updateRotation = value; + //MeshAgent.updateUpAxis = value; + } + + [Editor] + public void SetDestination(Vector3 offset) + { + MeshAgent.SetDestination(transform.position + offset); + } + } + + public static class Extension_DrawXXL_35AA76C28B2E48F4A9058A191EF29144 + { + public static void DrawXXL(this Vector3[] vector3s) + { + if (vector3s.Length < 2) + { + return; + } + for (int i = 0; i < vector3s.Length; i++) + { + DrawBasics.Point(vector3s[i], Color.yellow, text: $"{i}"); + if (i < vector3s.Length - 1) + { + DrawBasics.Line(vector3s[i], vector3s[i + 1], Color.red); + } + } + } + } +} + +#endif diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs.meta b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs.meta new file mode 100644 index 0000000..06507eb --- /dev/null +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/NewClass/RuntimeRenderer/NavMeshAgentVisualizer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ebd6b9a8b16a214cbb90c60a96e7e1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/UnityEngineExtensionMethod/AnimatorExtension.cs b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/UnityEngineExtensionMethod/AnimatorExtension.cs index fca11b5..40e22ee 100644 --- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/UnityEngineExtensionMethod/AnimatorExtension.cs +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Runtime/Scripts/UnityEngineExtensionMethod/AnimatorExtension.cs @@ -48,8 +48,13 @@ public static float GetOnAnimatorMoveTime(this Animator animator) { case AnimatorUpdateMode.Normal: return Time.deltaTime; +#if UNITY_2023_1_OR_NEWER case AnimatorUpdateMode.Fixed: return Time.deltaTime; +#else + case AnimatorUpdateMode.AnimatePhysics: + return Time.deltaTime; +#endif case AnimatorUpdateMode.UnscaledTime: return Time.unscaledDeltaTime; default: