本文整理汇总了C#中NavGraph类的典型用法代码示例。如果您正苦于以下问题:C# NavGraph类的具体用法?C# NavGraph怎么用?C# NavGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NavGraph类属于命名空间,在下文中一共展示了NavGraph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OnInspectorGUI
public override void OnInspectorGUI(NavGraph target) {
MyAStarPointGraph graph = target as MyAStarPointGraph;
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);
EditorGUILayoutx.BeginIndent();
graph.limits = EditorGUILayout.Vector3Field("Max Distance (axis aligned)", graph.limits);
EditorGUILayoutx.EndIndent();
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.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) {
graph.thickRaycastRadius = EditorGUILayout.FloatField(new GUIContent("Raycast Radius", "The radius in world units for the thick raycast"), graph.thickRaycastRadius);
}
graph.mask = EditorGUILayoutx.LayerMaskField(/*new GUIContent (*/"Mask"/*,"Used to mask which layers should be checked")*/, graph.mask);
EditorGUI.indentLevel--;
}
}
开发者ID:Maxii,项目名称:CodeEnv.Master,代码行数:25,代码来源:MyAStarPointGraphEditor.cs
示例2: 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;
EditorGUIUtility.LookLikeControls ();
EditorGUILayoutx.BeginIndent ();
graph.offset = EditorGUILayout.Vector3Field ("Offset",graph.offset);
EditorGUILayoutx.EndIndent ();
EditorGUILayoutx.BeginIndent ();
graph.rotation = EditorGUILayout.Vector3Field ("Rotation",graph.rotation);
EditorGUILayoutx.EndIndent ();
EditorGUIUtility.LookLikeInspector ();
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);
}
开发者ID:shreshtabm,项目名称:Fight-for-Zion-Mobile-Game,代码行数:29,代码来源:NavMeshGeneratorEditor.cs
示例3: 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);
}
开发者ID:shreshtabm,项目名称:Fight-for-Zion-Mobile-Game,代码行数:33,代码来源:NavMeshGeneratorEditor.cs
示例4: ExportToFile
/** Exports the INavmesh graph to a file */
public void ExportToFile(NavGraph target)
{
INavmesh graph = (INavmesh)target;
if (graph == null) return;
Int3[] vertices = graph.vertices;
if (vertices == null || target.nodes == null) {
if (EditorUtility.DisplayDialog ("Scan graph before exporting?","The graph does not contain any mesh data. Do you want to scan it?","Ok","Cancel")) {
AstarPath.MenuScan ();
} else {
return;
}
}
vertices = graph.vertices;
if (vertices == null || target.nodes == null) {
Debug.LogError ("Graph still does not contain any nodes or vertices. Canceling");
return;
}
string path = EditorUtility.SaveFilePanel ("Export .obj","","navmesh.obj","obj");
if (path == "") return;
//Generate .obj
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string name = System.IO.Path.GetFileNameWithoutExtension (path);
sb.Append ("g ").Append(name).AppendLine();
//Write vertices
for (int i=0;i<vertices.Length;i++) {
Vector3 v = (Vector3)vertices[i];
sb.Append(string.Format("v {0} {1} {2}\n",-v.x,v.y,v.z));
}
//Define single texture coordinate to zero
sb.Append ("vt 0\n");
//Write triangles
for (int i=0;i<target.nodes.Length;i++) {
MeshNode node = target.nodes[i] as MeshNode;
if (node == null) {
Debug.LogError ("Node could not be casted to MeshNode. Node was null or no MeshNode");
return;
}
sb.Append(string.Format("f {0}/0 {1}/0 {2}/0\n", node.v1+1,node.v2+1,node.v3+1));
}
string obj = sb.ToString();
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path))
{
sw.Write(obj);
}
}
开发者ID:Anaryu,项目名称:aetherion,代码行数:60,代码来源:RecastGraphEditor.cs
示例5: h_func
protected override float h_func(ref NavGraph para_graph, ref NavNode para_nodeID, ref NavNode para_goalNodeID)
{
WorldNode wN1 = (WorldNode) para_nodeID;
WorldNode wN2 = (WorldNode) para_goalNodeID;
float retHVal = UnityEngine.Vector3.Distance(wN1.getWorldPt(),wN2.getWorldPt());
return retHVal;
}
开发者ID:TAPeri,项目名称:WordsMatter,代码行数:8,代码来源:WorldAStarSearch.cs
示例6: ImgNavToWorldNavGraphBuilder
//NavGraph imgNavGraph;
//GridProperties gPropImgNav;
//GridProperties gPropWorldNav;
public ImgNavToWorldNavGraphBuilder(ref NavGraph para_imgNavGraph,
ref GridProperties para_gPropImgNavGraph,
ref GridProperties para_gPropWorldNavGraph)
{
//imgNavGraph = para_imgNavGraph;
//gPropImgNav = para_gPropImgNavGraph;
//gPropWorldNav = para_gPropWorldNavGraph;
}
开发者ID:TAPeri,项目名称:WordsMatter,代码行数:11,代码来源:ImgNavToWorldNavGraphBuilder.cs
示例7: OnInspectorGUI
public override void OnInspectorGUI(NavGraph target)
{
PointGraph graph = target as PointGraph;
/*
#if UNITY_3_3
graph.root = (Transform)EditorGUILayout.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));
#else
graph.root = (Transform)EditorGUILayout.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);
#endif
*/
//Debug.Log (EditorGUI.indentLevel);
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) {
GUILayout.Label ("All childs "+(graph.recursive ? "and sub-childs ":"") +"of 'root' will be used as nodes\nSet root to null to use a tag search instead",AstarPathEditor.helpBox);
} else {
GUILayout.Label ("All object with the tag '"+graph.searchTag+"' will be used as nodes"+(graph.searchTag == "Untagged" ? "\nNote: the tag 'Untagged' cannot be used" : ""),AstarPathEditor.helpBox);
}
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);
EditorGUIUtility.LookLikeControls ();
#if UNITY_4_0
graph.limits = EditorGUILayout.Vector3Field ("Max Distance (axis aligned)",graph.limits);
#else
EditorGUILayoutx.BeginIndent ();
graph.limits = EditorGUILayout.Vector3Field ("Max Distance (axis aligned)",graph.limits);
EditorGUILayoutx.EndIndent ();
#endif
EditorGUIUtility.LookLikeInspector ();
graph.raycast = EditorGUILayout.Toggle (new GUIContent ("Raycast","Use raycasting to check if connections are valid between each pair of nodes"),graph.raycast);
editor.GUILayoutx.BeginFadeArea (graph.raycast,"raycast");
EditorGUI.indentLevel++;
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);
editor.GUILayoutx.BeginFadeArea (graph.thickRaycast,"thickRaycast");
graph.thickRaycastRadius = EditorGUILayout.FloatField (new GUIContent ("Raycast Radius","The radius in world units for the thick raycast"),graph.thickRaycastRadius);
editor.GUILayoutx.EndFadeArea ();
//graph.mask = 1 << EditorGUILayout.LayerField ("Mask",(int)Mathf.Log (graph.mask,2));
graph.mask = EditorGUILayoutx.LayerMaskField (/*new GUIContent (*/"Mask"/*,"Used to mask which layers should be checked")*/,graph.mask);
EditorGUI.indentLevel--;
editor.GUILayoutx.EndFadeArea ();
}
开发者ID:TimEckhoff,项目名称:GGJ13_Chill,代码行数:56,代码来源:PointGeneratorEditor.cs
示例8: OnInspectorGUI
public override void OnInspectorGUI(NavGraph target)
{
base.OnInspectorGUI(target);
Separator();
MyGridGraph graph = target as MyGridGraph;
GUILayout.BeginHorizontal();
graph.levelLayerMask = EditorGUILayoutx.LayerMaskField("Level Layers", graph.levelLayerMask);
GUILayout.EndHorizontal();
}
开发者ID:Trifectgaming,项目名称:2D-Runner,代码行数:11,代码来源:MyGridGraphEditor.cs
示例9: Graph_SearchDijkstra
public Graph_SearchDijkstra(NavGraph navGraph,
int sourceNodeID,
int targetNodeID = -1)
{
navGraph_ = navGraph;
shortestPathTree_ = new NavGraphEdge[navGraph.NumNodes()];
searchFrontier_ = new NavGraphEdge[navGraph.NumNodes()];
costToThisNode_ = new float[navGraph.NumNodes()];
sourceNodeID_ = sourceNodeID;
targetNodeID_ = targetNodeID;
Search();
}
开发者ID:OggYiu,项目名称:game_jam_project,代码行数:13,代码来源:Graph_SearchDijkstra.cs
示例10: SerializeSettings
public void SerializeSettings (NavGraph target, AstarSerializer serializer) {
//NavMeshGraph graph = target as NavMeshGraph;
//string meshPath = AssetDatabase.GetAssetPath (graph.sourceMesh);
//string meshGUID = AssetDatabase.AssetPathToGUID (meshPath);
/*if (graph == null) {
serializer.writerStream.Write (-1);
} else {
int instanceID = graph.sourceMesh != null ? graph.sourceMesh.GetInstanceID () : -1;
serializer.writerStream.Write (instanceID);
}*/
}
开发者ID:JustSAT,项目名称:Tower-Defence,代码行数:14,代码来源:NavMeshGeneratorEditor.cs
示例11: g_func
protected override float g_func(ref NavGraph para_graph, ref NavNode para_node1, ref NavNode para_node2)
{
NavEdge reqEdge = para_graph.getEdge(para_node1.getNodeID(),para_node2.getNodeID());
float retGVal = 0;
if(reqEdge == null)
{
retGVal = float.PositiveInfinity;
}
else
{
retGVal = reqEdge.getCost();
}
return retGVal;
}
开发者ID:TAPeri,项目名称:WordsMatter,代码行数:15,代码来源:WorldAStarSearch.cs
示例12: 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;
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;
}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:18,代码来源:NavMeshGeneratorEditor.cs
示例13: DeSerializeSettings
public void DeSerializeSettings (NavGraph target, AstarSerializer serializer) {
//NavMeshGraph graph = target as NavMeshGraph;
//string meshGUID = serializer.readerStream.ReadString ();
//int instanceID = serializer.readerStream.ReadInt32 ();
//Mesh ob = EditorUtility.InstanceIDToObject (instanceID) as Mesh;
//if (!Application.isPlaying) {
//graph.sourceMesh = ob;
/*string meshPath = AssetDatabase.GUIDToAssetPath (meshGUID);
Debug.Log (meshGUID +" "+ meshPath);
graph.sourceMesh = AssetDatabase.LoadAssetAtPath (meshPath,typeof(Mesh)) as Mesh;*/
//}
//Debug.Log ("Did succeed? "+(graph.sourceMesh != null));
}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:17,代码来源:NavMeshGeneratorEditor.cs
示例14: Graph_SearchAStar_TS
public Graph_SearchAStar_TS(NavGraph graph, int source, int target)
: base(SearchType.AStar)
{
graph_ = graph;
shortestPathTree_ = new NavGraphEdge[graph.NumNodes()];
searchFrontier_ = new NavGraphEdge[graph.NumNodes()];
gCosts_ = new float[graph.NumNodes()];
fCosts_ = new float[graph.NumNodes()];
sourceIdx_ = source;
targetIdx_ = target;
//create the PQ
pq_ = new IndexedPriorityQLow(fCosts_, graph_.NumNodes());
//put the source node on the queue
pq_.Insert(sourceIdx_);
}
开发者ID:OggYiu,项目名称:game_jam_project,代码行数:17,代码来源:Graph_SearchAStar_TS.cs
示例15: Graph_SearchDijkstras_TS
public Graph_SearchDijkstras_TS( NavGraph navGraph,
int sourceNodeIndex,
int targetNodeIndex)
: base(Graph_SearchTimeSliced.SearchType.Dijkstra)
{
navGraph_ = navGraph;
shortestPathTree_ = new NavGraphEdge[navGraph_.NumNodes()];
searchFrontier_ = new NavGraphEdge[navGraph_.NumNodes()];
costToThisNode_ = new float[navGraph_.NumNodes()];
sourceNodeIndex_ = sourceNodeIndex;
targetNodeIndex_ = targetNodeIndex;
//create the PQ ,
pq_ = new IndexedPriorityQLow( costToThisNode_, navGraph_.NumNodes() );
//put the source node on the queue
pq_.Insert( sourceNodeIndex_ );
}
开发者ID:OggYiu,项目名称:game_jam_project,代码行数:18,代码来源:Graph_SearchDijkstras_TS.cs
示例16: 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");
}
开发者ID:klobodnf,项目名称:st1,代码行数:19,代码来源:LayerGridGraphEditor.cs
示例17: DeSerializeSettings
public void DeSerializeSettings (NavGraph target, AstarSerializer serializer) {
pivot = (GridPivot)serializer.GetValue ("pivot",typeof(int),GridPivot.BottomLeft);
locked = (bool)serializer.GetValue ("locked",typeof(bool),true);
showExtra = (bool)serializer.GetValue ("showExtra",typeof(bool));
}
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:6,代码来源:GridGeneratorEditor.cs
示例18: OnSceneGUI
//GraphUndo undoState;
//byte[] savedBytes;
public override void OnSceneGUI(NavGraph target)
{
Event e = Event.current;
GridGraph graph = target as GridGraph;
Matrix4x4 matrixPre = graph.matrix;
graph.GenerateMatrix ();
if (e.type == EventType.MouseDown) {
isMouseDown = true;
} else if (e.type == EventType.MouseUp) {
isMouseDown = false;
}
if (!isMouseDown) {
savedMatrix = graph.boundsMatrix;
}
Handles.matrix = savedMatrix;
if (graph.nodes == null || (graph.uniformWidhtDepthGrid && graph.depth*graph.width != graph.nodes.Length) || graph.matrix != matrixPre) {
//Rescann the graphs
AstarPath.active.AutoScan ();
//GUI.changed = true;
}
Matrix4x4 inversed = savedMatrix.inverse;
Handles.color = AstarColor.BoundsHandles;
Handles.DrawCapFunction cap = Handles.CylinderCap;
Vector2 extents = graph.unclampedSize*0.5F;
Vector3 center = inversed.MultiplyPoint3x4 (graph.center);
#if UNITY_3_3
if (Tools.current == 3) {
#else
if (Tools.current == Tool.Scale) {
#endif
Vector3 p1 = Handles.Slider (center+new Vector3 (extents.x,0,0), Vector3.right, 0.1F*HandleUtility.GetHandleSize (center+new Vector3 (extents.x,0,0)),cap,0);
Vector3 p2 = Handles.Slider (center+new Vector3 (0,0,extents.y), Vector3.forward, 0.1F*HandleUtility.GetHandleSize (center+new Vector3 (0,0,extents.y)),cap,0);
//Vector3 p3 = Handles.Slider (center+new Vector3 (0,extents.y,0), Vector3.up, 0.1F*HandleUtility.GetHandleSize (center+new Vector3 (0,extents.y,0)),cap,0);
Vector3 p4 = Handles.Slider (center+new Vector3 (-extents.x,0,0), -Vector3.right, 0.1F*HandleUtility.GetHandleSize (center+new Vector3 (-extents.x,0,0)),cap,0);
Vector3 p5 = Handles.Slider (center+new Vector3 (0,0,-extents.y), -Vector3.forward, 0.1F*HandleUtility.GetHandleSize (center+new Vector3 (0,0,-extents.y)),cap,0);
Vector3 p6 = Handles.Slider (center, Vector3.up, 0.1F*HandleUtility.GetHandleSize (center),cap,0);
Vector3 r1 = new Vector3 (p1.x,p6.y,p2.z);
Vector3 r2 = new Vector3 (p4.x,p6.y,p5.z);
//Debug.Log (graph.boundsMatrix.MultiplyPoint3x4 (Vector3.zero)+" "+graph.boundsMatrix.MultiplyPoint3x4 (Vector3.one));
//if (Tools.viewTool != ViewTool.Orbit) {
graph.center = savedMatrix.MultiplyPoint3x4 ((r1+r2)/2F);
Vector3 tmp = r1-r2;
graph.unclampedSize = new Vector2(tmp.x,tmp.z);
//}
#if UNITY_3_3
} else if (Tools.current == 1) {
#else
} else if (Tools.current == Tool.Move) {
#endif
if (Tools.pivotRotation == PivotRotation.Local) {
center = Handles.PositionHandle (center,Quaternion.identity);
if (Tools.viewTool != ViewTool.Orbit) {
graph.center = savedMatrix.MultiplyPoint3x4 (center);
}
} else {
Handles.matrix = Matrix4x4.identity;
center = Handles.PositionHandle (graph.center,Quaternion.identity);
if (Tools.viewTool != ViewTool.Orbit) {
graph.center = center;
}
}
#if UNITY_3_3
} else if (Tools.current == 2) {
#else
} else if (Tools.current == Tool.Rotate) {
#endif
//The rotation handle doesn't seem to be able to handle different matrixes of some reason
Handles.matrix = Matrix4x4.identity;
Quaternion rot = Handles.RotationHandle (Quaternion.Euler (graph.rotation),graph.center);
//.........这里部分代码省略.........
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:101,代码来源:GridGeneratorEditor.cs
示例19: OnInspectorGUI
public override void OnInspectorGUI(NavGraph target)
{
GridGraph graph = target as GridGraph;
//GUILayout.BeginHorizontal ();
//GUILayout.BeginVertical ();
Rect lockRect;
Rect tmpLockRect;
GUIStyle lockStyle = AstarPathEditor.astarSkin.FindStyle ("GridSizeLock");
if (lockStyle == null) {
lockStyle = new GUIStyle ();
}
bool sizeSelected1 = false;
bool sizeSelected2 = false;
int newWidth = IntField (new GUIContent ("Width (nodes)","Width of the graph in nodes"),graph.width,50,0, out lockRect, out sizeSelected1);
int newDepth = IntField (new GUIContent ("Depth (nodes)","Depth (or height you might also call it) of the graph in nodes"),graph.depth,50,0, out tmpLockRect, out sizeSelected2);
//Rect r = GUILayoutUtility.GetRect (0,0,lockStyle);
lockRect.width = lockStyle.fixedWidth;
lockRect.height = lockStyle.fixedHeight;
lockRect.x += lockStyle.margin.left;
lockRect.y += lockStyle.margin.top;
locked = GUI.Toggle (lockRect,locked,new GUIContent ("","If the width and depth values are locked, changing the node size will scale the grid which keeping the number of nodes consistent instead of keeping the size the same and changing the number of nodes in the graph"),lockStyle);
//GUILayout.EndHorizontal ();
if (newWidth != graph.width || newDepth != graph.depth) {
SnapSizeToNodes (newWidth,newDepth,graph);
}
GUI.SetNextControlName ("NodeSize");
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);
//if ((GUI.GetNameOfFocusedControl () != "NodeSize" && Event.current.type == EventType.Repaint) || Event.current.keyCode == KeyCode.Return) {
//Debug.Log ("Node Size Not Selected " + Event.current.type);
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 {
float delta = newNodeSize / graph.nodeSize;
graph.nodeSize = newNodeSize;
graph.unclampedSize = new Vector2 (newWidth*graph.nodeSize,newDepth*graph.nodeSize);
Vector3 newCenter = graph.matrix.MultiplyPoint3x4 (new Vector3 ((newWidth/2F)*delta,0,(newDepth/2F)*delta));
graph.center = newCenter;
graph.GenerateMatrix ();
//Make sure the width & depths stay the same
graph.width = newWidth;
graph.depth = newDepth;
AstarPath.active.AutoScan ();
}
}
//}
Vector3 pivotPoint;
Vector3 diff;
EditorGUIUtility.LookLikeControls ();
EditorGUILayoutx.BeginIndent ();
switch (pivot) {
case GridPivot.Center:
graph.center = EditorGUILayout.Vector3Field ("Center",graph.center);
break;
case GridPivot.TopLeft:
pivotPoint = graph.matrix.MultiplyPoint3x4 (new Vector3 (0,0,graph.depth));
diff = pivotPoint-graph.center;
pivotPoint = EditorGUILayout.Vector3Field ("Top-Left",pivotPoint);
graph.center = pivotPoint-diff;
break;
case GridPivot.TopRight:
pivotPoint = graph.matrix.MultiplyPoint3x4 (new Vector3 (graph.width,0,graph.depth));
diff = pivotPoint-graph.center;
pivotPoint = EditorGUILayout.Vector3Field ("Top-Right",pivotPoint);
graph.center = pivotPoint-diff;
break;
case GridPivot.BottomLeft:
pivotPoint = graph.matrix.MultiplyPoint3x4 (new Vector3 (0,0,0));
diff = pivotPoint-graph.center;
pivotPoint = EditorGUILayout.Vector3Field ("Bottom-Left",pivotPoint);
graph.center = pivotPoint-diff;
break;
//.........这里部分代码省略.........
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:101,代码来源:GridGeneratorEditor.cs
示例20: includeNode
// img width and height
// By default, C# creates param: para_graph as a new reference to the object. It does not copy the object but it creates a new reference.
// The ref keyword refers to the same object but prevents duplicating the reference.
private void includeNode(int para_graphID,
NavGraph para_graph,
int para_nodeX,
int para_nodeY,
Color para_nodeColor,
int[] para_imgWNH)
{
// PREP.
NavGraph retGraph = para_graph;
GraphTmpMetaData reqGraphMetaData = graphMetaDataArr[para_graphID];
int c = para_nodeX;
int r = para_nodeY;
int nxtNodeID = reqGraphMetaData.nxtNodeID;
int nxtEdgeID = reqGraphMetaData.nxtEdgeID;
Dictionary<string,int> coordToNodeIDMap = reqGraphMetaData.coordToNodeIDMap;
// GO.
// Add new node.
WorldNode nwNode = new WorldNode(nxtNodeID,
reqGraphMetaData.colorToNodeType[para_nodeColor],
new Vector3((worldGProp.x + (worldGProp.cellWidth/2f)) + (worldGProp.cellWidth * c),
(worldGProp.y - (worldGProp.cellWidth/2f)) - (worldGProp.cellHeight * r),
worldGProp.z));
retGraph.addNode(nwNode);
coordToNodeIDMap.Add((""+c+"-"+r),nwNode.getNodeID());
nxtNodeID++;
// Get valid neighbourhood pixels.
List<Color> neighbourhoodPixels = new List<Color>();
List<int[]> reqNPixCoords = new List<int[]>();
//reqNPixCoords.Add(new int[2]{(c-1),(r-1)});
reqNPixCoords.Add(new int[2]{(c),(r-1)});
//reqNPixCoords.Add(new int[2]{(c+1),(r-1)});
reqNPixCoords.Add(new int[2]{(c-1),(r)});
List<int> validCoordIndexList = new List<int>();
for(int k=0; k<reqNPixCoords.Count; k++)
{
int[] tmpCoords = reqNPixCoords[k];
if((tmpCoords[0] >= 0)&&(tmpCoords[0] < para_imgWNH[0]) // mapImg.width)
&&(tmpCoords[1] >= 0)&&(tmpCoords[1] < para_imgWNH[1])) // mapImg.height))
{
// Valid coords.
validCoordIndexList.Add(k);
neighbourhoodPixels.Add( pixels[(pixels.Length - para_imgWNH[0]) - (tmpCoords[1] * para_imgWNH[0]) + tmpCoords[0]] );
}
}
// Check for neighbours and create edges. (NavGraph will handle the internal creation of neighbour references, just run addEdge).
for(int k=0; k<validCoordIndexList.Count; k++)
{
if(colourDestinationGraphMap.ContainsKey(neighbourhoodPixels[k]))
{
if(colourDestinationGraphMap[neighbourhoodPixels[k]].Contains(para_graphID))
{
int[] neighbourCoords = reqNPixCoords[k];
int neighbourID = coordToNodeIDMap[(""+neighbourCoords[0]+"-"+neighbourCoords[1])];
retGraph.addEdge(nwNode.getNodeID(),neighbourID,new NavEdge(new int[2] {nwNode.getNodeID(),neighbourID},1));
}
}
}
// POST.
reqGraphMetaData.nxtNodeID = nxtNodeID;
reqGraphMetaData.nxtEdgeID = nxtEdgeID;
reqGraphMetaData.coordToNodeIDMap = coordToNodeIDMap;
graphMetaDataArr[para_graphID] = reqGraphMetaData;
}
开发者ID:TAPeri,项目名称:WordsMatter,代码行数:77,代码来源:ImgToWorldNavGraphBuilderV2.cs
注:本文中的NavGraph类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论