Equals
Checks whether this NavNode refers to the same navigation node as another.
Read time 2 minutesLast updated 8 hours ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
Equals(NavNode)
Checks whether this refers to the same navigation node as another.
NavNodepublic readonly bool Equals(NavNode other)
Parameters
A to compare this one with.
NavNodeReturns
Type | Description |
|---|---|
| bool | |
Remarks
The comparison uses the internal identifier of the node. Two NavNode values are equal even if they refer to a node that has since been removed from the NavMesh, because the identifier itself doesn't change. Use NavWorld.IsValid to determine whether the node is still active in the NavMesh.
Examples
using UnityEngine;using Unity.AI.Navigation.LowLevel;// Move the gameobject and see whether it maps to a different NavMesh nodepublic class NavNodeEqualsExample : MonoBehaviour{ Vector3 m_Anchor; void OnEnable() { m_Anchor = transform.position; } void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation here = world.MapLocation(transform.position, 5f * Vector3.one, -1); NavLocation there = world.MapLocation(m_Anchor, 5f * Vector3.one, -1); if (world.IsValid(here) && world.IsValid(there)) { bool sameNode = here.node.Equals(there.node); Debug.DrawLine(here.position, there.position, sameNode ? Color.green : Color.orange); } else { Debug.DrawLine(transform.position, m_Anchor, Color.red); } if (Time.frameCount % 100 == 0) m_Anchor = transform.position; }}
Equals(Object)
Checks whether this refers to the same navigation node as another.
NavNodepublic override readonly bool Equals(object obj)
Parameters
An object to interpret as a and to compare this one with.
NavNodeReturns
Type | Description |
|---|---|
| bool | |
Remarks
The comparison uses the internal identifier of the node. Two NavNode values are equal even if they refer to a node that has since been removed from the NavMesh, because the identifier itself doesn't change. Use NavWorld.IsValid to determine whether the node is still active in the NavMesh.
Examples
using UnityEngine;using Unity.AI.Navigation.LowLevel;// Move the gameobject and see whether it maps to a different NavMesh nodepublic class NavNodeEqualsExample : MonoBehaviour{ Vector3 m_Anchor; void OnEnable() { m_Anchor = transform.position; } void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation here = world.MapLocation(transform.position, 5f * Vector3.one, -1); NavLocation there = world.MapLocation(m_Anchor, 5f * Vector3.one, -1); if (world.IsValid(here) && world.IsValid(there)) { bool sameNode = here.node.Equals(there.node); Debug.DrawLine(here.position, there.position, sameNode ? Color.green : Color.orange); } else { Debug.DrawLine(transform.position, m_Anchor, Color.red); } if (Time.frameCount % 100 == 0) m_Anchor = transform.position; }}