VolumetricFogSubVolumeEditor.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditor.IMGUI.Controls;
  4. namespace VolumetricFogAndMist2
  5. {
  6. [CustomEditor(typeof(VolumetricFogSubVolume))]
  7. public class VolumetricFogSubVolumeEditor : Editor
  8. {
  9. SerializedProperty profile, fadeDistance;
  10. private void OnEnable()
  11. {
  12. profile = serializedObject.FindProperty("profile");
  13. fadeDistance = serializedObject.FindProperty("fadeDistance");
  14. }
  15. public override void OnInspectorGUI()
  16. {
  17. serializedObject.Update();
  18. EditorGUILayout.PropertyField(profile);
  19. EditorGUILayout.PropertyField(fadeDistance);
  20. serializedObject.ApplyModifiedProperties();
  21. }
  22. private readonly BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
  23. protected virtual void OnSceneGUI() {
  24. VolumetricFogSubVolume vl = (VolumetricFogSubVolume)target;
  25. Bounds bounds = vl.GetBounds();
  26. m_BoundsHandle.center = bounds.center;
  27. m_BoundsHandle.size = bounds.size;
  28. // draw the handle
  29. EditorGUI.BeginChangeCheck();
  30. m_BoundsHandle.DrawHandle();
  31. if (EditorGUI.EndChangeCheck()) {
  32. // record the target object before setting new values so changes can be undone/redone
  33. Undo.RecordObject(vl, "Change Bounds");
  34. // copy the handle's updated data back to the target object
  35. Bounds newBounds = new Bounds();
  36. newBounds.center = m_BoundsHandle.center;
  37. newBounds.size = m_BoundsHandle.size;
  38. vl.SetBounds(newBounds);
  39. }
  40. }
  41. }
  42. }