本文整理汇总了C#中Pathfinding.GridGraph类的典型用法代码示例。如果您正苦于以下问题:C# GridGraph类的具体用法?C# GridGraph怎么用?C# GridGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GridGraph类属于Pathfinding命名空间,在下文中一共展示了GridGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawNeighbours
protected override void DrawNeighbours(GridGraph graph)
{
graph.neighbours = NumNeighbours.Four;
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.EnumPopup (new GUIContent ("Connections","Only 4 connections per node is possible on layered grid graphs"),graph.neighbours);
EditorGUI.EndDisabledGroup();
}
示例2: SetGridGraph
public static void SetGridGraph (int graphIndex, GridGraph graph) {
if (_gridGraphs.Length <= graphIndex) {
var gg = new GridGraph[graphIndex+1];
for (int i = 0; i < _gridGraphs.Length; i++) gg[i] = _gridGraphs[i];
_gridGraphs = gg;
}
_gridGraphs[graphIndex] = graph;
}
示例3: DrawMaxClimb
protected override void DrawMaxClimb (GridGraph graph) {
var layerGridGraph = graph as LayerGridGraph;
base.DrawMaxClimb(graph);
layerGridGraph.maxClimb = Mathf.Clamp(layerGridGraph.maxClimb, 0, layerGridGraph.characterHeight);
if (layerGridGraph.maxClimb == layerGridGraph.characterHeight) {
EditorGUILayout.HelpBox("Max climb needs to be smaller or equal to character height", MessageType.Info);
}
}
示例4: DrawMiddleSection
protected override void DrawMiddleSection (GridGraph graph) {
var layerGridGraph = graph as LayerGridGraph;
DrawNeighbours(graph);
layerGridGraph.characterHeight = EditorGUILayout.FloatField("Character Height", layerGridGraph.characterHeight);
DrawMaxClimb(graph);
DrawMaxSlope(graph);
DrawErosion(graph);
layerGridGraph.mergeSpanRange = EditorGUILayout.FloatField("Merge Span Range", layerGridGraph.mergeSpanRange);
}
示例5: DrawFirstSection
void DrawFirstSection (GridGraph graph) {
DrawWidthDepthFields (graph);
newNodeSize = EditorGUILayout.FloatField (new GUIContent ("Node size","The size of a single node. The size is the side of the node square in world units"),graph.nodeSize);
newNodeSize = newNodeSize <= 0.01F ? 0.01F : newNodeSize;
float prevRatio = graph.aspectRatio;
graph.aspectRatio = EditorGUILayout.FloatField (new GUIContent ("Aspect Ratio","Scaling of the nodes width/depth ratio. Good for isometric games"),graph.aspectRatio);
DrawIsometricField(graph);
if (graph.nodeSize != newNodeSize || prevRatio != graph.aspectRatio) {
if (!locked) {
graph.nodeSize = newNodeSize;
Matrix4x4 oldMatrix = graph.matrix;
graph.GenerateMatrix ();
if (graph.matrix != oldMatrix) {
//Rescann the graphs
//AstarPath.active.AutoScan ();
GUI.changed = true;
}
} else {
int tmpWidth = graph.width;
int tmpDepth = graph.depth;
float delta = newNodeSize / graph.nodeSize;
graph.nodeSize = newNodeSize;
graph.unclampedSize = RoundVector3 (new Vector2 (tmpWidth*graph.nodeSize,tmpDepth*graph.nodeSize));
Vector3 newCenter = graph.matrix.MultiplyPoint3x4 (new Vector3 ((tmpWidth/2F)*delta,0,(tmpDepth/2F)*delta));
graph.center = RoundVector3 (newCenter);
graph.GenerateMatrix ();
//Make sure the width & depths stay the same
graph.width = tmpWidth;
graph.depth = tmpDepth;
AutoScan ();
}
}
DrawPositionField(graph);
graph.rotation = EditorGUILayout.Vector3Field ("Rotation", graph.rotation);
if (GUILayout.Button (new GUIContent ("Snap Size","Snap the size to exactly fit nodes"), GUILayout.MaxWidth (100), GUILayout.MaxHeight (16))) {
SnapSizeToNodes (graph.width,graph.depth,graph);
}
}
示例6: SetGridGraph
public static int SetGridGraph(GridGraph graph)
{
if (gridGraphs == null) {
gridGraphs = new GridGraph[1];
} else {
for (int i=0;i<gridGraphs.Length;i++) {
if (gridGraphs[i] == graph) {
return i;
}
}
GridGraph[] tmp = new GridGraph[gridGraphs.Length+1];
for (int i=0;i<gridGraphs.Length;i++) {
tmp[i] = gridGraphs[i];
}
gridGraphs = tmp;
}
gridGraphs[gridGraphs.Length-1] = graph;
return gridGraphs.Length-1;
}
示例7: RemoveGridGraph
public static void RemoveGridGraph(GridGraph graph)
{
if (gridGraphs == null) {
return;
}
for (int i=0;i<gridGraphs.Length;i++) {
if (gridGraphs[i] == graph) {
if (gridGraphs.Length == 1) {
gridGraphs = null;
return;
}
for (int j=i+1;j<gridGraphs.Length;j++) {
GridGraph gg = gridGraphs[j];
if (gg.nodes != null) {
for (int n=0;n<gg.nodes.Length;n++) {
if (gg.nodes[n] != null)
((GridNode)gg.nodes[n]).SetGridIndex (j-1);
}
}
}
GridGraph[] tmp = new GridGraph[gridGraphs.Length-1];
for (int j=0;j<i;j++) {
tmp[j] = gridGraphs[j];
}
for (int j=i+1;j<gridGraphs.Length;j++) {
tmp[j-1] = gridGraphs[j];
}
return;
}
}
}
示例8: SnapSizeToNodes
public void SnapSizeToNodes (int newWidth, int newDepth, GridGraph graph) {
//Vector2 preSize = graph.unclampedSize;
/*if (locked) {
graph.unclampedSize = new Vector2 (newWidth*newNodeSize,newDepth*newNodeSize);
graph.nodeSize = newNodeSize;
graph.GenerateMatrix ();
Vector3 newCenter = graph.matrix.MultiplyPoint3x4 (new Vector3 (newWidth/2F,0,newDepth/2F));
graph.center = newCenter;
AstarPath.active.AutoScan ();
} else {*/
graph.unclampedSize = new Vector2 (newWidth*graph.nodeSize,newDepth*graph.nodeSize);
Vector3 newCenter = graph.matrix.MultiplyPoint3x4 (new Vector3 (newWidth/2F,0,newDepth/2F));
graph.center = newCenter;
graph.GenerateMatrix ();
AstarPath.active.AutoScan ();
//}
GUI.changed = true;
}
示例9: SaveReferenceTexture
public void SaveReferenceTexture (GridGraph graph) {
//GridGraph graph = target as GridGraph;
if (graph.nodes == null || graph.nodes.Length != graph.width * graph.depth) {
AstarPath.active.Scan ();
}
if (graph.nodes.Length != graph.width * graph.depth) {
Debug.LogError ("Couldn't create reference image since width*depth != nodes.Length");
return;
}
if (graph.nodes.Length == 0) {
Debug.LogError ("Couldn't create reference image since the graph is too small (0*0)");
return;
}
Texture2D tex = new Texture2D (graph.width,graph.depth);
float maxY = float.NegativeInfinity;
for (int i=0;i<graph.nodes.Length;i++) {
Vector3 p = graph.inverseMatrix.MultiplyPoint ((Vector3)graph.nodes[i].position);
maxY = p.y > maxY ? p.y : maxY;
}
Color[] cols = new Color[graph.width*graph.depth];
for (int z=0;z<graph.depth;z++) {
for (int x=0;x<graph.width;x++) {
GraphNode node = graph.nodes[z*graph.width+x];
float v = node.Walkable ? 1F : 0.0F;
Vector3 p = graph.inverseMatrix.MultiplyPoint ((Vector3)node.position);
float q = p.y / maxY;
cols[z*graph.width+x] = new Color (v,q,0);
}
}
tex.SetPixels (cols);
tex.Apply ();
string path = AssetDatabase.GenerateUniqueAssetPath ("Assets/gridReference.png");
using (System.IO.StreamWriter outstream = new System.IO.StreamWriter (path)) {
using (System.IO.BinaryWriter outfile = new System.IO.BinaryWriter (outstream.BaseStream)) {
outfile.Write (tex.EncodeToPNG ());
}
}
AssetDatabase.Refresh ();
Object obj = AssetDatabase.LoadAssetAtPath (path,typeof (Texture));
EditorGUIUtility.PingObject (obj);
}
示例10: DrawJPS
protected virtual void DrawJPS (GridGraph graph) {
// Jump point search is a pro only feature
}
示例11: DrawLastSection
void DrawLastSection (GridGraph graph) {
GUILayout.Label (new GUIContent ("Advanced"), EditorStyles.boldLabel);
DrawPenaltyModifications (graph);
DrawJPS (graph);
}
示例12: UpdateShortcuts
public void UpdateShortcuts()
{
navmesh = (NavMeshGraph)FindGraphOfType (typeof(NavMeshGraph));
gridGraph = (GridGraph)FindGraphOfType (typeof(GridGraph));
listGraph = (ListGraph)FindGraphOfType (typeof(ListGraph));
}
示例13: DrawJPS
protected virtual void DrawJPS (GridGraph graph) {
graph.useJumpPointSearch = EditorGUILayout.Toggle(new GUIContent("Use Jump Point Search", "Jump Point Search can significantly speed up pathfinding. But only works on uniformly weighted graphs"), graph.useJumpPointSearch);
if (graph.useJumpPointSearch) {
EditorGUILayout.HelpBox("Jump Point Search assumes that there are no penalties applied to the graph. Tag penalties cannot be used either.", MessageType.Warning);
#if !ASTAR_JPS
EditorGUILayout.HelpBox("JPS needs to be enabled using a compiler directive before it can be used.\n" +
"Enabling this will add ASTAR_JPS to the Scriping Define Symbols field in the Unity Player Settings", MessageType.Warning);
if (GUILayout.Button("Enable Jump Point Search support")) {
OptimizationHandler.EnableDefine("ASTAR_JPS");
}
#endif
} else {
#if ASTAR_JPS
EditorGUILayout.HelpBox("If you are not using JPS in any scene, you can disable it to save memory", MessageType.Info);
if (GUILayout.Button("Disable Jump Point Search support")) {
OptimizationHandler.DisableDefine("ASTAR_JPS");
}
#endif
}
}
示例14: DrawCutCorners
protected virtual void DrawCutCorners (GridGraph graph) {
graph.cutCorners = EditorGUILayout.Toggle(new GUIContent("Cut Corners", "Enables or disables cutting corners. See docs for image example"), graph.cutCorners);
if (!graph.cutCorners && graph.useJumpPointSearch) {
EditorGUILayout.HelpBox("Jump Point Search only works if 'Cut Corners' is enabled.", MessageType.Error);
}
}
示例15: DrawCutCorners
protected override void DrawCutCorners (GridGraph graph) {
// No corner cutting since only 4 neighbours are possible
}