Skip to content

Instantly share code, notes, and snippets.

@Milk-Drinker01
Created September 24, 2022 15:46
Show Gist options
  • Select an option

  • Save Milk-Drinker01/9bc788ef350cd78b319e4a6a5c2e3079 to your computer and use it in GitHub Desktop.

Select an option

Save Milk-Drinker01/9bc788ef350cd78b319e4a6a5c2e3079 to your computer and use it in GitHub Desktop.
Unity Editor Bounds Handle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.IMGUI.Controls;
#endif
public class BoxBoundsExample : MonoBehaviour
{
public Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
}
#if UNITY_EDITOR
[CustomEditor(typeof(BoxBoundsExample))]
public class BoxBoundsEditor : Editor
{
private BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
void OnSceneGUI()
{
BoxBoundsExample boundsScript = (BoxBoundsExample)target;
m_BoundsHandle.center = boundsScript.bounds.center;
m_BoundsHandle.size = boundsScript.bounds.size;
// draw the handle
EditorGUI.BeginChangeCheck();
m_BoundsHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(boundsScript, "Change Bounds");
Bounds newBounds = new Bounds();
newBounds.center = m_BoundsHandle.center;
newBounds.size = m_BoundsHandle.size;
boundsScript.bounds = newBounds;
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment