blob: 9f67a3982a4e811ce752c022c8b5cf82376e9ed1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
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 }
|