Esempio n. 1
0
        /// <summary>
        /// Ons the DragHandle event.
        /// </summary>
        /// <param name="controlID">Control I.</param>
        /// <param name="e">E.</param>
        /// <param name="userData">User data.</param>
        private static void onDragHandleEvent(int controlID, Event e, long userData)
        {
            if (e.type == EventType.KeyDown && (e.keyCode == KeyCode.Delete || e.keyCode == KeyCode.Backspace))
            {
                int bindingInx  = (int)(userData >> 32);
                int keyframeInx = (int)(userData & 0x0000FFFF);


                EditorClipBinding[] clipBindings = (clipBindingsSerialized.value as EditorClipBinding[]);
                AnimationClip       clip         = clipBindings [bindingInx].clip;



                //AnimationUtilityEx.RemoveKeyframeFrom (clip, clipBindings [bindingInx], keyframeInx);

                __timeNormalized       = 0f;
                __timeNormalizedUpdate = true;

                __window.Repaint();

                //Debug.Log ("remove:" + bindingInx + " " + keyframeInx);


                SceneView.RepaintAll();
            }
            else if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 1)
            {
                int bindingInx  = (int)(userData >> 32);
                int keyframeInx = (int)(userData & 0x0000FFFF);
                EditorClipBinding[] clipBindings = (clipBindingsSerialized.value as EditorClipBinding[]);
                AnimationClip       clip         = clipBindings [bindingInx].clip;


                //Debug.Log ("bind:" + bindingInx + " " + keyframeInx);


                //make animation jump to selected keyframe represented by Handle
                float timeAtKeyframe = AnimationUtilityEx.GetTimeAt(clip, keyframeInx, AnimationUtilityEx.EditorCurveBinding_PosX);
                __timeNormalized       = timeAtKeyframe * 1f / __spaceGameObjectAnimationClip.length;
                __timeNormalizedUpdate = true;

                __window.Repaint();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the scene GUI event.
        /// </summary>
        /// <param name="sceneView">Scene view.</param>
        private static void OnSceneGUI(SceneView sceneView)
        {
            if (clipBindingsSerialized.value == null)
            {
                return;
            }

            EditorClipBinding[] clipBindings = clipBindingsSerialized.value as EditorClipBinding[];
            int   bindingsLength             = clipBindings.Length;
            Color clr = Color.red;

            Vector3[]     positionsInKeyframe = null;
            AnimationClip clip = null;

            EditorClipBinding clipBindingCurrent = null;

            long indexListAndindexFramePacked = 0;

            Transform transformRoot = null;


            Transform transformFirstChild = null;

            bool gameObjectCharacterSelected = false;

            if (Selection.activeGameObject != null)
            {
                if (Tools.current == Tool.Move)
                {
                    if (Selection.activeGameObject == __spaceGameObject)
                    {
                        gameObjectCharacterSelected = true;
                    }
                    else
                    {
                        clipBindingCurrent = clipBindings.FirstOrDefault((itm) => itm.gameObject == Selection.activeGameObject);
                        // && clipBindingCurrent.gameObject.transform.position!=Tools.handlePosition
                        if (clipBindingCurrent != null)
                        {
                            //clipBindingCurrent.gameObject.position has changed so recalcualte position offset
                            clipBindingCurrent.positionOffset = Quaternion.Inverse(__spaceGameObject.transform.rotation) * (clipBindingCurrent.gameObject.transform.position - __spaceGameObject.transform.position);
                        }
                    }
                }
                else if (Tools.current == Tool.Rotate)
                {
                    if (Selection.activeGameObject == __spaceGameObject)
                    {
                        gameObjectCharacterSelected = true;
                    }
                    else
                    {
                        clipBindingCurrent = clipBindings.FirstOrDefault((itm) => itm.gameObject == Selection.activeGameObject);
                        // && clipBindingCurrent.gameObject.transform.position!=Tools.handleRotation
                        if (clipBindingCurrent != null)
                        {
                            //clipBindingCurrent.gameObject.rotation has changed so recalcualte rotation offset
                            clipBindingCurrent.rotationOffset = Quaternion.Inverse(__spaceGameObject.transform.rotation) * clipBindingCurrent.gameObject.transform.rotation;
                        }
                    }
                }
            }


            for (int i = 0; i < bindingsLength; i++)
            {
                clipBindingCurrent = clipBindings [i];

                if (clipBindingCurrent.visible)
                {
                    clip = clipBindingCurrent.clip;

                    if (clip != null && clipBindingCurrent.gameObject != null && clipBindingCurrent.gameObject.transform.childCount > 0 && (transformFirstChild = clipBindingCurrent.gameObject.transform.GetChild(0)) != null)
                    {
                        if (gameObjectCharacterSelected)                                                                          //=> move and/or rotate clip binding's gameobjects
                        {
                            GameObject gameObjectBinded = clipBindingCurrent.gameObject;
                            gameObjectBinded.transform.rotation = __spaceGameObject.transform.rotation * clipBindingCurrent.rotationOffset;
                            gameObjectBinded.transform.position = __spaceGameObject.transform.position + __spaceGameObject.transform.rotation * clipBindingCurrent.positionOffset;
                        }



                        transformRoot = clipBindingCurrent.gameObject.transform;



                        positionsInKeyframe = AnimationUtilityEx.GetPositions(clip, AnimationUtility.CalculateTransformPath(transformFirstChild, transformRoot), transformRoot);



                        if (positionsInKeyframe != null)
                        {
                            for (int j = 0; j < positionsInKeyframe.Length; j++)
                            {
                                indexListAndindexFramePacked = i;                                                                                                //put index of clipBinding in list/array
                                indexListAndindexFramePacked = indexListAndindexFramePacked << 32 | (uint)j;                                                     //pack together with keyframe index

                                //actualy this is static handle
                                HandlesEx.DragHandle(positionsInKeyframe [j], 0.1f, Handles.SphereCap, Color.red, "(" + j + ")" + " " + Decimal.Round(Convert.ToDecimal(AnimationUtilityEx.GetTimeAt(clip, j, AnimationUtilityEx.EditorCurveBinding_PosX)), 2).ToString(), indexListAndindexFramePacked, onDragHandleEvent, new GUIContent[] { new GUIContent("Delete") }, new long[] { j }, null);
                            }
                            //save color
                            clr = Handles.color;


                            clipBindingCurrent.color.a = 1;
                            Handles.color = clipBindingCurrent.color;


                            Handles.DrawPolyLine(positionsInKeyframe);
                            //restore color
                            Handles.color = clr;
                        }
                    }
                }
            }


            //Debug.Log ("hot"+GUIUtility.hotControl);

            SceneView.RepaintAll();
        }