Skip to content

Commit

Permalink
Custom agents can now be duplicated in the scene
Browse files Browse the repository at this point in the history
  • Loading branch information
jadvrodrigues committed Nov 25, 2020
1 parent f080c7a commit 3a20747
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions Assets/CustomNavMesh/Scripts/HiddenNavMeshAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ public void LinkWithCustomAgent(CustomNavMeshAgent customAgent)
TrySubscribe();
}

/// <summary>
/// Checks if this hidden agent is linked with the specified custom agent.
/// </summary>
/// <param name="customAgent">The custom agent.</param>
/// <returns>True if the specified agent is indeed the linked one; otherwise, false.</returns>
public bool IsLinkedWith(CustomNavMeshAgent customAgent)
{
return CustomAgent == customAgent;
}

protected override void OnCustomEnable()
{
var meshFilter = GetComponent<MeshFilter>();
Expand Down

0 comments on commit 3a20747

Please sign in to comment.