private static void CreateGenericSpline <T>(string nameType) where T : ControllerStick { GameObject splineObj = new GameObject(nameType); T splineController = splineObj.AddComponent <T>(); SplineBase spline = null; if (Selection.activeGameObject != null) { spline = Selection.activeGameObject.GetComponent <SplineBase>(); splineObj.transform.SetParent(Selection.activeGameObject.transform); } Undo.RegisterCreatedObjectUndo(splineObj, nameType); Selection.activeGameObject = splineObj; SceneView.lastActiveSceneView.MoveToView(splineObj.transform); GameObjectUtility.EnsureUniqueNameForSibling(splineObj); Editor splineEditorGeneric = CreateEditor((ControllerStick)splineController, typeof(ControllerStickEditor)); ControllerStickEditor splineEditor = (ControllerStickEditor)splineEditorGeneric; splineEditor.ConstructSpline(spline); }
static void DrawGizmos(ControllerStick sticker, GizmoType selectionType) { if (Application.isPlaying || sticker == null || sticker.SplineBase == null) { return; } if (sticker.AnchorOnSplineChange && Selection.activeGameObject != sticker.gameObject) { ControllerStickEditor controllerStickEditor = (ControllerStickEditor)CreateEditor((ControllerStick)sticker) as ControllerStickEditor; SerializedProperty pathPosition = controllerStickEditor.GetPropertie("_pathPosition"); float closestPosOnSpline = sticker.SplineBase.FindClosestPoint(sticker.transform.position, 0, -1, 10, sticker.PositionUnits); float current = pathPosition.floatValue; float diff = Mathf.Abs(closestPosOnSpline - current); if (diff > 0.002f) { pathPosition.floatValue = closestPosOnSpline; //controllerStickEditor.UpdatePositionFromEditor(); //controllerStickEditor.GetPropertie("_lastPosition").vector3Value = sticker.transform.position; controllerStickEditor.ApplyModification(); sticker.AttemptToStick(); } DestroyImmediate(controllerStickEditor); } else { //Debug.Log("stick like usual"); sticker.AttemptToStick(); } Gizmos.DrawLine(sticker.transform.position, sticker.transform.position); Gizmos.DrawLine(sticker.transform.position, sticker.PositionWithoutOffsetFromSpline(sticker.PathPosition)); }