public void Render(Minimap_Waypoint waypointAStar, int startX, int startY, int endX, int endY, int nodeSizeX, int nodeSizeY, Material pathMaterial) { List <Vector3> path = new List <Vector3>(); int index = waypointAStar.FindContainingNode(endX, endY); if (index == -1 || waypointAStar.Get(index).parent == -1) { return; } path.Add(new Vector3((endX + 0.5f) * nodeSizeX, (endY + 0.5f) * nodeSizeY, 100)); while (index != -1) { path.Add(GetIndexCoords(waypointAStar, index, nodeSizeX, nodeSizeY)); index = waypointAStar.Get(index).parent; } path.Add(new Vector3((startX + 0.5f) * nodeSizeX, (startY + 0.5f) * nodeSizeY, 100)); const float cornerSharpness = 0.85f; _lineRenderer.SetVertexCount(path.Count * 2 - 2); _lineRenderer.SetPosition(0, path[0]); for (int i = 1; i < path.Count - 1; ++i) { _lineRenderer.SetPosition(2 * i - 1, Vector3.Lerp(path[i - 1], path[i], cornerSharpness)); _lineRenderer.SetPosition(2 * i, Vector3.Lerp(path[i + 1], path[i], cornerSharpness)); } _lineRenderer.SetPosition(path.Count * 2 - 3, path[path.Count - 1]); _lineRenderer.sharedMaterial = pathMaterial; }
private Vector3 GetIndexCoords(Minimap_Waypoint waypointAStar, int index, int nodeSizeX, int nodeSizeY) { return(new Vector3( (waypointAStar.Get(index).x + waypointAStar.Get(index).size / 2.0f) * nodeSizeX, (waypointAStar.Get(index).y + waypointAStar.Get(index).size / 2.0f) * nodeSizeY, 100 )); }
public int Compare(int a, int b) { float waypointA = (_waypointAStar.Get(a).distance + _waypointAStar.Get(a).heuristic *_heuristicWeight); float waypointB = (_waypointAStar.Get(b).distance + _waypointAStar.Get(b).heuristic *_heuristicWeight); if (waypointA < waypointB) { return(-1); } else if (waypointA > waypointB) { return(1); } return(0); }
public void Render(Minimap_Waypoint waypointAStar, int startNode, int nodeCount, int nodeSizeX, int nodeSizeY, float distance, Material aStarMaterial) { nodeCount = Mathf.Min(nodeCount, waypointAStar.NumNodes - startNode); const int maxVerts = 65000; if (nodeCount * 4 > maxVerts) { Debug.LogError("Render tile dimensions too large: " + nodeCount + " * 4 = " + (nodeCount * 4) + " (> " + maxVerts + ")"); return; } Vector3[] verts = new Vector3[nodeCount * 4]; Vector2[] uvs = new Vector2[nodeCount * 4]; Color32[] colors = new Color32[nodeCount * 4]; int[] tris = new int[nodeCount * 6]; for (int i = 0; i < nodeCount; ++i) { int index = i + startNode; int x0 = waypointAStar.Get(index).x *nodeSizeX; int x1 = x0 + waypointAStar.Get(index).size *nodeSizeX; int y0 = waypointAStar.Get(index).y *nodeSizeY; int y1 = y0 + waypointAStar.Get(index).size *nodeSizeY; Color32 c; if (waypointAStar.Get(index).distance < 0.0f) { c = Color.clear; } else if (waypointAStar.Get(index).distance >= Minimap_Waypoint.INFINITY) { c = new Color(0.5f, 0.5f, 1.0f, 1.0f); } else { float value = Mathf.Clamp01(waypointAStar.Get(index).distance / distance); c = new Color(1.0f, value, value, 1.0f); } verts[i * 4 + 0] = new Vector3(x0, y0, 0); uvs[i * 4 + 0] = new Vector2(0, 0); colors[i * 4 + 0] = c; verts[i * 4 + 1] = new Vector3(x0, y1, 0); uvs[i * 4 + 1] = new Vector2(0, 1); colors[i * 4 + 1] = c; verts[i * 4 + 2] = new Vector3(x1, y1, 0); uvs[i * 4 + 2] = new Vector2(1, 1); colors[i * 4 + 2] = c; verts[i * 4 + 3] = new Vector3(x1, y0, 0); uvs[i * 4 + 3] = new Vector2(1, 0); colors[i * 4 + 3] = c; tris[i * 6 + 0] = i * 4 + 0; tris[i * 6 + 1] = i * 4 + 1; tris[i * 6 + 2] = i * 4 + 2; tris[i * 6 + 3] = i * 4 + 2; tris[i * 6 + 4] = i * 4 + 3; tris[i * 6 + 5] = i * 4 + 0; } _mesh.Clear(); _mesh.vertices = verts; _mesh.uv = uvs; _mesh.colors32 = colors; _mesh.triangles = tris; _meshFilter.sharedMesh = _mesh; _meshRenderer.sharedMaterial = aStarMaterial; }