Ejemplo n.º 1
0
    void Update()
    {
        if (go == null)
        {
            return;
        }

        if (animationClip == null)
        {
            return;
        }

        // There is a bug in AnimationMode.SampleAnimationClip which crashes
        // Unity if there is no valid controller attached
        Animator animator = go.GetComponent <Animator>();

        if (animator != null && animator.runtimeAnimatorController == null)
        {
            return;
        }

        // Animate the GameObject
        if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode())
        {
            AnimationMode.BeginSampling();
            AnimationMode.SampleAnimationClip(go, animationClip, time);
            AnimationMode.EndSampling();

            SceneView.RepaintAll();
        }
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
    private void _OnEditorUpdate()
    {
        if (_clipsOfCurrentAnimator != null)
        {
            if (!_useSlider)
            {
                DelayToPlay();
                if (!_stop)
                {
                    float animTime = Time.realtimeSinceStartup - _editorLastTime;
                    animTime *= _speed;
                    AnimationClip animClip = _clipsOfCurrentAnimator[_currentClipIndex];
                    if (animTime > animClip.length)
                    {
                        _editorLastTime = Time.realtimeSinceStartup;
                        _stop           = true;
                    }


                    animTime %= animClip.length;
                    AnimationMode.SampleAnimationClip(_currentAnimator.gameObject, animClip, animTime);
                }
            }
            else
            {
                AnimationClip animClip = _clipsOfCurrentAnimator[_currentClipIndex];
                AnimationMode.SampleAnimationClip(_currentAnimator.gameObject, animClip, _valueOfSlider);
            }
        }
    }
Ejemplo n.º 4
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;
            }
        }
 public static void SampleAnimationClip(GameObject rootGameObject, AnimationClip clip, float time)
 {
   if ((UnityEngine.Object) rootGameObject != (UnityEngine.Object) null)
     AnimationMode.SampleAnimationClip(rootGameObject, clip, time);
   else
     CurveBindingUtility.SampleAnimationClip(clip, time);
 }
 public override void ResampleAnimation()
 {
     if (!this.state.disabled)
     {
         if (this.previewing)
         {
             if (this.canPreview)
             {
                 if (this.state.activeAnimationClip != null)
                 {
                     AnimationMode.BeginSampling();
                     Undo.FlushUndoRecordObjects();
                     AnimationMode.SampleAnimationClip(this.state.activeRootGameObject, this.state.activeAnimationClip, this.time.time);
                     if (this.m_CandidateClip != null)
                     {
                         AnimationMode.SampleCandidateClip(this.state.activeRootGameObject, this.m_CandidateClip, 0f);
                     }
                     AnimationMode.EndSampling();
                     SceneView.RepaintAll();
                     InspectorWindow.RepaintAllInspectors();
                     ParticleSystemWindow instance = ParticleSystemWindow.GetInstance();
                     if (instance)
                     {
                         instance.Repaint();
                     }
                 }
             }
         }
     }
 }
        void OnAnimatingCallback(float play_time)
        {
            if (_sequence == null || _sequence.tracks.IsNullOrEmpty())
            {
                return;
            }
            foreach (AnimationTimelinableTrack track in _sequence.tracks)
            {
                foreach (AnimationTimelinableItemInfo itemInfo in track.itemInfoes)
                {
                    if (track.animator == null || track.runtimeAnimatorController == null)
                    {
                        continue;
                    }

                    if (itemInfo.IsTimeInside(play_time))
                    {
                        float elasped_duration = play_time - itemInfo.time;

                        AnimationMode.SampleAnimationClip(track.animator.gameObject, itemInfo.animationClip,
                                                          elasped_duration * itemInfo.speed);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void SetToWeather(int index)
        {
            animator = GetComponent <Animator>();
            if (animator != null)
            {
                animator.enabled = false;
            }
            else
            {
                return;
            }

            AnimationClip ac = GetFirstClip();

            if (ac == null)
            {
                return;
            }

            maxIndex = GetKeyFrameNum();
            index    = Mathf.Clamp(index, 0, maxIndex - 1);
            float ratio = (float)index / (maxIndex - 1);

//            animator.Play (stateName, 0, ratio);

            AnimationMode.BeginSampling();
            AnimationMode.SampleAnimationClip(this.gameObject, ac, ratio * ac.length);
            AnimationMode.EndSampling();

            SceneView.RepaintAll();
        }
    private void EditorApplication_update()
    {
        // Failsafe
        if (selectedAnimation == null || selectedAnimator == null)
        {
            StopAnim();

            return;
        }

        if (isPaused)
        {
            animationLastTickTime           = Time.realtimeSinceStartup;
            repetitionsDelayCurrentOverhead = 0f;

            return;
        }

        if (!isSamplingViaSlider)
        {
            float timeSinceLastTick = Time.realtimeSinceStartup - animationLastTickTime;

            animationTime = (animationTime + repetitionsDelayCurrentOverhead + (timeSinceLastTick * animationSpeed)) % (selectedAnimation.length + repetitionsDelay); // Looping the animation
            repetitionsDelayCurrentOverhead = Mathf.Max(0f, animationTime - selectedAnimation.length);
            animationTime -= repetitionsDelayCurrentOverhead;

            AnimationMode.SampleAnimationClip(selectedAnimator.gameObject, selectedAnimation, animationTime);
        }
        else
        {
            AnimationMode.SampleAnimationClip(selectedAnimator.gameObject, selectedAnimation, animationSamplingTime % selectedAnimation.length);
        }

        animationLastTickTime = Time.realtimeSinceStartup;
    }
Ejemplo n.º 10
0
    Pose GeneratePose(float sampleTime)
    {
        if (go == null)
        {
            return(null);
        }

        if (animationClip == null)
        {
            return(null);
        }

        Animator animator = go.GetComponent <Animator>();

        if (animator != null && animator.runtimeAnimatorController == null)
        {
            return(null);
        }

        if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode())
        {
            AnimationMode.BeginSampling();
            AnimationMode.SampleAnimationClip(go, animationClip, sampleTime);
            AnimationMode.EndSampling();

            SceneView.RepaintAll();
        }
        return(CreatePose());
    }
    private void GUITabsAnimation(Animator animator = null)
    {
        GUILayout.Space(10f);
        GUILayout.Label("Animations");
        if (animator == null)
        {
            return;
        }

        animClipsArr = FindAnimationClipInAnimator(animator);
        animNamesArr = FindAnimNames(animClipsArr);
        EditorSceneManager.sceneOpened += EditorSceneManager_sceneOpened;

        currentAnimIndex = EditorGUILayout.Popup("Current Anim", currentAnimIndex, animNamesArr);

        animationSpeed = EditorGUILayout.FloatField("Animation Speed", animationSpeed);

        delayBetweenAnimation = EditorGUILayout.FloatField("Delay Between Animation", delayBetweenAnimation);


        if (isPlaying)
        {
            if (GUILayout.Button("Stop") || PlayModeStateChanged.State == PlayModeStateChange.EnteredPlayMode)
            {
                StopAnim();
            }
        }
        else
        {
            if (GUILayout.Button("Play") && PlayModeStateChanged.State != PlayModeStateChange.EnteredPlayMode)
            {
                PlayAnim();
            }
        }

        GUILayout.Space(10f);

        GUILayout.Label("SamplerAnimation");
        samplerAnim = GUILayout.HorizontalSlider(samplerAnim, 0f, animClipsArr[currentAnimIndex].length);

        if (!isPlaying)
        {
            AnimationMode.StartAnimationMode();
            AnimationMode.SampleAnimationClip(currenAnimator.gameObject, animClipsArr[currentAnimIndex], samplerAnim);
        }

        GUILayout.Space(10f);
        GUILayout.Label("Info animation");
        if (isPlaying)
        {
            GUILayout.Label("Current duration : " + animTime.ToString());
        }
        else
        {
            GUILayout.Label("Current duration : " + samplerAnim.ToString());
        }

        GUILayout.Label("Total Duration : " + animClipsArr[currentAnimIndex].length.ToString());
        GUILayout.Label("Is looping : " + animClipsArr[currentAnimIndex].isLooping.ToString());
    }
Ejemplo n.º 12
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;
            }
        }
Ejemplo n.º 13
0
        public override void UpdateView(Rect editorRect, Rect percentageRect)
        {
            base.UpdateView(editorRect, percentageRect);

            if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode())
            {
                if (isAutoSampling)
                {
                    elapseSamplingTime = Time.realtimeSinceStartup;
                    if (elapseSamplingTime - startSamplingTime >= interval)
                    {
                        AutoSampling();
                    }
                }

                AnimationMode.BeginSampling();
                {
                    samplingTime = interval * AnimationEventControllerEditorWindow.Instance.current.timeline.frameIndex;

                    AnimationClip clip = AnimationEventControllerEditorWindow.Instance.GetCurrentClip();

                    AnimationMode.SampleAnimationClip(animationEventController.animator.gameObject, clip, samplingTime);
                }
                AnimationMode.EndSampling();

                SceneView.RepaintAll();
            }
        }
Ejemplo n.º 14
0
    private void IncreaseTimeForAnimation()
    {
        AnimationClip animclip = animationClips[currentAnimationClipIndex];

        previousAnimTime %= animclip.length;
        AnimationMode.SampleAnimationClip(currentAnimator.gameObject, animclip, previousAnimTime);
    }
Ejemplo n.º 15
0
    private void _OnEditorUpdate()
    {
        float         animTime      = Time.realtimeSinceStartup - _editorLastTime;
        AnimationClip animationClip = _animationClipsArr[_currentAnimIndex];

        animTime %= animationClip.length;
        AnimationMode.SampleAnimationClip(_animator.gameObject, animationClip, animTime);
    }
    private void OnEditorUpdate()
    {
        animTime = (Time.realtimeSinceStartup - editorLastTime) * animationSpeed;
        AnimationClip animClip = animClipsArr[currentAnimIndex];

        animTime %= animClip.length + delayBetweenAnimation;
        AnimationMode.SampleAnimationClip(currenAnimator.gameObject, animClip, animTime);
    }
 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();
 }
Ejemplo n.º 18
0
 void Update()
 {
     if (_isPreviewPlaying && AnimationMode.InAnimationMode())
     {
         if (_animTarget != null && _clip != null)
         {
             AnimationMode.SampleAnimationClip(_animTarget.gameObject, _clip, ParticleSystemEditorHelper.I.PlaybackTime);
         }
     }
 }
Ejemplo n.º 19
0
 public static void SampleAnimationClip(GameObject rootGameObject, AnimationClip clip, float time)
 {
     if (rootGameObject != null)
     {
         AnimationMode.SampleAnimationClip(rootGameObject, clip, time);
     }
     else
     {
         SampleAnimationClip(clip, time);
     }
 }
Ejemplo n.º 20
0
        private void OnEditorUpdate()
        {
            AnimationClip animClip = animClipsArr[currentAnimIndex];

            float animTime = Time.realtimeSinceStartup - editorLastTime;

            // Looping anim
            animTime %= animClip.length;

            AnimationMode.SampleAnimationClip(animator.gameObject, animClip, animTime);
        }
Ejemplo n.º 21
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();
                }
            }
        }
Ejemplo n.º 22
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);
     }
 }
Ejemplo n.º 23
0
        public void SetFrame(int frame, AnimationClip clip)
        {
            if (m_PreviewInstance && clip)
            {
                AnimationMode.BeginSampling();
                AnimationMode.SampleAnimationClip(m_PreviewInstance, clip, AnimationWindowExtra.FrameToTime(frame));
                AnimationMode.EndSampling();

                IkUtils.UpdateIK(m_PreviewInstance, "", false);
            }
        }
Ejemplo n.º 24
0
    /***********************************************
    *
    ***********************************************/


    public void ResampleAnimation()
    {
        if (AnimationMode.InAnimationMode())
        {
            AnimationMode.BeginSampling();
            AnimationMode.SampleAnimationClip(target, clip, time);
            AnimationMode.EndSampling();
        }

        UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
    }
Ejemplo n.º 25
0
        private void SamplePanelAnimator(WooPanel panel)
        {
            if (panel == null || panel.GetComponent <Animator>() == null)
            {
                return;
            }

            AnimationClip animation          = null;
            var           animatorController = panel.GetComponent <Animator>().runtimeAnimatorController;

            animation = panelNodes[panel].GetActiveAnimation();

            var time = panelNodes[panel].simulatedTime;

            time = Mathf.Clamp(time, 0.0f, 1.0f);

            if (panelNodes[panel].IsClosed || panelNodes[panel].IsClosing || panelNodes[panel].IsWaitingToClose)
            {
                if (panelNodes[panel].IsMirrored())
                {
                    time = 1.0f - time;
                }
            }

            if (animation != null)
            {
                                #if UNITY_EDITOR
                if (AnimationMode.InAnimationMode())
                {
                    if (!Application.isPlaying)
                    {
                        AnimationMode.SampleAnimationClip(panel.gameObject, animation, animation.length * time);
                    }
                }
                else
                {
                    if (!Application.isPlaying && panel.GetLayerIndex() != -1)
                    {
                        panel.GetAnimator().Play(animation.name, panel.GetLayerIndex(), time);
                        panel.GetAnimator().Update(Time.deltaTime);
                        panel.GetAnimator().StopPlayback();
                    }
                }
                                #endif

                if (Application.isPlaying && panel.GetLayerIndex() != -1)
                {
                    panel.GetAnimator().Play(animation.name, panel.GetLayerIndex(), time);
                    panel.GetAnimator().Update(Time.deltaTime);
                    panel.GetAnimator().StopPlayback();
                }
            }
        }
Ejemplo n.º 26
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();
                }
            }
        }
Ejemplo n.º 27
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();
     }
 }
Ejemplo n.º 29
0
 private void SampleAnimation(float t)
 {
     if (clip == null)
     {
         return;
     }
     if (clip.isHumanMotion)
     {
         SetAnimationMode(true);
         AnimationMode.SampleAnimationClip(target, clip, t);
     }
     else
     {
         clip.SampleAnimation(target, t);
     }
 }
    private void _OnEditorUpdate()
    {
        _animationTime = 0;

        if (!_isSampling)
        {
            _animationTime  = Time.realtimeSinceStartup - _editorLastTime;
            _animationTime *= _speedModifier;
            _animationTime %= _selectedAnimationClip.length + _delayBetweenLoop;
        }
        else
        {
            _animationTime = _sampleTime;
        }

        AnimationMode.SampleAnimationClip(_selectedAnimator.gameObject, _selectedAnimationClip, _animationTime);
        Repaint();
    }