/// <summary> /// Draws a rectangle based on a Rect and color /// </summary> /// <param name="rectangle">Rectangle.</param> /// <param name="color">Color.</param> public static void DrawRectangle(Rect rectangle, Color color) { Vector3 pos = new Vector3(rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2, 0.0f); Vector3 scale = new Vector3(rectangle.width, rectangle.height, 0.0f); PhysicsDebugger.DrawRectangle(pos, color, scale); }
/// <summary> /// On DrawGizmos, we draw lines to show the path the object will follow /// </summary> protected virtual void OnDrawGizmos() { #if UNITY_EDITOR if (PathElements == null) { return; } if (PathElements.Count == 0) { return; } // if we haven't stored the object's original position yet, we do it if (_originalTransformPositionStatus == false) { _originalTransformPosition = transform.position; _originalTransformPositionStatus = true; } // if we're not in runtime mode and the transform has changed, we update our position if (transform.hasChanged && _active == false) { _originalTransformPosition = transform.position; } // for each point in the path for (int i = 0; i < PathElements.Count; i++) { // we draw a green point PhysicsDebugger.DrawGizmoPoint(_originalTransformPosition + PathElements[i].PathElementPosition, 0.2f, Color.green); // we draw a line towards the next point in the path if ((i + 1) < PathElements.Count) { Gizmos.color = Color.white; Gizmos.DrawLine(_originalTransformPosition + PathElements[i].PathElementPosition, _originalTransformPosition + PathElements[i + 1].PathElementPosition); } // we draw a line from the first to the last point if we're looping if ((i == PathElements.Count - 1) && (CycleOption == CycleOptions.Loop)) { Gizmos.color = Color.white; Gizmos.DrawLine(_originalTransformPosition + PathElements[0].PathElementPosition, _originalTransformPosition + PathElements[i].PathElementPosition); } } // if the game is playing, we add a blue point to the destination, and a red point to the last visited point if (Application.isPlaying) { PhysicsDebugger.DrawGizmoPoint(_originalTransformPosition + _currentPoint.Current, 0.2f, Color.blue); PhysicsDebugger.DrawGizmoPoint(_originalTransformPosition + _previousPoint, 0.2f, Color.red); } #endif }
void OnDrawGizmos() { debuggingEnabled = visualizeHeirarchy || visualizeBoundingBoxes || visualizePotentialCollisions || visualizeBVHTree; if (!debuggingEnabled) { return; } if (boundingInternalNodeBuffer != null) { boundingInternalNodeBuffer.GetData(nodeData); } if (boundingLeafNodeBuffer != null) { boundingLeafNodeBuffer.GetData(leafData); } if (mergeOutputBuffer != null) { mergeOutputBuffer.GetData(particleData); } if (showVelocities) { PhysicsDebugger.ShowVelocities(ref particleData); } if (visualizeHeirarchy) { PhysicsDebugger.FindRoot(ref leafData, ref nodeData, ref particleData, heirarchyLeaf); } if (visualizeBoundingBoxes) { PhysicsDebugger.VisualizeBoundingBoxes(ref nodeData, ref leafData, boundingBoxMin); } if (visualizePotentialCollisions) { PhysicsDebugger.VisualisePotentialCollisions(ref leafData, ref nodeData, ref particleData, heirarchyLeafToCheckForCollision, diameter); } if (visualizeBVHTree) { PhysicsDebugger.VisualizeBVHTree(ref nodeData, ref leafData, treeScale, leafData[heirarchyLeafToCheckForCollision]); } }
void CreateBoundingBox(internalNode node, ref internalNode[] internalNodes, ref internalNode[] leafNodes) { internalNode ChildA; internalNode ChildB; PhysicsDebugger.GetNodeChildren(node, out ChildA, out ChildB, ref leafNodes, ref internalNodes); if (!PhysicsDebugger.isLeaf(ChildA)) { CreateBoundingBox(ChildA, ref internalNodes, ref leafNodes); } if (!PhysicsDebugger.isLeaf(ChildB)) { CreateBoundingBox(ChildB, ref internalNodes, ref leafNodes); } Vector3 minPoint; Vector3 maxPoint; PhysicsDebugger.CalculateAABB(node, out minPoint, out maxPoint, ref internalNodes, ref leafNodes); internalNodes[node.nodeId].minPos = minPoint; internalNodes[node.nodeId].maxPos = maxPoint; }