本文整理匯總了C#中Pathfinding.NavGraph類的典型用法代碼示例。如果您正苦於以下問題:C# NavGraph類的具體用法?C# NavGraph怎麽用?C# NavGraph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NavGraph類屬於Pathfinding命名空間,在下文中一共展示了NavGraph類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: OnInspectorGUI
//public GameObject meshRenderer;
public override void OnInspectorGUI (NavGraph target) {
NavMeshGraph graph = target as NavMeshGraph;
/*
#if UNITY_3_3
graph.sourceMesh = EditorGUILayout.ObjectField ("Source Mesh",graph.sourceMesh,typeof(Mesh)) as Mesh;
#else
graph.sourceMesh = EditorGUILayout.ObjectField ("Source Mesh",graph.sourceMesh,typeof(Mesh), true) as Mesh;
#endif
*/
graph.sourceMesh = ObjectField ("Source Mesh", graph.sourceMesh, typeof(Mesh), false) as Mesh;
#if UNITY_LE_4_3
EditorGUIUtility.LookLikeControls ();
EditorGUILayoutx.BeginIndent ();
#endif
graph.offset = EditorGUILayout.Vector3Field ("Offset",graph.offset);
#if UNITY_LE_4_3
EditorGUILayoutx.EndIndent ();
EditorGUILayoutx.BeginIndent ();
#endif
graph.rotation = EditorGUILayout.Vector3Field ("Rotation",graph.rotation);
#if UNITY_LE_4_3
EditorGUILayoutx.EndIndent ();
EditorGUIUtility.LookLikeInspector ();
#endif
graph.scale = EditorGUILayout.FloatField (new GUIContent ("Scale","Scale of the mesh"),graph.scale);
graph.scale = (graph.scale < 0.01F && graph.scale > -0.01F) ? (graph.scale >= 0 ? 0.01F : -0.01F) : graph.scale;
graph.accurateNearestNode = EditorGUILayout.Toggle (new GUIContent ("Accurate Nearest Node Queries","More accurate nearest node queries. See docs for more info"),graph.accurateNearestNode);
}
示例2: OnSceneGUI
public override void OnSceneGUI (NavGraph target) {
//NavMeshGraph graph = target as NavMeshGraph;
/*if (meshRenderer == null) {
Debug.Log ("IsNull");
meshRenderer = new GameObject ("NavmeshRenderer");
meshRenderer.hideFlags = HideFlags.HideAndDontSave;
Renderer renderer = meshRenderer.AddComponent (typeof(MeshRenderer)) as Renderer;
MeshFilter filter = meshRenderer.AddComponent (typeof(MeshFilter)) as MeshFilter;
Mesh mesh = new Mesh ();
mesh.vertices = graph.vertices;
mesh.triangles = graph.triangles;
mesh.RecalculateBounds ();
mesh.RecalculateNormals ();
filter.mesh = mesh;
renderer.material = new Material (Shader.Find ("Transparent/Diffuse"));
renderer.material.color = AstarColor.MeshColor;
} else {
Debug.Log ("Not Null "+meshRenderer.renderer.enabled+" "+meshRenderer.hideFlags);
//meshRenderer.transform.position = new Vector3 (0,5,0);//meshRenderer.transform.position+Vector3.up*0.5F;
meshRenderer.active = false;
meshRenderer.active = true;
}*/
//DrawAALine (Vector3.zero,Vector3.one*20);
}
示例3: ScanGraph
public static void ScanGraph(NavGraph graph)
{
if (AstarPath.OnGraphPreScan != null) {
AstarPath.OnGraphPreScan (graph);
}
graph.Scan ();
int index = AstarPath.active.astarData.GetGraphIndex (graph);
if (index < 0) throw new System.ArgumentException ("Graph is not added to AstarData");
if (graph.nodes != null) {
for (int j=0;j<graph.nodes.Length;j++) {
if (graph.nodes[j] != null)
graph.nodes[j].graphIndex = index;
}
}
if (AstarPath.OnGraphPostScan != null) {
AstarPath.OnGraphPostScan (graph);
}
AstarPath.active.FloodFill ();
AstarPath.active.DataUpdate ();
}
示例4: OnInspectorGUI
public override void OnInspectorGUI (NavGraph target) {
var graph = target as LayerGridGraph;
base.OnInspectorGUI(target);
if (graph.neighbours != NumNeighbours.Four) {
Debug.Log("Note: Only 4 neighbours per grid node is allowed in this graph type");
}
}
示例5: OnInspectorGUI
public override void OnInspectorGUI (NavGraph target) {
var graph = target as NavMeshGraph;
graph.sourceMesh = ObjectField ("Source Mesh", graph.sourceMesh, typeof(Mesh), false) as Mesh;
graph.offset = EditorGUILayout.Vector3Field ("Offset",graph.offset);
graph.rotation = EditorGUILayout.Vector3Field ("Rotation",graph.rotation);
graph.scale = EditorGUILayout.FloatField (new GUIContent ("Scale","Scale of the mesh"),graph.scale);
graph.scale = (graph.scale < 0.01F && graph.scale > -0.01F) ? (graph.scale >= 0 ? 0.01F : -0.01F) : graph.scale;
graph.accurateNearestNode = EditorGUILayout.Toggle (new GUIContent ("Accurate Nearest Node Queries","More accurate nearest node queries. See docs for more info"),graph.accurateNearestNode);
}
示例6: OnEnter
public override void OnEnter()
{
var mo = graph.Value as FsmNavGraph;
if(mo.Value == null)
{
Finish();
return;
} // it would continue for a frame without return
g = FsmConverter.GetNavGraph(graph);
DoStuff();
if (!everyFrame.Value)
{ Finish(); }
}
示例7: OnInspectorGUI
public override void OnInspectorGUI(NavGraph target)
{
var graph = target as PointGraph;
graph.root = ObjectField (new GUIContent ("Root","All childs of this object will be used as nodes, if it is not set, a tag search will be used instead (see below)"),graph.root,typeof(Transform),true) as Transform;
graph.recursive = EditorGUILayout.Toggle (new GUIContent ("Recursive","Should childs of the childs in the root GameObject be searched"),graph.recursive);
graph.searchTag = EditorGUILayout.TagField (new GUIContent ("Tag","If root is not set, all objects with this tag will be used as nodes"),graph.searchTag);
if (graph.root != null) {
EditorGUILayout.HelpBox ("All childs "+(graph.recursive ? "and sub-childs ":"") +"of 'root' will be used as nodes\nSet root to null to use a tag search instead", MessageType.None);
} else {
EditorGUILayout.HelpBox ("All object with the tag '"+graph.searchTag+"' will be used as nodes"+(graph.searchTag == "Untagged" ? "\nNote: the tag 'Untagged' cannot be used" : ""), MessageType.None);
}
graph.maxDistance = EditorGUILayout.FloatField (new GUIContent ("Max Distance","The max distance in world space for a connection to be valid. A zero counts as infinity"),graph.maxDistance);
graph.limits = EditorGUILayout.Vector3Field ("Max Distance (axis aligned)",graph.limits);
graph.raycast = EditorGUILayout.Toggle (new GUIContent ("Raycast","Use raycasting to check if connections are valid between each pair of nodes"),graph.raycast);
if ( graph.raycast ) {
EditorGUI.indentLevel++;
graph.use2DPhysics = EditorGUILayout.Toggle (new GUIContent ("Use 2D Physics", "If enabled, all raycasts will use the Unity 2D Physics API instead of the 3D one."), graph.use2DPhysics);
graph.thickRaycast = EditorGUILayout.Toggle (new GUIContent ("Thick Raycast","A thick raycast checks along a thick line with radius instead of just along a line"),graph.thickRaycast);
if ( graph.thickRaycast ) {
EditorGUI.indentLevel++;
graph.thickRaycastRadius = EditorGUILayout.FloatField (new GUIContent ("Raycast Radius","The radius in world units for the thick raycast"),graph.thickRaycastRadius);
EditorGUI.indentLevel--;
}
graph.mask = EditorGUILayoutx.LayerMaskField ("Mask",graph.mask);
EditorGUI.indentLevel--;
}
graph.optimizeForSparseGraph = EditorGUILayout.Toggle (new GUIContent ("Optimize For Sparse Graph","Check online documentation for more information."),graph.optimizeForSparseGraph);
if ( graph.optimizeForSparseGraph ) {
EditorGUI.indentLevel++;
graph.optimizeFor2D = EditorGUILayout.Toggle (new GUIContent ("Optimize For XZ Plane","Check online documentation for more information."),graph.optimizeFor2D);
EditorGUI.indentLevel--;
}
}
示例8: OnInspectorGUI
public override void OnInspectorGUI (NavGraph target) {
var graph = target as GridGraph;
DrawFirstSection(graph);
Separator();
DrawMiddleSection(graph);
Separator();
DrawCollisionEditor(graph.collision);
if (graph.collision.use2D) {
if (Mathf.Abs(Vector3.Dot(Vector3.forward, Quaternion.Euler(graph.rotation) * Vector3.up)) < 0.9f) {
EditorGUILayout.HelpBox("When using 2D it is recommended to rotate the graph so that it aligns with the 2D plane.", MessageType.Warning);
}
}
Separator();
DrawLastSection(graph);
}
示例9: OnInspectorGUI
public override void OnInspectorGUI (NavGraph target) {
LayerGridGraph graph = target as LayerGridGraph;
graph.mergeSpanRange = EditorGUILayout.FloatField ("Merge Span Range",graph.mergeSpanRange);
graph.characterHeight = EditorGUILayout.FloatField ("Character Height",graph.characterHeight);
graph.maxClimb = Mathf.Clamp (EditorGUILayout.FloatField ("Max climb",graph.maxClimb),0,graph.characterHeight);
graph.neighbours = NumNeighbours.Four;
textureVisible = false;
base.OnInspectorGUI (target);
if (graph.neighbours != NumNeighbours.Four) {
Debug.Log ("Note: Only 4 neighbours per grid node is allowed in this graph type");
}
if (graph.collision.thickRaycast)
HelpBox ("Note: Thick raycast cannot be used with this graph type");
}
示例10: GetNode
/** Returns the node at \a graphs[graphIndex].nodes[nodeIndex]. The graphIndex refers to the specified graphs array.\n
* All kinds of error checking is done to make sure no exceptions are thrown */
public GraphNode GetNode (int graphIndex, int nodeIndex, NavGraph[] graphs) {
throw new System.NotImplementedException ();
/*
if (graphs == null) {
return null;
}
if (graphIndex < 0 || graphIndex >= graphs.Length) {
Debug.LogError ("Graph index is out of range"+graphIndex+ " [0-"+(graphs.Length-1)+"]");
return null;
}
NavGraph graph = graphs[graphIndex];
if (graph.nodes == null) {
return null;
}
if (nodeIndex < 0 || nodeIndex >= graph.nodes.Length) {
Debug.LogError ("Node index is out of range : "+nodeIndex+ " [0-"+(graph.nodes.Length-1)+"]"+" (graph "+graphIndex+")");
return null;
}
return graph.nodes[nodeIndex];*/
}
示例11: RemoveGraph
/** Removes the specified graph from the #graphs array and Destroys it in a safe manner.
* To avoid changing graph indices for the other graphs, the graph is simply nulled in the array instead
* of actually removing it from the array.
* The empty position will be reused if a new graph is added.
*
* \returns True if the graph was sucessfully removed (i.e it did exist in the #graphs array). False otherwise.
*
* \see NavGraph.SafeOnDestroy
*
* \version Changed in 3.2.5 to call SafeOnDestroy before removing
* and nulling it in the array instead of removing the element completely in the #graphs array.
*
*/
public bool RemoveGraph (NavGraph graph) {
//Safe OnDestroy is called since there is a risk that the pathfinding is searching through the graph right now,
//and if we don't wait until the search has completed we could end up with evil NullReferenceExceptions
graph.SafeOnDestroy ();
int i=0;
for (;i<graphs.Length;i++) if (graphs[i] == graph) break;
if (i == graphs.Length) {
return false;
}
graphs[i] = null;
UpdateShortcuts ();
return true;
}
示例12: Serialize
/** Serializes the graph settings to JSON and returns the data */
public byte[] Serialize(NavGraph graph)
{
System.Text.StringBuilder output = GetStringBuilder ();//new System.Text.StringBuilder();
JsonWriter writer = new JsonWriter (output,writerSettings);
writer.Write (graph);
return encoding.GetBytes (output.ToString());
}
示例13: DeSerializeSettings
//This is intended for quick saving of settings for e.g Undo operations
public void DeSerializeSettings(NavGraph graph, AstarPath active)
{
ISerializableGraph serializeGraph = graph as ISerializableGraph;
if (serializeGraph == null) {
Debug.LogError ("The graph specified is not (de)serializable (how it could be serialized in the first place is a mystery) the graph was of type "+graph.GetType());
return;
}
graph.open = readerStream.ReadBoolean ();
//readerStream.ReadString ();
serializeGraph.DeSerializeSettings (this);
}
示例14: DeSerializeEditorSettings
public void DeSerializeEditorSettings(NavGraph graph, ISerializableGraphEditor editor, AstarPath active)
{
if (editor == null) {
Debug.LogError ("The editor specified is Null");
return;
}
editor.DeSerializeSettings (graph,this);
}
示例15: SetUpGraphRefs
public void SetUpGraphRefs(NavGraph[] graphs)
{
graphRefGuids = new int[loadedGraphGuids.Length];
for (int i=0;i<loadedGraphGuids.Length;i++) {
Pathfinding.Util.Guid guid = new Pathfinding.Util.Guid (loadedGraphGuids[i]);
graphRefGuids[i] = -1;
for (int j=0;j<graphs.Length;j++) {
if (graphs[j].guid == guid) {
graphRefGuids[i] = i;
}
}
//graphRefGuids[i] = astarData.GuidToIndex ());
}
}