Пример использования
Ниже приведен пример использования объекта Path для нахождения пути между А и В
using Nav3D.API;
using System;
using System.Linq;
using UnityEngine;
class YourGameScenario : MonoBehaviour
{
#region Attributes
Vector3[] m_FoundPath;
#endregion
#region Unity events
private void Start()
{
Nav3DManager.OnNav3DInit += () =>
{
Vector3 a = new Vector3(-10, -10, -10);
Vector3 b = new Vector3(10, 10, 10);
FindPath(a, b, PrintPath);
};
}
private void OnDrawGizmos()
{
if (!Application.isPlaying || !enabled)
return;
if (m_FoundPath != null && m_FoundPath.Any())
{
for (int i = 0; i < m_FoundPath.Length - 1; i++)
Gizmos.DrawLine(m_FoundPath[i], m_FoundPath[i + 1]);
}
}
#endregion
#region Service methods
//your method for pathfinding from A to B
void FindPath(Vector3 _A, Vector3 _B, Action _OnPathFound)
{
//create Path instance
Path path = Nav3DPathfindingManager.PrefetchPath(_A, _B);
//perform pathfinding from _A to _B
path.UpdatePath(_OnSuccess: () =>
{
//notify that path was found
Debug.Log("Path successfully found!");
//invoke callback
_OnPathFound(path.Trajectory);
//finish work with Path instance
path.Dispose();
});
}
void PrintPath(Vector3[] _Path)
{
m_FoundPath = _Path;
Debug.Log($"Path points: {string.Join(", ", m_FoundPath)}");
}
#endregion
}