int gaveWarningOnFrame = -1;         //Just to avoid lag when debugging.
        bool CanDraw(InfoDebug infoDebug)
        {
            if (triangleCount <= InfoDebug.drawSafetyMaxTriangleCount || infoDebug.overrideDrawSafety)
            {
                return(true);
            }
            else if (gaveWarningOnFrame != Time.frameCount)
            {
                Debug.LogWarning("The mesh of GameObject " + infoDebug.transform.name + " has " + triangleCount + " triangles. Drawing the mesh tree might cause lots of lag. Enable the overrideDrawSafety to draw anyways.", infoDebug.transform.gameObject);
                gaveWarningOnFrame = Time.frameCount;
            }

            return(false);
        }
 public void DrawDebugs(InfoDebug infoDebug)
 {
     if (infoDebug.drawAABBTree || infoDebug.drawTriangleTree)
     {
         if (CanDraw(infoDebug))
         {
             if (infoDebug.drawAABBTree)
             {
                 TraverseNodes(rootNode, DrawAABBTree, DrawAABBTree, infoDebug.transform);
             }
             if (infoDebug.drawTriangleTree)
             {
                 TraverseNodes(rootNode, null, DrawTriangleTree, infoDebug.transform);
             }
         }
     }
 }
        public void FindClosestTriangles(Node node, AABB aabb, HashSet <int> triangles, InfoDebug infoDebug = null)
        {
            if (node.triangles == null)
            {
                if (AABB.AABBOverlapsAABB(node.aabb, aabb))
                {
                    FindClosestTriangles(node.positiveChild, aabb, triangles, infoDebug);
                    FindClosestTriangles(node.negativeChild, aabb, triangles, infoDebug);
                }
            }
            else
            {
                if (AABB.AABBOverlapsAABB(node.aabb, aabb))
                {
                    #region Debug
#if UNITY_EDITOR
                    if (infoDebug != null && (infoDebug.drawAABBOnContact || infoDebug.drawTrianglesOnContact) && CanDraw(infoDebug))
                    {
                        if (infoDebug.drawAABBOnContact)
                        {
                            DrawAABBOnContact(node, infoDebug.transform);
                        }
                        if (infoDebug.drawTrianglesOnContact)
                        {
                            DrawTrianglesOnContact(node, infoDebug.transform);
                        }
                    }
#endif
                    #endregion

                    //I originally used a hashset as a way to avoid duplicate triangles, however with new changes to
                    //the tree there should be no chance of duplicate triangles, so a hashset might not be needed anymore.
                    for (int i = 0; i < node.triangles.Length; i++)
                    {
                        triangles.Add(node.triangles[i]);
                    }
                }
            }
        }