public bool ChangeSplineAndPosition(SplineBase splineBase, float newPosition)
        {
            if (_splineController.SplineBase == splineBase)
            {
                ChangePosition(newPosition);
                return(false);
            }
            SerializedProperty spline       = this.GetPropertie("_spline");
            SerializedProperty pathPosition = this.GetPropertie("_pathPosition");

            spline.objectReferenceValue = splineBase;
            pathPosition.floatValue     = newPosition;
            this.ApplyModification();

            ResetEventsOfControllersEvents(_splineController.transform);

            ControllerStickOffset[] allOffset = FindObjectsOfType <ControllerStickOffset>();
            for (int i = 0; i < allOffset.Length; i++)
            {
                if (allOffset[i] == _splineController)
                {
                    continue;
                }
                ControllerStickOffsetEditor offsetEditor = (ControllerStickOffsetEditor)UnityEditor.Editor.CreateEditor((ControllerStickOffset)allOffset[i], typeof(ControllerStickOffsetEditor));
                offsetEditor.ChangeSplineOfController(splineBase);
                DestroyImmediate(offsetEditor);

                ResetEventsOfControllersEvents(allOffset[i].transform);
            }

            this.ApplyModification();
            return(true);
        }
Esempio n. 2
0
        private static void CreateSplineControllerStick()
        {
            string nameStickOffet = "Controller Offset From Other Sticker";

            ControllerStick stickReference = null;
            GameObject      stickOffsetGameObject;

            if (Selection.activeGameObject != null)
            {
                stickReference = Selection.activeGameObject.GetComponent <ControllerStick>();
            }

            if (stickReference != null)
            {
                stickOffsetGameObject = new GameObject(nameStickOffet);
                stickOffsetGameObject.transform.SetParent(stickReference.transform.parent);
                stickOffsetGameObject.transform.SetSiblingIndex(stickReference.transform.GetSiblingIndex() + 1);
                Undo.RegisterCreatedObjectUndo(stickOffsetGameObject, nameStickOffet);
                GameObjectUtility.EnsureUniqueNameForSibling(stickOffsetGameObject);
            }
            else if (Selection.activeGameObject != null && stickReference == null)
            {
                stickOffsetGameObject = Selection.activeGameObject;
            }
            else
            {
                stickOffsetGameObject = new GameObject(nameStickOffet);
                GameObjectUtility.EnsureUniqueNameForSibling(stickOffsetGameObject);
                Undo.RegisterCreatedObjectUndo(stickOffsetGameObject, nameStickOffet);
            }

            //GameObject
            ControllerStickOffset stickOffset = stickOffsetGameObject.AddComponent <ControllerStickOffset>();

            Selection.activeGameObject = stickOffsetGameObject;
            SceneView.lastActiveSceneView.MoveToView(stickOffsetGameObject.transform);
            ControllerStickOffsetEditor splineEditorGeneric = (ControllerStickOffsetEditor)CreateEditor((ControllerStickOffset)stickOffset, typeof(ControllerStickOffsetEditor));

            splineEditorGeneric.ConstructSticker(stickReference);
        }