public override void OnDrawGizmos(DrawingData gizmos, bool drawNodes, RedrawScope redrawScope) { base.OnDrawGizmos(gizmos, drawNodes, redrawScope); if (!drawNodes) { return; } using (var draw = gizmos.GetBuilder()) { using (draw.WithColor(new Color(0.161f, 0.341f, 1f, 0.5f))) { if (root != null) { DrawChildren(draw, this, root); } else if (!string.IsNullOrEmpty(searchTag)) { GameObject[] gos = GameObject.FindGameObjectsWithTag(searchTag); for (int i = 0; i < gos.Length; i++) { draw.SolidBox(gos[i].transform.position, Vector3.one * UnityEditor.HandleUtility.GetHandleSize(gos[i].transform.position) * 0.1F); } } } } }
protected void DrawUnwalkableNodes(DrawingData gizmos, float size, RedrawScope redrawScope) { var hasher = DrawingData.Hasher.Create(this); GetNodes(node => { hasher.Add(node.Walkable); if (!node.Walkable) { hasher.Add(node.position); } }); if (!gizmos.Draw(hasher, redrawScope)) { using (var builder = gizmos.GetBuilder(hasher)) { using (builder.WithColor(AstarColor.UnwalkableNode)) { GetNodes(node => { if (!node.Walkable) { builder.SolidBox((Vector3)node.position, new Unity.Mathematics.float3(size, size, size)); } }); } } } }
void CheckFrameTicking() { if (Time.frameCount != lastFrameCount) { framePassed = true; lastFrameCount = Time.frameCount; previousFrameRedrawScope = gizmos.frameRedrawScope; gizmos.frameRedrawScope = new RedrawScope(gizmos); Draw.builder.DisposeInternal(); Draw.ingame_builder.DisposeInternal(); Draw.builder = gizmos.GetBuiltInBuilder(false); Draw.ingame_builder = gizmos.GetBuiltInBuilder(true); } else if (framePassed && Application.isPlaying) { // Rendered frame passed without a game frame passing! // This might mean the game is paused. // Redraw gizmos while the game is paused. // It might also just mean that we are rendering with multiple cameras. previousFrameRedrawScope.Draw(); } if (framePassed) { gizmos.TickFrame(); builtGizmos = false; framePassed = false; } }
/// <summary>Draw gizmos for the graph</summary> public virtual void OnDrawGizmos(DrawingData gizmos, bool drawNodes, RedrawScope redrawScope) { 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 NodeHasher(active); GetNodes(node => hasher.HashNode(node)); // Update the gizmo mesh if necessary if (!gizmos.Draw(hasher, redrawScope)) { using (var helper = GraphGizmoHelper.GetGizmoHelper(gizmos, active, hasher, redrawScope)) { GetNodes((System.Action <GraphNode>)helper.DrawConnections); } } if (active.showUnwalkableNodes) { DrawUnwalkableNodes(gizmos, active.unwalkableNodeDebugSize, redrawScope); } }
public void OnDrawGizmos(DrawingData gizmos, RedrawScope redrawScope) { var hasher = new NodeHasher(AstarPath.active); hasher.Add(gizmoVersion); if (!gizmos.Draw(hasher, redrawScope)) { using (var builder = gizmos.GetBuilder(hasher, redrawScope)) { var centers = ArrayPool <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] = (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.Line(centers[i], centers[connections[i][j]], Color.black); } } } } } } }
/// <summary> /// Get an empty builder for queuing drawing commands. /// TODO: Example usage. /// /// See: <see cref="Drawing.CommandBuilder"/> /// </summary> /// <param name="hasher">Hash of whatever inputs you used to generate the drawing data.</param> /// <param name="redrawScope">Scope for this command builder. See #GetRedrawScope.</param> /// <param name="renderInGame">If true, this builder will be rendered in standalone games and in the editor even if gizmos are disabled.</param> public static CommandBuilder GetBuilder(DrawingData.Hasher hasher, RedrawScope redrawScope = default, bool renderInGame = false) { return(instance.gizmos.GetBuilder(hasher, redrawScope, renderInGame)); }
/// <summary> /// Get an empty builder for queuing drawing commands. /// /// See: <see cref="Drawing.CommandBuilder"/> /// </summary> /// <param name="redrawScope">Scope for this command builder. See #GetRedrawScope.</param> /// <param name="renderInGame">If true, this builder will be rendered in standalone games and in the editor even if gizmos are disabled. /// If false, it will only be rendered in the editor when gizmos are enabled.</param> public static CommandBuilder GetBuilder(RedrawScope redrawScope, bool renderInGame = false) { return(instance.gizmos.GetBuilder(redrawScope, renderInGame)); }
public void Init(AstarPath active, DrawingData.Hasher hasher, DrawingData gizmos, RedrawScope redrawScope) { if (active != null) { debugData = active.debugPathData; debugPathID = active.debugPathID; debugMode = active.debugMode; debugFloor = active.debugFloor; debugRoof = active.debugRoof; showSearchTree = active.showSearchTree && debugData != null; } this.hasher = hasher; builder = gizmos.GetBuilder(hasher, redrawScope); }
public static GraphGizmoHelper GetGizmoHelper(DrawingData gizmos, AstarPath active, DrawingData.Hasher hasher, RedrawScope redrawScope) { var helper = ObjectPool <GraphGizmoHelper> .Claim(); helper.Init(active, hasher, gizmos, redrawScope); return(helper); }
public static GraphGizmoHelper GetSingleFrameGizmoHelper(DrawingData gizmos, AstarPath active, RedrawScope redrawScope) { return(GetGizmoHelper(gizmos, active, DrawingData.Hasher.NotSupplied, redrawScope)); }