示例#1
0
 public static void DrawCell(Cell cell, Color color, Vector3 gridScale, bool mode2D)
 {
     DebugDrawUtils.DrawBounds(cell.Bounds, color, gridScale, mode2D);
 }
示例#2
0
        public override void DebugDraw()
        {
            if (!bspModel)
            {
                return;
            }

            var gridSize3D     = new Vector3(bspConfig.gridSize.x, 0, bspConfig.gridSize.y);
            var graphQuery     = bspModel.CreateGraphQuery();
            var discardedColor = new Color(0, 0, 0, 0.35f);
            var debugTextItems = new List <DebugTextItem>();
            int debugDoorIndex = 0;

            foreach (var node in bspModel.nodes)
            {
                if (!node.discarded)
                {
                    //continue;
                }
                //DebugDrawUtils.DrawBounds(node.bounds, Color.green, gridSize3D, false);

                // Draw the room
                if (node.children.Length == 0)
                {
                    // only render leaf nodes
                    var paddedBounds = node.paddedBounds;
                    var color        = node.discarded ? discardedColor : node.debugColor;
                    DebugDrawUtils.DrawBounds(paddedBounds, color, gridSize3D, false);
                }

                var connectionColor = Color.red;

                bool renderedDoors = false;
                // Draw the connected rooms
                //foreach (var connectedNodeId in node.connectedRooms)
                foreach (var leafConnection in node.subtreeLeafConnections)
                {
                    var room0 = graphQuery.GetNode(leafConnection.room0);
                    var room1 = graphQuery.GetNode(leafConnection.room1);
                    //var connectedNode = graphQuery.GetNode(connectedNodeId);
                    var intersection = Rectangle.Intersect(room0.bounds, room1.bounds);
                    var center       = intersection.Center();
                    var centerF      = IntVector.ToV3(center);
                    var centerWorld  = Vector3.Scale(centerF, gridSize3D);
                    var offsetStart  = Vector3.zero;
                    var offsetEnd    = Vector3.zero;
                    var padding      = bspConfig.roomPadding;

                    var doorOffset0 = Vector3.zero;
                    var doorOffset1 = Vector3.zero;

                    var textOffset = Vector3.zero;

                    if (intersection.Size.x > 0)
                    {
                        offsetStart.z -= padding;
                        offsetEnd.z   += padding;

                        doorOffset0.x -= 0.0f;
                        doorOffset1.x += 1.0f;

                        textOffset.x -= 1;
                        textOffset.z += 1.0f;
                    }
                    else
                    {
                        offsetStart.x -= padding;
                        offsetEnd.x   += padding;

                        doorOffset0.z -= 0.0f;
                        doorOffset1.z += 1.0f;

                        textOffset.x -= 0.25f;
                    }

                    offsetStart = Vector3.Scale(offsetStart, gridSize3D);
                    offsetEnd   = Vector3.Scale(offsetEnd, gridSize3D);

                    doorOffset0 = Vector3.Scale(doorOffset0, gridSize3D);
                    doorOffset1 = Vector3.Scale(doorOffset1, gridSize3D);

                    textOffset = Vector3.Scale(textOffset, gridSize3D);

                    bool discarded = (room0.discarded || room1.discarded);
                    var  doorColor = discarded ? discardedColor : connectionColor;
                    Debug.DrawLine(centerWorld + offsetStart + doorOffset0, centerWorld + offsetEnd + doorOffset0, doorColor);
                    Debug.DrawLine(centerWorld + offsetStart + doorOffset1, centerWorld + offsetEnd + doorOffset1, doorColor);

                    if (!discarded)
                    {
                        var debugText = new DebugTextItem();
                        debugText.position = centerWorld + textOffset;
                        debugText.color    = Color.black;
                        debugText.message  = "" + (char)('A' + debugDoorIndex);
                        debugTextItems.Add(debugText);

                        renderedDoors = true;
                    }
                }

                if (renderedDoors)
                {
                    debugDoorIndex++;
                }
            }

            var debugText3D = GetComponent <DebugText3D>();

            if (debugText3D != null)
            {
                debugText3D.items = debugTextItems.ToArray();
            }
        }