Hello,
I wrote an editor script for calculating Bounds of a scene. To prove, if the calculation was correct I would like to visualize the Bounds via a Gizmo. Unfortunately this is not possible, I am getting this error in Unity:
ArgumentException: Gizmo drawing functions can only be used in OnDrawGizmos and OnDrawGizmosSelected.
Any ideas how to make this work as easy as possible?
Here is my code:
public class AutoLightProbes : EditorWindow
{
public static Bounds sceneBounds = new Bounds(Vector3.zero, Vector3.zero);
[MenuItem("Tools/AutoLightProbes/CalculateLightProbes")]
private static void CalculateLightProbes()
{
DefineSceneBounds();
OnDrawGizmos();
}
// 1a) Find out the bounds of the scene
public static void DefineSceneBounds()
{
foreach (Renderer renderer in FindObjectsOfType(typeof(Renderer)))
{
sceneBounds.Encapsulate(renderer.bounds);
}
Debug.Log(sceneBounds);
}
// 1b) Draw Gizmo of the szeneBounds
public static void OnDrawGizmos()
{
Gizmos.color = Color.magenta;
Gizmos.DrawCube(sceneBounds.center, sceneBounds.size);
}
}
Thank you
Huxi