public override void OnDrawGizmos(Util.RetainedGizmos gizmos, bool drawNodes)
        {
            base.OnDrawGizmos(gizmos, drawNodes);

            if (!drawNodes)
            {
                return;
            }

            Gizmos.color = new Color(0.161f, 0.341f, 1f, 0.5f);

            if (root != null)
            {
                DrawChildren(this, root);
            }
            else if (!string.IsNullOrEmpty(searchTag))
            {
                var gos = GameObject.FindGameObjectsWithTag(searchTag);
                for (var i = 0; i < gos.Length; i++)
                {
                    Gizmos.DrawCube(gos[i].transform.position,
                                    Vector3.one * UnityEditor.HandleUtility.GetHandleSize(gos[i].transform.position) * 0.1F);
                }
            }
        }
示例#2
0
 void SubmitMeshes(RetainedGizmos gizmos, ulong hash)
 {
     for (int i = 0; i < meshes.Count; i++)
     {
         gizmos.meshes.Add(new MeshWithHash {
             hash = hash, mesh = meshes[i], lines = false
         });
         gizmos.existingHashes.Add(hash);
     }
 }
            // Token: 0x06002DB1 RID: 11697 RVA: 0x001D0890 File Offset: 0x001CEA90
            public void DrawMesh(RetainedGizmos gizmos, Vector3[] vertices, List <int> triangles, Color[] colors)
            {
                Mesh mesh = gizmos.GetMesh();

                mesh.vertices = vertices;
                mesh.SetTriangles(triangles, 0);
                mesh.colors = colors;
                mesh.UploadMeshData(true);
                this.meshes.Add(mesh);
            }
示例#4
0
 public void Init(RetainedGizmos.Hasher hasher, RetainedGizmos gizmos)
 {
     debugData      = PathFindHelper.debugPathData;
     debugPathID    = PathFindHelper.debugPathID;
     debugMode      = AstarPath.active.debugMode;
     debugFloor     = AstarPath.active.debugFloor;
     debugRoof      = AstarPath.active.debugRoof;
     showSearchTree = AstarPath.active.showSearchTree && debugData != null;
     this.gizmos    = gizmos;
     this.hasher    = hasher;
     builder        = ObjectPool <RetainedGizmos.Builder> .Claim();
 }
示例#5
0
            public void DrawMesh(RetainedGizmos gizmos, Vector3[] vertices, List <int> triangles, Color[] colors)
            {
                var mesh = gizmos.GetMesh();

                // Set all data on the mesh
                mesh.vertices = vertices;
                mesh.SetTriangles(triangles, 0);
                mesh.colors = colors;

                // Upload all data
                mesh.UploadMeshData(false);
                meshes.Add(mesh);
            }
示例#6
0
        public void Init(AstarPath active, RetainedGizmos.Hasher hasher, RetainedGizmos gizmos)
        {
            this.debugData   = active.debugPathData;
            this.debugPathID = active.debugPathID;
            this.debugMode   = active.debugMode;
            this.debugFloor  = active.debugFloor;
            this.debugRoof   = active.debugRoof;
            this.gizmos      = gizmos;
            this.hasher      = hasher;
            this.builder     = ObjectPool <RetainedGizmos.Builder> .Claim();

            this.showSearchTree = (active.showSearchTree && this.debugData != null);
        }
示例#7
0
        public void OnDrawGizmos(Pathfinding.Util.RetainedGizmos gizmos)
        {
            var hasher = new Pathfinding.Util.RetainedGizmos.Hasher(AstarPath.active);

            hasher.AddHash(gizmoVersion);

            if (!gizmos.Draw(hasher))
            {
                var builder = ObjectPool <RetainedGizmos.Builder> .Claim();

                var centers = ArrayPool <UnityEngine.Vector3> .Claim(areas.Length);

                for (int i = 0; i < areas.Length; i++)
                {
                    Int3 center = Int3.zero;
                    var  childs = children[i];
                    if (childs.Count > 0)
                    {
                        for (int j = 0; j < childs.Count; j++)
                        {
                            center += childs[j].position;
                        }
                        center    /= childs.Count;
                        centers[i] = (UnityEngine.Vector3)center;
                    }
                }

                for (int i = 0; i < areas.Length; i++)
                {
                    if (children[i].Count > 0)
                    {
                        for (int j = 0; j < connections[i].Count; j++)
                        {
                            if (connections[i][j] > i)
                            {
                                builder.DrawLine(centers[i], centers[connections[i][j]], UnityEngine.Color.black);
                            }
                        }
                    }
                }

                builder.Submit(gizmos, hasher);
            }
        }
示例#8
0
            void SubmitLines(RetainedGizmos gizmos, ulong hash)
            {
                // Unity only supports 65535 vertices per mesh. 65532 used because MaxLineEndPointsPerBatch needs to be even.
                const int MaxLineEndPointsPerBatch = 65532 / 2;
                int       batches = (lines.Count + MaxLineEndPointsPerBatch - 1) / MaxLineEndPointsPerBatch;

                for (int batch = 0; batch < batches; batch++)
                {
                    int startIndex        = MaxLineEndPointsPerBatch * batch;
                    int endIndex          = Mathf.Min(startIndex + MaxLineEndPointsPerBatch, lines.Count);
                    int lineEndPointCount = endIndex - startIndex;
                    UnityEngine.Assertions.Assert.IsTrue(lineEndPointCount % 2 == 0);

                    // Use pooled lists to avoid excessive allocations
                    var vertices = ListPool <Vector3> .Claim(lineEndPointCount *2);

                    var colors = ListPool <Color32> .Claim(lineEndPointCount *2);

                    var normals = ListPool <Vector3> .Claim(lineEndPointCount *2);

                    var uv = ListPool <Vector2> .Claim(lineEndPointCount *2);

                    var tris = ListPool <int> .Claim(lineEndPointCount *3);

                    // Loop through each endpoint of the lines
                    // and add 2 vertices for each
                    for (int j = startIndex; j < endIndex; j++)
                    {
                        var vertex = (Vector3)lines[j];
                        vertices.Add(vertex);
                        vertices.Add(vertex);

                        var color = (Color32)lineColors[j];
                        colors.Add(color);
                        colors.Add(color);
                        uv.Add(new Vector2(0, 0));
                        uv.Add(new Vector2(1, 0));
                    }

                    // Loop through each line and add
                    // one normal for each vertex
                    for (int j = startIndex; j < endIndex; j += 2)
                    {
                        var lineDir = (Vector3)(lines[j + 1] - lines[j]);
                        // Store the line direction in the normals.
                        // A line consists of 4 vertices. The line direction will be used to
                        // offset the vertices to create a line with a fixed pixel thickness
                        normals.Add(lineDir);
                        normals.Add(lineDir);
                        normals.Add(lineDir);
                        normals.Add(lineDir);
                    }

                    // Setup triangle indices
                    // A triangle consists of 3 indices
                    // A line (4 vertices) consists of 2 triangles, so 6 triangle indices
                    for (int j = 0, v = 0; j < lineEndPointCount * 3; j += 6, v += 4)
                    {
                        // First triangle
                        tris.Add(v + 0);
                        tris.Add(v + 1);
                        tris.Add(v + 2);

                        // Second triangle
                        tris.Add(v + 1);
                        tris.Add(v + 3);
                        tris.Add(v + 2);
                    }

                    var mesh = gizmos.GetMesh();

                    // Set all data on the mesh
                    mesh.SetVertices(vertices);
                    mesh.SetTriangles(tris, 0);
                    mesh.SetColors(colors);
                    mesh.SetNormals(normals);
                    mesh.SetUVs(0, uv);

                    // Upload all data
                    mesh.UploadMeshData(false);

                    // Release the lists back to the pool
                    ListPool <Vector3> .Release(ref vertices);

                    ListPool <Color32> .Release(ref colors);

                    ListPool <Vector3> .Release(ref normals);

                    ListPool <Vector2> .Release(ref uv);

                    ListPool <int> .Release(ref tris);

                    gizmos.meshes.Add(new MeshWithHash {
                        hash = hash, mesh = mesh, lines = true
                    });
                    gizmos.existingHashes.Add(hash);
                }
            }
示例#9
0
 public void Submit(RetainedGizmos gizmos, Hasher hasher)
 {
     SubmitLines(gizmos, hasher.Hash);
     SubmitMeshes(gizmos, hasher.Hash);
 }
示例#10
0
        public static void OnDrawGizmos(this NavmeshBase navmeshBase, Pathfinding.Util.RetainedGizmos gizmos, bool drawNodes)
        {
            if (!drawNodes)
            {
                return;
            }

            using (var helper = gizmos.GetSingleFrameGizmoHelper()) {
                var bounds = new Bounds();
                bounds.SetMinMax(Vector3.zero, navmeshBase.forcedBoundsSize);
                // Draw a write cube using the latest transform
                // (this makes the bounds update immediately if some field is changed in the editor)
                helper.builder.DrawWireCube(navmeshBase.CalculateTransform(), bounds, Color.white);
            }

            if (navmeshBase.tiles != null)
            {
                // Update navmesh vizualizations for
                // the tiles that have been changed
                for (int i = 0; i < navmeshBase.tiles.Length; i++)
                {
                    // This may happen if an exception has been thrown when the graph was scanned.
                    // We don't want the gizmo code to start to throw exceptions as well then as
                    // that would obscure the actual source of the error.
                    if (navmeshBase.tiles[i] == null)
                    {
                        continue;
                    }

                    // Calculate a hash of the tile
                    var hasher = new RetainedGizmos.Hasher(AstarPath.active);
                    hasher.AddHash(navmeshBase.showMeshOutline ? 1 : 0);
                    hasher.AddHash(navmeshBase.showMeshSurface ? 1 : 0);
                    hasher.AddHash(navmeshBase.showNodeConnections ? 1 : 0);

                    var nodes = navmeshBase.tiles[i].nodes;
                    for (int j = 0; j < nodes.Length; j++)
                    {
                        hasher.HashNode(nodes[j]);
                    }

                    if (!gizmos.Draw(hasher))
                    {
                        using (var helper = gizmos.GetGizmoHelper(hasher)) {
                            if (navmeshBase.showMeshSurface || navmeshBase.showMeshOutline)
                            {
                                navmeshBase.CreateNavmeshSurfaceVisualization(navmeshBase.tiles[i], helper);
                            }
                            if (navmeshBase.showMeshSurface || navmeshBase.showMeshOutline)
                            {
                                CreateNavmeshOutlineVisualization(navmeshBase.tiles[i], helper);
                            }

                            if (navmeshBase.showNodeConnections)
                            {
                                for (int j = 0; j < nodes.Length; j++)
                                {
                                    helper.DrawConnections(nodes[j]);
                                }
                            }
                        }
                    }

                    gizmos.Draw(hasher);
                }
            }

            if (AstarPath.active.showUnwalkableNodes)
            {
                navmeshBase.DrawUnwalkableNodes(AstarPath.active.unwalkableNodeDebugSize);
            }
        }
            // Token: 0x06002DB6 RID: 11702 RVA: 0x001D0CC8 File Offset: 0x001CEEC8
            private void SubmitLines(RetainedGizmos gizmos, ulong hash)
            {
                int num = (this.lines.Count + 32766 - 1) / 32766;

                for (int i = 0; i < num; i++)
                {
                    int            num2 = 32766 * i;
                    int            num3 = Mathf.Min(num2 + 32766, this.lines.Count);
                    int            num4 = num3 - num2;
                    List <Vector3> list = ListPool <Vector3> .Claim(num4 * 2);

                    List <Color32> list2 = ListPool <Color32> .Claim(num4 * 2);

                    List <Vector3> list3 = ListPool <Vector3> .Claim(num4 * 2);

                    List <Vector2> list4 = ListPool <Vector2> .Claim(num4 * 2);

                    List <int> list5 = ListPool <int> .Claim(num4 * 3);

                    for (int j = num2; j < num3; j++)
                    {
                        Vector3 item = this.lines[j];
                        list.Add(item);
                        list.Add(item);
                        Color32 item2 = this.lineColors[j];
                        list2.Add(item2);
                        list2.Add(item2);
                        list4.Add(new Vector2(0f, 0f));
                        list4.Add(new Vector2(1f, 0f));
                    }
                    for (int k = num2; k < num3; k += 2)
                    {
                        Vector3 item3 = this.lines[k + 1] - this.lines[k];
                        list3.Add(item3);
                        list3.Add(item3);
                        list3.Add(item3);
                        list3.Add(item3);
                    }
                    int l    = 0;
                    int num5 = 0;
                    while (l < num4 * 3)
                    {
                        list5.Add(num5);
                        list5.Add(num5 + 1);
                        list5.Add(num5 + 2);
                        list5.Add(num5 + 1);
                        list5.Add(num5 + 3);
                        list5.Add(num5 + 2);
                        l    += 6;
                        num5 += 4;
                    }
                    Mesh mesh = gizmos.GetMesh();
                    mesh.SetVertices(list);
                    mesh.SetTriangles(list5, 0);
                    mesh.SetColors(list2);
                    mesh.SetNormals(list3);
                    mesh.SetUVs(0, list4);
                    mesh.UploadMeshData(true);
                    ListPool <Vector3> .Release(ref list);

                    ListPool <Color32> .Release(ref list2);

                    ListPool <Vector3> .Release(ref list3);

                    ListPool <Vector2> .Release(ref list4);

                    ListPool <int> .Release(ref list5);

                    gizmos.meshes.Add(new RetainedGizmos.MeshWithHash
                    {
                        hash  = hash,
                        mesh  = mesh,
                        lines = true
                    });
                    gizmos.existingHashes.Add(hash);
                }
            }
 // Token: 0x06002DB4 RID: 11700 RVA: 0x001D0C40 File Offset: 0x001CEE40
 public void Submit(RetainedGizmos gizmos, RetainedGizmos.Hasher hasher)
 {
     this.SubmitLines(gizmos, hasher.Hash);
     this.SubmitMeshes(gizmos, hasher.Hash);
 }