private static void DrawHandleInspector( SerializedProperty handleTypeProp, SerializedProperty handle1Prop, SerializedProperty handle2Prop) { BezierPoint.HandleStyle handleType = (BezierPoint.HandleStyle)handleTypeProp.enumValueIndex; if (handleType != BezierPoint.HandleStyle.None) { Vector3 newHandle1 = EditorGUILayout.Vector3Field("Handle 1", handle1Prop.vector3Value); Vector3 newHandle2 = EditorGUILayout.Vector3Field("Handle 2", handle2Prop.vector3Value); if (handleType == BezierPoint.HandleStyle.Connected) { if (newHandle1 != handle1Prop.vector3Value) { handle1Prop.vector3Value = newHandle1; handle2Prop.vector3Value = -newHandle1; } else if (newHandle2 != handle2Prop.vector3Value) { handle1Prop.vector3Value = -newHandle2; handle2Prop.vector3Value = newHandle2; } } else { handle1Prop.vector3Value = newHandle1; handle2Prop.vector3Value = newHandle2; } } }
private static BezierPoint.HandleStyle DrawTypeInspector( SerializedProperty handleTypeProp, SerializedProperty handle1Prop, SerializedProperty handle2Prop) { Assert.IsNotNull(handleTypeProp); Assert.IsNotNull(handle1Prop); Assert.IsNotNull(handle2Prop); BezierPoint.HandleStyle newHandleType = (BezierPoint.HandleStyle)EditorGUILayout.EnumPopup( "Handle Type", (BezierPoint.HandleStyle)handleTypeProp.intValue); if (newHandleType != (BezierPoint.HandleStyle)handleTypeProp.intValue) { handleTypeProp.intValue = (int)newHandleType; switch (newHandleType) { case BezierPoint.HandleStyle.Connected: if (handle1Prop.vector3Value != Vector3.zero) { handle2Prop.vector3Value = -handle1Prop.vector3Value; } else if (handle2Prop.vector3Value != Vector3.zero) { handle1Prop.vector3Value = -handle2Prop.vector3Value; } else { handle1Prop.vector3Value = new Vector3(0.1f, 0, 0); handle2Prop.vector3Value = new Vector3(-0.1f, 0, 0); } break; case BezierPoint.HandleStyle.Broken: if (handle1Prop.vector3Value == Vector3.zero && handle2Prop.vector3Value == Vector3.zero) { handle1Prop.vector3Value = new Vector3(0.1f, 0, 0); handle2Prop.vector3Value = new Vector3(-0.1f, 0, 0); } break; case BezierPoint.HandleStyle.None: handle1Prop.vector3Value = Vector3.zero; handle2Prop.vector3Value = Vector3.zero; break; } } return(newHandleType); }
public BezierPoint AddPoint_LocalSpace(BezierPoint.HandleStyle handleStyle , Vector3 pointLocalPosition , Vector3 handle1LocalPosition , Vector3 handle2LocalPosition) { m_IsDirty = true; BezierPoint newPoint = new GameObject("Point " + Points.Count).AddComponent <BezierPoint>(); newPoint.SetOwner(this); newPoint.transform.parent = transform; newPoint.MyHandleStyle = handleStyle; newPoint.SetPosition_LocalSpace(pointLocalPosition); newPoint.SetHandle1Position_LocalSpace(handle1LocalPosition); newPoint.SetHandle2Position_LocalSpace(handle2LocalPosition); Points.Add(newPoint); return(newPoint); }
public override void OnInspectorGUI() { serializedObject.Update(); BezierPoint.HandleStyle newHandleType = (BezierPoint.HandleStyle)EditorGUILayout.EnumPopup("Handle Type", (BezierPoint.HandleStyle)handleTypeProp.intValue); if (newHandleType != (BezierPoint.HandleStyle)handleTypeProp.intValue) { handleTypeProp.intValue = (int)newHandleType; if ((int)newHandleType == 0) { if (handle1Prop.vector3Value != Vector3.zero) { handle2Prop.vector3Value = -handle1Prop.vector3Value; } else if (handle2Prop.vector3Value != Vector3.zero) { handle1Prop.vector3Value = -handle2Prop.vector3Value; } else { handle1Prop.vector3Value = new Vector3(0.1f, 0, 0); handle2Prop.vector3Value = new Vector3(-0.1f, 0, 0); } } else if ((int)newHandleType == 1) { if (handle1Prop.vector3Value != Vector3.zero) { float tempLength = handle2Prop.vector3Value.magnitude; handle2Prop.vector3Value = -handle1Prop.vector3Value.normalized * tempLength; } else if (handle2Prop.vector3Value != Vector3.zero) { float tempLength = handle1Prop.vector3Value.magnitude; handle1Prop.vector3Value = -handle2Prop.vector3Value.normalized * tempLength; } else { handle1Prop.vector3Value = new Vector3(0.1f, 0, 0); handle2Prop.vector3Value = new Vector3(-0.1f, 0, 0); } } else if ((int)newHandleType == 2) { if (handle1Prop.vector3Value == Vector3.zero && handle2Prop.vector3Value == Vector3.zero) { handle1Prop.vector3Value = new Vector3(0.1f, 0, 0); handle2Prop.vector3Value = new Vector3(-0.1f, 0, 0); } } else if ((int)newHandleType == 3) { handle1Prop.vector3Value = Vector3.zero; handle2Prop.vector3Value = Vector3.zero; } } if (handleTypeProp.intValue != 3) { Vector3 newHandle1 = EditorGUILayout.Vector3Field("Handle 1", handle1Prop.vector3Value); Vector3 newHandle2 = EditorGUILayout.Vector3Field("Handle 2", handle2Prop.vector3Value); if (handleTypeProp.intValue == 0) { if (newHandle1 != handle1Prop.vector3Value) { handle1Prop.vector3Value = newHandle1; handle2Prop.vector3Value = -newHandle1; } else if (newHandle2 != handle2Prop.vector3Value) { handle1Prop.vector3Value = -newHandle2; handle2Prop.vector3Value = newHandle2; } } else if (handleTypeProp.intValue == 1) { if (newHandle1 != handle1Prop.vector3Value) { handle1Prop.vector3Value = newHandle1; handle2Prop.vector3Value = -newHandle1; } else if (newHandle2 != handle2Prop.vector3Value) { handle1Prop.vector3Value = -newHandle2; handle2Prop.vector3Value = newHandle2; } } else if (handleTypeProp.intValue == 2) { handle1Prop.vector3Value = newHandle1; handle2Prop.vector3Value = newHandle2; } } if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } }