GetHashCode()
Obtains the hash code of this NavNode for use in collections.
Read time 1 minuteLast updated 8 hours ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
public override readonly int GetHashCode()
Returns
Type | Description |
|---|---|
| int | The hash code derived from the node identifier, suitable for use in hash-based collections. |
Remarks
The returned value is derived from the internal identifier of the NavNode and is suitable for storing nodes in hash-based collections such as Dictionary_2 or HashSet_1. Two values that compare equal through NavNode.Equals also produce the same hash code.
NavNodeExamples
using System.Collections.Generic;using UnityEngine;using Unity.AI.Navigation.LowLevel;// Move the gameobject and see where each NavMesh polygon gets visited firstpublic class NavNodeHashExample : MonoBehaviour{ readonly Dictionary<NavNode, Vector3> m_FirstSeenAt = new Dictionary<NavNode, Vector3>(); void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(transform.position, 5f * Vector3.one, -1); if (!world.IsValid(location)) { Debug.DrawRay(transform.position, Vector3.up, Color.red); return; } if (!m_FirstSeenAt.ContainsKey(location.node)) m_FirstSeenAt.Add(location.node, location.position); foreach (KeyValuePair<NavNode, Vector3> visited in m_FirstSeenAt) { bool stillValid = world.IsValid(visited.Key); Debug.DrawRay(visited.Value, 0.3f * Vector3.up, stillValid ? Color.cyan : Color.red); } } void OnEnable() { m_FirstSeenAt.Clear(); }}