forked from keenanwoodall/Deform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulgeDeformerEditor.cs
109 lines (88 loc) · 3.45 KB
/
BulgeDeformerEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using UnityEngine;
using UnityEditor;
using Beans.Unity.Editor;
using Deform;
namespace DeformEditor
{
[CustomEditor (typeof (BulgeDeformer)), CanEditMultipleObjects]
public class BulgeDeformerEditor : DeformerEditor
{
private class Content
{
public static readonly GUIContent Factor = DeformEditorGUIUtility.DefaultContent.Factor;
public static readonly GUIContent Top = DeformEditorGUIUtility.DefaultContent.Top;
public static readonly GUIContent Bottom = DeformEditorGUIUtility.DefaultContent.Bottom;
public static readonly GUIContent Smooth = DeformEditorGUIUtility.DefaultContent.Smooth;
public static readonly GUIContent Axis = DeformEditorGUIUtility.DefaultContent.Axis;
}
private class Properties
{
public SerializedProperty Factor;
public SerializedProperty Top;
public SerializedProperty Bottom;
public SerializedProperty Smooth;
public SerializedProperty Axis;
public Properties (SerializedObject obj)
{
Factor = obj.FindProperty ("factor");
Top = obj.FindProperty ("top");
Bottom = obj.FindProperty ("bottom");
Smooth = obj.FindProperty ("smooth");
Axis = obj.FindProperty ("axis");
}
}
private Properties properties;
private VerticalBoundsHandle boundsHandle = new VerticalBoundsHandle ();
protected override void OnEnable ()
{
base.OnEnable ();
properties = new Properties (serializedObject);
boundsHandle.handleCapFunction = DeformHandles.HandleCapFunction;
boundsHandle.drawGuidelineCallback = (a, b) => DeformHandles.Line (a, b, DeformHandles.LineMode.LightDotted);
}
public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();
serializedObject.UpdateIfRequiredOrScript ();
EditorGUILayout.PropertyField (properties.Factor, Content.Factor);
EditorGUILayoutx.MinField (properties.Top, properties.Bottom.floatValue, Content.Top);
EditorGUILayoutx.MaxField (properties.Bottom, properties.Top.floatValue, Content.Bottom);
EditorGUILayout.PropertyField (properties.Smooth, Content.Smooth);
EditorGUILayout.PropertyField (properties.Axis, Content.Axis);
serializedObject.ApplyModifiedProperties ();
EditorApplication.QueuePlayerLoopUpdate ();
}
public override void OnSceneGUI ()
{
base.OnSceneGUI ();
var bulge = target as BulgeDeformer;
DrawFactorHandle (bulge);
boundsHandle.handleColor = DeformEditorSettings.SolidHandleColor;
boundsHandle.screenspaceHandleSize = DeformEditorSettings.ScreenspaceSliderHandleCapSize;
if (boundsHandle.DrawHandle (bulge.Top, bulge.Bottom, bulge.Axis, Vector3.forward))
{
Undo.RecordObject (bulge, "Changed Bounds");
bulge.Top = boundsHandle.top;
bulge.Bottom = boundsHandle.bottom;
}
EditorApplication.QueuePlayerLoopUpdate ();
}
private void DrawFactorHandle (BulgeDeformer bulge)
{
var direction = bulge.Axis.up;
var center = bulge.Axis.position + (bulge.Axis.forward * ((bulge.Top + bulge.Bottom) * 0.5f));
var worldPosition = center + direction * ((bulge.Factor + 1f) * 0.5f);
DeformHandles.Line (center, worldPosition, DeformHandles.LineMode.LightDotted);
using (var check = new EditorGUI.ChangeCheckScope ())
{
var newWorldPosition = DeformHandles.Slider (worldPosition, direction);
if (check.changed)
{
var newFactor = DeformHandlesUtility.DistanceAlongAxis (bulge.Axis, bulge.Axis.position, newWorldPosition, Axis.Y) * 2f - 1f;
Undo.RecordObject (bulge, "Changed Factor");
bulge.Factor = newFactor;
}
}
}
}
}