From 3a20747d7ed22cf86ca8b30e96dbdf186e09a8e2 Mon Sep 17 00:00:00 2001 From: "DESKTOP-ME4BAM0\\User" Date: Wed, 25 Nov 2020 23:15:24 +0000 Subject: [PATCH] Custom agents can now be duplicated in the scene --- Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs | 2 +- Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs b/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs index 50db987..db774dd 100644 --- a/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs +++ b/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs @@ -543,7 +543,7 @@ protected override void OnCustomDestroy() void TryCreatingHiddenAgent() { - if (HiddenAgent == null) + if (HiddenAgent == null || !HiddenAgent.IsLinkedWith(this)) { var hiddenObject = new GameObject("(Hidden) " + name); hiddenObject.hideFlags = HideFlags.NotEditable; diff --git a/Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs b/Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs index e13fe44..a13e058 100644 --- a/Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs +++ b/Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs @@ -212,6 +212,16 @@ public void LinkWithCustomAgent(CustomNavMeshAgent customAgent) TrySubscribe(); } + /// + /// Checks if this hidden agent is linked with the specified custom agent. + /// + /// The custom agent. + /// True if the specified agent is indeed the linked one; otherwise, false. + public bool IsLinkedWith(CustomNavMeshAgent customAgent) + { + return CustomAgent == customAgent; + } + protected override void OnCustomEnable() { var meshFilter = GetComponent();