示例#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);
            }
        }
示例#2
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);
     }
 }
示例#3
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();
            }
        }