Esempio n. 1
0
        /** Draw gizmos for the graph */
        public virtual void OnDrawGizmos(RetainedGizmos gizmos, bool drawNodes)
        {
            if (!drawNodes)
            {
                return;
            }

            // This is a relatively slow default implementation.
            // subclasses of the base graph class may override
            // this method to draw gizmos in a more optimized way

            var hasher = new RetainedGizmos.Hasher(active);

            GetNodes(node => hasher.HashNode(node));

            // Update the gizmo mesh if necessary
            if (!gizmos.Draw(hasher))
            {
                using (var helper = gizmos.GetGizmoHelper(active, hasher)) {
                    GetNodes((System.Action <GraphNode>)helper.DrawConnections);
                }
            }

            if (active.showUnwalkableNodes)
            {
                DrawUnwalkableNodes(active.unwalkableNodeDebugSize);
            }
        }
Esempio n. 2
0
        public void OnDrawGizmos(RetainedGizmos gizmos)
        {
            var hasher = new RetainedGizmos.Hasher(AstarPath.active);

            hasher.AddHash(gizmoVersion);

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

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

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

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

                builder.Submit(gizmos, hasher);
            }
        }
Esempio n. 3
0
 public virtual void OnDrawGizmos(RetainedGizmos gizmos, bool drawNodes)
 {
     if (!drawNodes)
     {
         return;
     }
     RetainedGizmos.Hasher hasher = new RetainedGizmos.Hasher(this.active);
     this.GetNodes(delegate(GraphNode node)
     {
         hasher.HashNode(node);
     });
     if (!gizmos.Draw(hasher))
     {
         using (GraphGizmoHelper gizmoHelper = gizmos.GetGizmoHelper(this.active, hasher))
         {
             this.GetNodes(new Action <GraphNode>(gizmoHelper.DrawConnections));
         }
     }
     if (this.active.showUnwalkableNodes)
     {
         this.DrawUnwalkableNodes(this.active.unwalkableNodeDebugSize);
     }
 }
Esempio n. 4
0
        void OnDrawGizmos()
        {
            // Prevent interfering with scene view picking
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (drawObstacles && simulator != null && simulator.obstacles != null)
            {
                var hasher    = new RetainedGizmos.Hasher();
                var obstacles = simulator.obstacles;
                int numEdges  = 0;
                for (int i = 0; i < obstacles.Count; i++)
                {
                    var vertex = obstacles[i];
                    do
                    {
                        hasher.AddHash(vertex.position.GetHashCode() ^ vertex.height.GetHashCode());
                        numEdges++;
                        vertex = vertex.next;
                    } while (vertex != obstacles[i] && vertex != null);
                }

                if (!gizmos.Draw(hasher))
                {
                    Profiler.BeginSample("Rebuild RVO Obstacle Gizmos");
                    using (var helper = gizmos.GetGizmoHelper(null, hasher))
                    {
                        var up        = movementPlane == MovementPlane.XY ? Vector3.back : Vector3.up;
                        var vertices  = new Vector3[numEdges * 6];
                        var colors    = new Color[numEdges * 6];
                        int edgeIndex = 0;
                        for (int i = 0; i < obstacles.Count; i++)
                        {
                            var start = obstacles[i];
                            var c     = start;
                            do
                            {
                                vertices[edgeIndex * 6 + 0] = c.position;
                                vertices[edgeIndex * 6 + 1] = c.next.position;
                                vertices[edgeIndex * 6 + 2] = c.next.position + up * c.next.height;
                                vertices[edgeIndex * 6 + 3] = c.position;
                                vertices[edgeIndex * 6 + 4] = c.next.position + up * c.next.height;
                                vertices[edgeIndex * 6 + 5] = c.position + up * c.height;
                                edgeIndex++;
                                c = c.next;
                            } while (c != start && c != null && c.next != null);
                        }

                        for (int i = 0; i < colors.Length; i++)
                        {
                            colors[i] = ObstacleColor;
                        }

                        helper.DrawTriangles(vertices, colors, numEdges * 2);
                    }
                    Profiler.EndSample();
                }

                gizmos.FinalizeDraw();
            }
        }