C++RAW

#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/NavMesh/NavMesh.h"
#include "Runtime/NavMesh/NavMeshPath.h"
#include "Runtime/NavMesh/NavMeshSettings.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#include "Runtime/Mono/MonoManager.h"

CSRAW

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace UnityEngine
{

// Keep this enum in sync with the one defined in "NavMeshPath.h"
// Status of path.
ENUM NavMeshPathStatus
	// The path terminates at the destination.
	PathComplete = 0,
	
	// The path cannot reach the destination.
	PathPartial = 1,

	// The path is invalid.
	PathInvalid = 2
END

CSRAW
[StructLayout (LayoutKind.Sequential)]
// Path navigation.
CLASS NavMeshPath
	CSRAW internal IntPtr m_Ptr;
	CSRAW internal Vector3[] m_corners;

	C++RAW

#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
	#define GET ExtractMonoObjectData<NavMeshPath*>(self)
#else
	inline NavMeshPath* GetNativeNavMeshPath (ScriptingObjectPtr self)
	{
		MonoNavMeshPath managedpath;
		MarshallManagedStructIntoNative (self, &managedpath);
		return managedpath.native;
	}
	#define GET GetNativeNavMeshPath (self)
#endif
	

	// NavMeshPath constructor.
	CUSTOM NavMeshPath ()
	{
		MonoNavMeshPath managedPath;
		managedPath.native = new NavMeshPath ();
		MarshallNativeStructIntoManaged (managedPath,self);
	}

	THREAD_SAFE
	CUSTOM private void DestroyNavMeshPath ()
	{
		if (GET)
		{
			delete GET;
		}
	}

	CSRAW ~NavMeshPath ()
	{
		DestroyNavMeshPath ();
		m_Ptr = IntPtr.Zero;
	}

	CUSTOM private Vector3[] CalculateCornersInternal ()
	{
		NavMesh* navMesh = GetNavMeshSettings ().GetNavMesh ();
		if (navMesh == NULL)
			return CreateEmptyStructArray (GetMonoManager ().GetCommonClasses ().vector3);

		const int polygonCount = GET->GetPolygonCount ();
		if (polygonCount == 0)
			return CreateEmptyStructArray (GetMonoManager ().GetCommonClasses ().vector3);

		Vector3f* corners;
		ALLOC_TEMP (corners, Vector3f, 2+polygonCount);

		NavMeshPath* path = GET;
		int cornerCount = navMesh->CalculatePathCorners (corners, 2+polygonCount, *path);
		if (cornerCount == 0)
			return CreateEmptyStructArray (GetMonoManager ().GetCommonClasses ().vector3);

		return CreateScriptingArray<Vector3f>(corners, cornerCount, GetMonoManager ().GetCommonClasses ().vector3);
	}

	CUSTOM private void ClearCornersInternal ()
	{
		GET->SetPolygonCount (0);
	}

	// Erase all corner points from path.
	CSRAW public void ClearCorners ()
	{
		ClearCornersInternal ();
		m_corners = null;
	}

	CSRAW private void CalculateCorners ()
	{
		if (m_corners == null)
			m_corners = CalculateCornersInternal ();
	}

	// Corner points of path. (RO)
	CSRAW public Vector3[] corners { get { CalculateCorners (); return m_corners;} }

	// Status of the path. (RO)
	CUSTOM_PROP NavMeshPathStatus status
	{
		return GET->GetStatus ();
	}

	C++RAW
 #undef GET
END

CSRAW }