From 94bc47ea26b62ffff23018249ee0290f39b1e1dc Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Tue, 7 Sep 2021 19:19:03 -0700 Subject: [PATCH] chore!: remove NetworkNavMeshAgent --- .../Components/NetworkNavMeshAgent.cs | 119 ------------------ .../Components/NetworkNavMeshAgent.cs.meta | 11 -- 2 files changed, 130 deletions(-) delete mode 100644 com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs delete mode 100644 com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs.meta diff --git a/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs b/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs deleted file mode 100644 index 7a2e040a6b..0000000000 --- a/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.AI; - -namespace Unity.Netcode.Components -{ - /// - /// A prototype component for syncing NavMeshAgents - /// - [AddComponentMenu("Netcode/" + nameof(NetworkNavMeshAgent))] - [RequireComponent(typeof(NavMeshAgent))] - public class NetworkNavMeshAgent : NetworkBehaviour - { - private NavMeshAgent m_Agent; - - /// - /// Is proximity enabled - /// - public bool EnableProximity = false; - - /// - /// The proximity range - /// - public float ProximityRange = 50f; - - /// - /// The delay in seconds between corrections - /// - public float CorrectionDelay = 3f; - - //TODO rephrase. - /// - /// The percentage to lerp on corrections - /// - [Tooltip("Everytime a correction packet is received. This is the percentage (between 0 & 1) that we will move towards the goal.")] - public float DriftCorrectionPercentage = 0.1f; - - /// - /// Should we warp on destination change - /// - public bool WarpOnDestinationChange = false; - - private void Awake() - { - m_Agent = GetComponent(); - } - - private Vector3 m_LastDestination = Vector3.zero; - private double m_LastCorrectionTime = 0d; - - private void Update() - { - if (!IsOwner) - { - return; - } - - if (m_Agent.destination != m_LastDestination) - { - m_LastDestination = m_Agent.destination; - if (!EnableProximity) - { - OnNavMeshStateUpdateClientRpc(m_Agent.destination, m_Agent.velocity, transform.position); - } - else - { - var proximityClients = new List(); - foreach (KeyValuePair client in NetworkManager.ConnectedClients) - { - if (client.Value.PlayerObject == null || Vector3.Distance(client.Value.PlayerObject.transform.position, transform.position) <= ProximityRange) - { - proximityClients.Add(client.Key); - } - } - - OnNavMeshStateUpdateClientRpc(m_Agent.destination, m_Agent.velocity, transform.position, new ClientRpcParams { Send = new ClientRpcSendParams { TargetClientIds = proximityClients.ToArray() } }); - } - } - - if (NetworkManager.LocalTime.Time - m_LastCorrectionTime >= CorrectionDelay) // TODO this is not aliased correctly, is this an issue? - { - if (!EnableProximity) - { - OnNavMeshCorrectionUpdateClientRpc(m_Agent.velocity, transform.position); - } - else - { - var proximityClients = new List(); - foreach (KeyValuePair client in NetworkManager.ConnectedClients) - { - if (client.Value.PlayerObject == null || Vector3.Distance(client.Value.PlayerObject.transform.position, transform.position) <= ProximityRange) - { - proximityClients.Add(client.Key); - } - } - - OnNavMeshCorrectionUpdateClientRpc(m_Agent.velocity, transform.position, new ClientRpcParams { Send = new ClientRpcSendParams { TargetClientIds = proximityClients.ToArray() } }); - } - - m_LastCorrectionTime = NetworkManager.LocalTime.Time; - } - } - - [ClientRpc] - private void OnNavMeshStateUpdateClientRpc(Vector3 destination, Vector3 velocity, Vector3 position, ClientRpcParams rpcParams = default) - { - m_Agent.Warp(WarpOnDestinationChange ? position : Vector3.Lerp(transform.position, position, DriftCorrectionPercentage)); - m_Agent.SetDestination(destination); - m_Agent.velocity = velocity; - } - - [ClientRpc] - private void OnNavMeshCorrectionUpdateClientRpc(Vector3 velocity, Vector3 position, ClientRpcParams rpcParams = default) - { - m_Agent.Warp(Vector3.Lerp(transform.position, position, DriftCorrectionPercentage)); - m_Agent.velocity = velocity; - } - } -} diff --git a/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs.meta b/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs.meta deleted file mode 100644 index 2accb4974a..0000000000 --- a/com.unity.netcode.gameobjects/Components/NetworkNavMeshAgent.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 43b86c65774f4494ba4e5878d5df9bcd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: