You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.9 KiB
100 lines
3.9 KiB
using UnityEditor; |
|
using UnityEngine; |
|
|
|
namespace UDE_HAND_INTERACTION |
|
{ |
|
[CustomEditor(typeof(RegularShapeFit))] |
|
[CanEditMultipleObjects] |
|
public class RegularShapeFitEditor : Editor |
|
{ |
|
private RegularShapeFit regularShapeFit; |
|
private SerializedProperty TargetObjectProperty; |
|
private Transform TargetObject; |
|
private void OnEnable() |
|
{ |
|
regularShapeFit = target as RegularShapeFit; |
|
TargetObjectProperty = serializedObject.FindProperty("TargetObject"); |
|
} |
|
|
|
public override void OnInspectorGUI() |
|
{ |
|
base.OnInspectorGUI(); |
|
TargetObject = TargetObjectProperty.objectReferenceValue as Transform; |
|
} |
|
|
|
public void OnSceneGUI() |
|
{ |
|
if (TargetObject == null) |
|
{ |
|
return; |
|
} |
|
if(regularShapeFit.SpecialSphere || regularShapeFit.SpecialCube) |
|
{ |
|
regularShapeFit.startPoint = Vector3.zero; |
|
regularShapeFit.endPoint = Vector3.zero; |
|
} |
|
DrawTransformControls(regularShapeFit, TargetObject); |
|
|
|
if (Event.current.type == EventType.Repaint) |
|
{ |
|
DrawReferenceLines(regularShapeFit, TargetObject); |
|
} |
|
} |
|
|
|
private void DrawTransformControls(RegularShapeFit regularShapeFit, Transform TargetObject) |
|
{ |
|
EditorGUI.BeginChangeCheck(); |
|
Quaternion handleRotation = TargetObject.rotation; |
|
|
|
Vector3 startPosition = Handles.PositionHandle(TargetObject.TransformPoint(regularShapeFit.startPoint), handleRotation); |
|
if (EditorGUI.EndChangeCheck()) |
|
{ |
|
regularShapeFit.startPoint = TargetObject.InverseTransformPoint(startPosition); |
|
} |
|
EditorGUI.BeginChangeCheck(); |
|
Vector3 endPosition = Handles.PositionHandle(TargetObject.TransformPoint(regularShapeFit.endPoint), handleRotation); |
|
if (EditorGUI.EndChangeCheck()) |
|
{ |
|
regularShapeFit.endPoint = TargetObject.InverseTransformPoint(endPosition); |
|
} |
|
} |
|
|
|
private void DrawReferenceLines(RegularShapeFit regularShapeFit, Transform TargetObject) |
|
{ |
|
Vector3 start = regularShapeFit.RealStart; |
|
Vector3 end = regularShapeFit.RealEnd; |
|
Vector3 ArcDir = regularShapeFit.GetArcDir(); |
|
Vector3 direction = TargetObject.TransformDirection(regularShapeFit.LocalDirection); |
|
|
|
float radius = regularShapeFit.DrawRadius; |
|
Handles.color = EditorConstants.RED_COLOR; |
|
if (regularShapeFit.SpecialSphere) |
|
{ |
|
Handles.DrawWireArc(start, direction, ArcDir, 360, radius); |
|
Handles.DrawWireArc(start, Vector3.right, radius * Vector3.forward, 360, radius); |
|
Handles.DrawWireArc(start, Vector3.forward, radius * Vector3.right, 360, radius); |
|
} |
|
else if (regularShapeFit.SpecialCube) |
|
{ |
|
Handles.DrawWireCube(start, Vector3.one * radius); |
|
} |
|
else |
|
{ |
|
Handles.DrawWireArc(start, direction, ArcDir, 360, radius); |
|
Handles.DrawWireArc(end, direction, ArcDir, 360, radius); |
|
Handles.DrawLine(start, end); |
|
Handles.color = EditorConstants.PRIMARY_COLOR_DISABLED; |
|
for (int i = 0; i < 12; ++i) |
|
{ |
|
Vector3 Cur_dir = Quaternion.AngleAxis(i * 30, direction) * ArcDir; |
|
Vector3 Pre_dir = Quaternion.AngleAxis((i - 1) * 30, direction) * ArcDir; |
|
Vector3 Nxt_dir = Quaternion.AngleAxis((i + 1) * 30, direction) * ArcDir; |
|
Handles.DrawLine(start + Cur_dir * radius, end + Pre_dir * radius); |
|
Handles.DrawLine(start + Cur_dir * radius, end + Nxt_dir * radius); |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
}
|
|
|