42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using UnityEditor;
|
|
using UnityEditor.IMGUI.Controls;
|
|
using UnityEngine;
|
|
using Ashwild.Harvesting;
|
|
|
|
namespace Ashwild.EditorTools
|
|
{
|
|
[CustomEditor(typeof(ScatterExclusionVolume))]
|
|
public class ScatterExclusionVolumeEditor : Editor
|
|
{
|
|
private readonly BoxBoundsHandle boxHandle = new BoxBoundsHandle();
|
|
|
|
private void OnSceneGUI()
|
|
{
|
|
ScatterExclusionVolume vol = (ScatterExclusionVolume)target;
|
|
|
|
// Poignées dans l'espace local du volume (gère la rotation).
|
|
Matrix4x4 m = Matrix4x4.TRS(vol.transform.position, vol.transform.rotation, Vector3.one);
|
|
using (new Handles.DrawingScope(m))
|
|
{
|
|
boxHandle.center = Vector3.zero;
|
|
boxHandle.size = vol.size;
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
boxHandle.DrawHandle();
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
Undo.RecordObject(vol, "Resize Exclusion Volume");
|
|
Undo.RecordObject(vol.transform, "Move Exclusion Volume");
|
|
|
|
// Le centre du handle bouge en local quand on tire une face : on le repasse en monde.
|
|
vol.transform.position = m.MultiplyPoint3x4(boxHandle.center);
|
|
vol.size = new Vector3(
|
|
Mathf.Max(0.1f, boxHandle.size.x),
|
|
Mathf.Max(0.1f, boxHandle.size.y),
|
|
Mathf.Max(0.1f, boxHandle.size.z));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|