Beispiel #1
0
        public bool StartPreview()
        {
            if (previewing)
            {
                return(true);
            }

            if (!canPreview)
            {
                return(false);
            }

            AnimationMode.StartAnimationMode(GetAnimationModeDriver());
            AnimationPropertyContextualMenu.Instance.SetResponder(this);
            Undo.postprocessModifications += PostprocessAnimationRecordingModifications;
            DestroyGraph();
            CreateCandidateClip();

            IAnimationWindowPreview[] previewComponents = FetchPostProcessComponents();
            m_UsesPostProcessComponents = previewComponents != null;
            if (previewComponents != null)
            {
                foreach (var component in previewComponents)
                {
                    component.StartPreview();
                }
            }

            return(true);
        }
Beispiel #2
0
    public GameObject Unreveal()
    {
        CancelInvokes();
        OnUnrevealStarted.Invoke();
        TurnOffTextAlpha();
        GameObject slicedGameObject = PrepareForAnimation();

        if (!IsInEditorMode())
        {
            PlayUnrevealAnimation();
        }

#if UNITY_EDITOR
        if (IsInEditorMode())
        {
            if (!IsEditorPlayingAnimation)
            {
                IsEditorPlayingAnimation = true;
                editorClipTime           = 0;
                editorClip = unrevealClip;

                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }

                EditorApplication.update += EditorUpdate;
            }
        }
#endif

        return(this.slicedParent = slicedGameObject);
    }
Beispiel #3
0
    private void BakeAnimationFrameMeshes()
    {
        GameObject animatedObject = Instantiate(referenceAnimatedObject);

        //animator = animatedObject.AddComponent<Animator>();
        //animator.runtimeAnimatorController = animatorController;
        frameMeshes = new List <Mesh>();
        AnimationMode.StartAnimationMode();
        AnimationMode.BeginSampling();
        var skinnedRenderer = animatedObject.GetComponentInChildren <SkinnedMeshRenderer>();

        AnimationMode.SampleAnimationClip(animatedObject, referenceAnimationClip, 0);
        var bakedMesh = new Mesh();

        skinnedRenderer.BakeMesh(bakedMesh);
        AssetDatabase.CreateAsset(bakedMesh, "Assets/BackedMesh.mesh");
        for (float t = 0.0f; t <= referenceAnimationClip.length; t += 1f / frameRate)
        {
            AnimationMode.SampleAnimationClip(animatedObject, referenceAnimationClip, t);
            bakedMesh = new Mesh();
            skinnedRenderer.BakeMesh(bakedMesh);
            frameMeshes.Add(bakedMesh);
        }
        AssetDatabase.SaveAssets();
        AnimationMode.EndSampling();
        AnimationMode.StopAnimationMode();
        GameObject.DestroyImmediate(animatedObject);
        //SceneView.RepaintAll();
    }
Beispiel #4
0
 private void StartAnimationMode()
 {
     if (!AnimationMode.InAnimationMode())
     {
         AnimationMode.StartAnimationMode();
     }
 }
Beispiel #5
0
        private void AnimationUpdate()
        {
            switch (mode)
            {
            case Mode.AnimationClips:

                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(gameObject, animationClips[currentClipIndex], currentClipTime);
                AnimationMode.EndSampling();
                currentClipTime += clipFrameInterval;
                break;

            case Mode.AnimationStates:
                animator.Update(clipFrameInterval);
                break;

            case Mode.PlayableDirector:
                director.time = currentClipTime;
                director.Evaluate();
                currentClipTime += clipFrameInterval;
                break;
            }
        }
Beispiel #6
0
        public void GatherProperties(PlayableDirector director)
        {
            if (director == null || Application.isPlaying)
            {
                return;
            }

            var asset = director.playableAsset as TimelineAsset;

            if (!previewMode)
            {
                AnimationMode.StartAnimationMode(previewDriver);

                OnStartPreview(director);

                AnimationPropertyContextualMenu.Instance.SetResponder(new TimelineRecordingContextualResponder(this));
                if (!previewMode)
                {
                    return;
                }
                EnsureWindowTimeConsistency();
            }

            if (asset != null)
            {
                m_PropertyCollector.Reset();
                m_PropertyCollector.PushActiveGameObject(null); // avoid overflow on unbound tracks
                asset.GatherProperties(director, m_PropertyCollector);
            }
        }
Beispiel #7
0
        private void StartAnimationUpdate()
        {
            switch (mode)
            {
            case Mode.AnimationClips:
                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(gameObject, animationClips[currentClipIndex], 0f);
                AnimationMode.EndSampling();
                break;

            case Mode.AnimationStates:
                animator.enabled = false;
                animator.Play(animationStates[currentClipIndex], 0, 0f);
                break;

            case Mode.PlayableDirector:
                director.enabled = false;
                director.time    = 0f;
                director.Evaluate();
                break;
            }
        }
 private void Maintain(EePreviewAvatar dummy)
 {
     dummy.Dummy.gameObject.SetActive(true);
     AnimationMode.StartAnimationMode();
     AnimationMode.BeginSampling();
     AnimationMode.SampleAnimationClip(dummy.Dummy.gameObject, _state.CurrentClip, 1 / 60f);
     AnimationMode.EndSampling();
 }
Beispiel #9
0
        public void DrawLeftTop()
        {
            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
            {
                using (var check1 = new EditorGUIBeginChangeCheckScope())
                {
                    GUILayout.Toggle(_isPlaying, EditorIconGUIContent.GetSystem(EditorIconGUIContentType.PlayButton),
                                     EditorStyles.toolbarButton);            //Play
                    if (check1.IsChanged)
                    {
                        SwitchPlay();
                    }
                }


                using (var check3 = new EditorGUIBeginChangeCheckScope())
                {
                    GUILayout.Toggle(AnimationMode.InAnimationMode(),
                                     EditorIconGUIContent.GetSystem(EditorIconGUIContentType.Animation_Record),
                                     EditorStyles.toolbarButton);            //Animate
                    if (check3.IsChanged)
                    {
                        if (AnimationMode.InAnimationMode())
                        {
                            AnimationMode.StopAnimationMode();
                        }
                        else
                        {
                            AnimationMode.StartAnimationMode();
                        }
                    }
                }

                using (new EditorGUIUtilityLabelWidthScope(30))
                {
                    _frameCountPerSecond =
                        EditorGUILayout.IntField("FPS", _frameCountPerSecond, GUILayout.Width(30 + 25));
                    if (_frameCountPerSecond <= 1)
                    {
                        _frameCountPerSecond = 1;
                    }
                }

                using (new EditorGUIUtilityLabelWidthScope(70))
                {
                    _playSpeed = EditorGUILayout.FloatField("play_speed", _playSpeed, GUILayout.Width(70 + 25));
                    if (_playSpeed <= 0)
                    {
                        _playSpeed = 1;
                    }
                }

                GUILayout.FlexibleSpace();
            }
        }
Beispiel #10
0
 protected virtual void StartRecd()
 {
     if (target)
     {
         EventMgr.Emit(new EventRecordData());
         track.SetFlag(TrackMode.Record, true);
         AnimationMode.StartAnimationMode();
         AnimationMode.BeginSampling();
         AnimationMode.SampleAnimationClip(target, animationClip, 0);
     }
 }
Beispiel #11
0
 void ToggleAnimationMode()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
     else
     {
         AnimationMode.StartAnimationMode();
     }
 }
Beispiel #12
0
 private void PlayAnim()
 {
     if (_isPlaying)
     {
         return;
     }
     _editorLastTime           = Time.realtimeSinceStartup;
     EditorApplication.update += _OnEditorUpdate;
     AnimationMode.StartAnimationMode();
     _isPlaying = true;
 }
Beispiel #13
0
        /// <summary>
        /// Draw a timeline that can be scrubbed to allow picking a specific normalized time of an animation
        /// </summary>
        public static void DrawScrub(Rect rect, StateMachineBehaviour target, SerializedProperty normalizedTime, SerializedProperty repeat, SerializedProperty atLeastOnce, SerializedProperty neverWhileExit)
        {
            bool  updatePreview = false;
            float timeBefore    = normalizedTime.floatValue;

            GUI.Label(new Rect(rect.x, rect.y, 50, 20), "Time");
            EditorGUI.PropertyField(new Rect(rect.x + 50, rect.y, rect.width - 50 - 42, 20), normalizedTime, GUIContent.none);
            if (GUI.Button(new Rect(rect.x + rect.width - 40, rect.y, 40, 20), "View"))
            {
                updatePreview = true;
            }

            DrawSmallProperty(new Rect(rect.x, rect.y + 20, rect.width / 3f, 20), new GUIContent("Loop", "Enable this to allow execution every time the state loops. Otherwise it will only happen once."), repeat);
            DrawSmallProperty(new Rect(rect.x + rect.width / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("At Least Once", "Execute when the exit transition ends if this hasn't been executed yet."), atLeastOnce);
            DrawSmallProperty(new Rect(rect.x + rect.width * 2f / 3f, rect.y + 20, rect.width / 3f, 20), new GUIContent("Never While Exit", "Prevent executing during the exit transition."), neverWhileExit);

            if (timeBefore != normalizedTime.floatValue)
            {
                updatePreview = true;
            }

            if (updatePreview)
            {
                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }

                AnimatorController ignore;
                Animator           animator;
                GetCurrentAnimatorAndController(out ignore, out animator);

                var contexts = AnimatorController.FindStateMachineBehaviourContext(target);

                foreach (var context in contexts)
                {
                    AnimatorState state = context.animatorObject as AnimatorState;
                    if (null == state)
                    {
                        continue;
                    }

                    AnimationClip previewClip = GetFirstAvailableClip(state.motion);
                    if (null == previewClip)
                    {
                        continue;
                    }

                    AnimationMode.BeginSampling();
                    AnimationMode.SampleAnimationClip(animator.gameObject, previewClip, normalizedTime.floatValue * previewClip.length);
                    AnimationMode.EndSampling();
                }
            }
        }
Beispiel #14
0
 private void ToggleAnimationMode()
 {
     if (editAnimators && !AnimationMode.InAnimationMode())
     {
         AnimationMode.StartAnimationMode();
     }
     if (!editAnimators && AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
 }
 private void RenderPreview(int frame)
 {
     if (_modelGameObject != null)
     {
         _modelGameObject.SetActive(true);
         AnimationMode.StartAnimationMode();
         SetupFrame(frame);
         _previewCamera.Render();
         AnimationMode.StopAnimationMode();
         _modelGameObject.SetActive(false);
     }
 }
Beispiel #16
0
        private void PreviewAnimationEvent(FAnimationEventEditor animEvtEditor, int frame)
        {
            FPlayAnimationEvent animEvt = (FPlayAnimationEvent)animEvtEditor._evt;

            if (animEvt._animationClip == null)
            {
                return;
            }

            bool isEditable = animEvt.IsAnimationEditable();

            // render path
            if (isEditable)
            {
                TransformCurves transformCurves = new TransformCurves(animEvt.Owner, animEvt._animationClip);

                RenderTransformPath(transformCurves, animEvt.LengthTime, 1f / animEvt.Sequence.FrameRate);

                float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;

                if (animEvt.FrameRange.Contains(frame))
                {
//					float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;
                    RenderTransformAnimation(transformCurves, t);
                }

//				AnimationClipCurveData[] allCurves = AnimationUtility.GetAllCurves( animEvt._animationClip, true );
//				foreach( AnimationClipCurveData curve in allCurves )
//				{
//
//				}
            }
            else if (animEvt.FrameRange.Contains(frame))
            {
                float t = (float)(frame + animEvt._startOffset - animEvt.Start) / animEvt.Sequence.FrameRate;

                bool wasInAnimationMode = AnimationMode.InAnimationMode();

                if (!AnimationMode.InAnimationMode())
                {
                    AnimationMode.StartAnimationMode();
                }
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(animEvt.Owner.gameObject, animEvt._animationClip, t);
                AnimationMode.EndSampling();

                if (!wasInAnimationMode)
                {
                    AnimationMode.StopAnimationMode();
                }
            }
        }
Beispiel #17
0
    private void SetAnimationMode(bool enabled)
    {
#if UNITY_EDITOR
        if (AnimationMode.InAnimationMode() && !enabled)
        {
            AnimationMode.StopAnimationMode();
        }
        else if (!AnimationMode.InAnimationMode() && enabled)
        {
            AnimationMode.StartAnimationMode();
        }
#endif
    }
        public void Capture()
        {
            if (!AnimationMode.InAnimationMode())
            {
                AnimationMode.StartAnimationMode();
            }

            var generatedCamera = GenerateCamera();

            _previewSetup.Dummy.gameObject.SetActive(true);

            DoGenerationProcess(generatedCamera);
        }
Beispiel #19
0
        public override void OnInspectorGUI()
        {
            if (target == null)
            {
                return;
            }
            var _target = target as Element;

            ////////////////////////////
            base.OnInspectorGUI();

            //EditorGUILayout.BeginVertical();
            fbx           = _target.meshAsset;
            animationClip = _target.asset;
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("播放"))
            {
                m_Playing = true;
                time      = 0;
            }
            if (GUILayout.Button("暂停"))
            {
                m_Playing = false;
                time      = 0;
                AnimationMode.StartAnimationMode();
                AnimationMode.SampleAnimationClip(m_PreviewInstance, animationClip, time);
                Repaint();
            }
            EditorGUILayout.EndHorizontal();
            var lastRect = GUILayoutUtility.GetLastRect();
            var pos      = GUIHelper.CurrentWindow.position;
            // Debug.Log(GUIHelper.CurrentWindow.position);
            var rect = new Rect(lastRect.xMin + 50, lastRect.yMax + 50, pos.width * 0.9f, pos.height * 0.9f);

            Handles.DrawCamera(rect, camera);
            GetPreviewObject();
            var m_PreviewHint      = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().GetHashCode();
            var m_PreviewSceneHint = m_PreviewHint;
            var controlID          = GUIUtility.GetControlID(m_PreviewHint, FocusType.Passive, rect);
            var typeForControl     = Event.current.GetTypeForControl(controlID);

            DoRenderPreview();
            int controlID2 = GUIUtility.GetControlID(m_PreviewSceneHint, FocusType.Passive);

            typeForControl = Event.current.GetTypeForControl(controlID2);
            HandleViewTool(Event.current, typeForControl, controlID2, rect);
            DoAvatarPreviewFrame(Event.current, typeForControl, rect);
        }
 private void EditorToolsOnActiveToolChanged()
 {
     if (EditorTools.IsActiveTool(this))
     {
         AnimationMode.StartAnimationMode();
         _animationTimer = Time.realtimeSinceStartup;
         InitializeEditorTool(piskelTarget.clip);
     }
     else
     {
         AnimationMode.SampleAnimationClip(piskelTarget.gameObject, piskelTarget.clip, 0);
         AnimationMode.StopAnimationMode();
     }
 }
    private void PlayAnim()
    {
        if (isPlaying)
        {
            return;
        }

        animationStartTime    = Time.realtimeSinceStartup;
        animationLastTickTime = animationStartTime;

        EditorApplication.update += EditorApplication_update;
        AnimationMode.StartAnimationMode();

        isPlaying = true;
    }
        public override bool StartPreview()
        {
            if (previewing)
            {
                return(true);
            }

            if (!canPreview)
            {
                return(false);
            }

            AnimationMode.StartAnimationMode(GetAnimationModeDriver());
            AnimationPropertyContextualMenu.Instance.SetResponder(this);
            Undo.postprocessModifications += PostprocessAnimationRecordingModifications;
            return(true);
        }
    // Init the trajectories for each body joints for the current Animation Clip
    private void initTrajectories()
    {
        // TODO
        // Créer ou vider dictionnaire m_trajectories qui va contenir la list des points de la trajectoire
        // Créer ou vider dictionnaire m_toggleTraj qui va contenir la list des bool indiquant si la trajectoire est visible ou non
        // Remplir le m_trajectories[m_BodyJoints[i].name] avec les positions des points
        // Voir AnimationMode.BeginSampling(); .... AnimationMode.EndSampling(); qui se trouve dans playAnimation
        if (m_trajectories == null)
        {
            m_trajectories = new Dictionary <string, List <Vector3> >();
        }

        if (m_toggleTraj == null)
        {
            m_toggleTraj = new Dictionary <string, bool> ();
        }

        m_trajectories.Clear();
        m_toggleTraj.Clear();

        m_f_endTime       = m_animationClip.length;
        m_f_frameDuration = 1.0f / m_animationClip.frameRate;

        if (!AnimationMode.InAnimationMode())
        {
            AnimationMode.StartAnimationMode();
        }

        for (int i = 0; i < m_BodyJoints.Count; ++i)
        {
            List <Vector3> tmp = new List <Vector3>();

            for (double j = m_f_startTime; j < m_f_endTime; j += m_f_frameDuration)
            {
                samplePosture((float)j);
                tmp.Add(m_BodyJoints[i].transform.position);
            }

            m_trajectories.Add(m_BodyJoints[i].name, tmp);
            m_toggleTraj.Add(m_BodyJoints[i].name, true);
        }
    }
    // Init the trajectories for each body joints for the current Animation Clip
    private void InitTrajectories()
    {
        // Enable the Animation Mode if disabled
        if (!AnimationMode.InAnimationMode())
        {
            AnimationMode.StartAnimationMode();
        }

        // Init Dictionnaries
        if (trajectories == null)
        {
            trajectories = new Dictionary <string, List <Vector3> >();
        }
        if (toogleTrajectories == null)
        {
            toogleTrajectories = new Dictionary <string, bool>();
        }
        trajectories.Clear();
        toogleTrajectories.Clear();
        for (int i = 0; i < bodyJoints.Count; i++)
        {
            trajectories.Add(bodyJoints[i].name, new List <Vector3>());
            toogleTrajectories.Add(bodyJoints[i].name, true);
        }

        // Sample Animation & Add new bones positions
        for (float sampleTime = firstFrameTime; sampleTime < clipLength; sampleTime += 0.01f)
        {
            AnimationMode.BeginSampling();
            AnimationMode.SampleAnimationClip(skeleton, clipToPlay, sampleTime);
            for (int i = 0; i < trajectories.Count; i++)
            {
                trajectories[bodyJoints[i].name].Add(bodyJoints[i].position);
            }
            AnimationMode.EndSampling();
        }

        // Reset gameobject to base position
        AnimationMode.BeginSampling();
        AnimationMode.SampleAnimationClip(skeleton, clipToPlay, 0.0f);
        AnimationMode.EndSampling();
    }
        public override bool StartPreview()
        {
            bool result;

            if (this.previewing)
            {
                result = true;
            }
            else if (!this.canPreview)
            {
                result = false;
            }
            else
            {
                AnimationMode.StartAnimationMode(this.GetAnimationModeDriver());
                AnimationPropertyContextualMenu.Instance.SetResponder(this);
                Undo.postprocessModifications = (Undo.PostprocessModifications)Delegate.Combine(Undo.postprocessModifications, new Undo.PostprocessModifications(this.PostprocessAnimationRecordingModifications));
                result = true;
            }
            return(result);
        }
        public override void OnPreviewSettings()
        {
            bool inAnimationModeOrigin = AnimationMode.InAnimationMode();

            EditorGUI.BeginDisabledGroup(REF_OBJECT == null);
            bool inAnimationModeChange = GUILayout.Toggle(
                inAnimationModeOrigin, "Preview",
                EditorStyles.toolbarButton
                );

            EditorGUI.EndDisabledGroup();

            if (inAnimationModeChange != inAnimationModeOrigin)
            {
                switch (inAnimationModeChange)
                {
                case true: AnimationMode.StartAnimationMode(); break;

                case false: AnimationMode.StopAnimationMode(); break;
                }
            }
        }
        public override bool StartPreview()
        {
            if (previewing)
            {
                return(true);
            }

            if (!canPreview)
            {
                return(false);
            }

            AnimationMode.StartAnimationMode(GetAnimationModeDriver());
            AnimationPropertyContextualMenu.Instance.SetResponder(this);
            Undo.postprocessModifications += PostprocessAnimationRecordingModifications;
            PrefabUtility.allowRecordingPrefabPropertyOverridesFor += AllowRecordingPrefabPropertyOverridesFor;
            DestroyGraph();
            CreateCandidateClip();

            //If a hierarchy was created and array reorder happen in the inspector prior
            //to the preview being started we will need to ensure that the display name
            //reflects the binding path on an array element.
            state.UpdateCurvesDisplayName();

            IAnimationWindowPreview[] previewComponents = FetchPostProcessComponents();
            m_UsesPostProcessComponents = previewComponents != null && previewComponents.Length > 0;
            if (previewComponents != null)
            {
                // Animation preview affects inspector values, so make sure we ignore constrain proportions
                ConstrainProportionsTransformScale.m_IsAnimationPreview = true;
                foreach (var component in previewComponents)
                {
                    component.StartPreview();
                }
            }

            return(true);
        }
Beispiel #28
0
        void UpdateAnimation(GameObject go)
        {
            animtionDeltaTime = (float)EditorApplication.timeSinceStartup - lastAnimationTime;
            animationTime    += animtionDeltaTime;
            lastAnimationTime = (float)EditorApplication.timeSinceStartup;

            if (go)
            {
                var anim = go.GetComponent <Animation>();
                if (anim)
                {
                    if (!anim.isPlaying)
                    {
                        anim.Play();
                    }
                    if (animationTime > anim.clip.length)
                    {
                        animationTime = 0;
                    }

                    if (!AnimationMode.InAnimationMode())
                    {
                        AnimationMode.StartAnimationMode();
                    }
                    AnimationMode.SampleAnimationClip(skeleton, anim.clip, animationTime);
                    //AnimationMode.StopAnimationMode();
                }
                else
                {
                    Animator animator = go.GetComponent <Animator>();
                    if (animator)
                    {
                        animator.Update(animtionDeltaTime);
                    }
                }
            }
        }
Beispiel #29
0
 void PlayAnima(float dt)
 {
     if (m_PreviewInstance == null || animationClip == null)
     {
         return;
     }
     if (m_Playing)
     {
         if (time <= 1)
         {
             time += dt;
             AnimationMode.StartAnimationMode();
             AnimationMode.SampleAnimationClip(m_PreviewInstance, animationClip, time);
             if (time >= 1)
             {
                 time = 0;
             }
         }
     }
     else
     {
         time = 0;
     }
 }
    // Use this for initialization
    public void Run()
    {
        Debug.Log("Baking the following animations....");
        List <AnimationClip> animClips = GetAnimationLengths();

        bones = GetListBones();

        for (int j = 0; j < animClips.Count; j++)
        {
            newClip = new AnimationClip();

            //AnimatorStateInfo state =  transform.GetComponent<Animator> ().GetCurrentAnimatorStateInfo(0);
            //float leng = state.length;

            clip = animClips[j];
            float leng = clip.length;
            //Debug.Log(leng);

            curvePosX.Clear(); curvePosY.Clear(); curvePosZ.Clear();
            curveRotX.Clear();      curveRotY.Clear(); curveRotZ.Clear(); curveRotW.Clear();
            curveScaleX.Clear(); curveScaleY.Clear(); curveScaleZ.Clear();

            for (int i = 0; i < bones.Count; i++)
            {
                curvePosX.Add(new AnimationCurve());
                curvePosY.Add(new AnimationCurve());
                curvePosZ.Add(new AnimationCurve());
                curveRotX.Add(new AnimationCurve());
                curveRotY.Add(new AnimationCurve());
                curveRotZ.Add(new AnimationCurve());
                curveRotW.Add(new AnimationCurve());
                curveScaleX.Add(new AnimationCurve());
                curveScaleY.Add(new AnimationCurve());
                curveScaleZ.Add(new AnimationCurve());
            }


            //Time.timeScale = 0.0f;
            //float _lastRealTime = 0.0f;
            frameTime = 1f / clip.frameRate;
            float numFramesInAnim = (leng * clip.frameRate);



            for (int i = 0; i < numFramesInAnim + 1; i++)
            {
                AnimationMode.StartAnimationMode();
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(transform.gameObject, clip, i * frameTime);
                transform.GetComponent <Puppet2D_GlobalControl>().Run();

                foreach (Transform bone in bones)
                {
                    bakeAnimation(bone, i * frameTime);
                }
            }
            AnimationMode.EndSampling();
            AnimationMode.StopAnimationMode();



            newClip.name     = clip.name + "_Baked";
            newClip.wrapMode = clip.wrapMode;
            AnimationClipSettings animClipSettings = new AnimationClipSettings();
            animClipSettings.stopTime = clip.length;


            AnimationUtility.SetAnimationType(newClip, ModelImporterAnimationType.Generic);
            SaveAnimationClip(newClip);

            AnimationEvent[] events = new AnimationEvent[1];
            events[0]      = new AnimationEvent();
            events[0].time = clip.length;
            AnimationUtility.SetAnimationEvents(newClip, events);
            AnimationEvent[] events2 = new AnimationEvent[0];
            AnimationUtility.SetAnimationEvents(newClip, events2);

            /*AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(newClip, true);
             * for (int i=0; i<curveDatas.Length; i++)
             * {
             *      AnimationUtility.SetEditorCurve(
             *              newClip,
             *              curveDatas[i].path,
             *              curveDatas[i].type,
             *              curveDatas[i].propertyName,
             *              curveDatas[i].curve
             *              );
             * }*/

            AssetDatabase.SaveAssets();

            UnityEngine.Object[] newSelection = new UnityEngine.Object[Selection.objects.Length + 1];
            for (int i = 0; i < Selection.objects.Length; i++)
            {
                newSelection [i] = Selection.objects [i];
            }
            newSelection [newSelection.Length - 1] = newClip;
            Selection.objects = newSelection;

            /*
             * transform.GetComponent<Animator> ().StartRecording (0);
             *
             *
             * Invoke ("stopRecording", leng);
             */
        }
        Debug.Log("Finished Baking.");
    }