Added custom inspector for VolumeObject; Change the name of AoVolume to VolumeObject;
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using UnityEditor;
|
|
using UnityEditor.IMGUI.Controls;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Misaki.AoVolume.Editor
|
|
{
|
|
[CustomEditor(typeof(VolumeObject))]
|
|
[CanEditMultipleObjects]
|
|
public class VolumeObjectView : UnityEditor.Editor
|
|
{
|
|
[SerializeField]
|
|
private VisualTreeAsset _viewAsset;
|
|
|
|
private readonly BoxBoundsHandle _boundsHandle = new()
|
|
{
|
|
wireframeColor = Color.green,
|
|
handleColor = Color.green
|
|
};
|
|
|
|
public override VisualElement CreateInspectorGUI()
|
|
{
|
|
if (_viewAsset == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var view = _viewAsset.Instantiate();
|
|
view.dataSource = target;
|
|
|
|
view.Q<Button>("force-update-button").clicked += () =>
|
|
{
|
|
var volumeObject = target as VolumeObject;
|
|
volumeObject.ForceDataUpdate();
|
|
};
|
|
|
|
return view;
|
|
}
|
|
|
|
private void OnSceneGUI()
|
|
{
|
|
var volume = (VolumeObject)target;
|
|
|
|
using (new Handles.DrawingScope(volume.transform.localToWorldMatrix))
|
|
{
|
|
_boundsHandle.center = Vector3.zero;
|
|
_boundsHandle.size = volume.data.size;
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
_boundsHandle.DrawHandle();
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
Undo.RecordObject(volume, string.Format("Change {0} Volume Size", target.name));
|
|
volume.data.size = _boundsHandle.size;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |