Example #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);
            }
        }
Example #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);
            }
        }
Example #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);
     }
 }