Ejemplo n.º 1
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());
    }
Ejemplo n.º 2
0
        private void DoCurveColorIndicator(Rect rect, AnimationWindowHierarchyNode node)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Color color = GUI.color;

            GUI.color = this.state.showCurveEditor ? (node.curves.Length != 1 || node.curves[0].isPPtrCurve ? AnimationWindowHierarchyGUI.k_KeyColorForNonCurves : CurveUtility.GetPropertyColor(node.curves[0].binding.propertyName)) : AnimationWindowHierarchyGUI.k_KeyColorInDopesheetMode;
            bool flag = false;

            if (AnimationMode.InAnimationMode())
            {
                foreach (AnimationWindowCurve curve in node.curves)
                {
                    if (curve.m_Keyframes.Any <AnimationWindowKeyframe>((Func <AnimationWindowKeyframe, bool>)(key => this.state.time.ContainsTime(key.time))))
                    {
                        flag = true;
                    }
                }
            }
            Texture image = !flag ? (Texture)CurveUtility.GetIconCurve() : (Texture)CurveUtility.GetIconKey();

            rect = new Rect((float)((double)rect.xMax - 10.0 - (double)(image.width / 2) - 5.0), rect.yMin + 3f, (float)image.width, (float)image.height);
            GUI.DrawTexture(rect, image, ScaleMode.ScaleToFit, true, 1f);
            GUI.color = color;
        }
        private UndoPropertyModification[] PostprocessAnimationRecordingModifications(UndoPropertyModification[] modifications)
        {
            //Fix for case 751009: The animationMode can be changed outside the AnimationWindow, and callbacks needs to be unregistered.
            if (!AnimationMode.InAnimationMode(GetAnimationModeDriver()))
            {
                OnExitingAnimationMode();
                return(modifications);
            }

            if (recording)
            {
                modifications = ProcessAutoKey(modifications);
            }
            else if (previewing)
            {
                modifications = RegisterCandidates(modifications);
            }

            RefreshDisplayNamesOnArrayTopologicalChange(modifications);

            // Only resample when playable graph has been customized with post process nodes.
            if (m_UsesPostProcessComponents)
            {
                ResampleAnimation(ResampleFlags.None);
            }

            foreach (var mod in modifications)
            {
                m_ObjectsModifiedDuringAnimationMode.Add(mod.currentValue.target);
            }

            return(modifications);
        }
Ejemplo n.º 4
0
    public void StopAnimation()
    {
        if (anim != null && anim.isPlaying)
        {
            anim.Stop();
        }

#if UNITY_EDITOR
        if (IsInEditorMode() && IsEditorPlayingAnimation)
        {
            if (AnimationMode.InAnimationMode())
            {
                AnimationMode.StopAnimationMode();
            }

            EditorApplication.update -= EditorUpdate;
            editorClipTime            = 0;
            editorClip = null;

            RevertTextAlpha();
            IsEditorPlayingAnimation = false;
            GameObject.DestroyImmediate(slicedParent);
        }
#endif
    }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 6
0
        void AddSerializedPlayableModifications(IPlayableAsset asset, AnimationClip clip)
        {
            var obj = asset as Object;

            if (obj == null)
            {
                return;
            }

            var driver = WindowState.previewDriver;

            if (driver == null || !AnimationMode.InAnimationMode(driver))
            {
                return;
            }

            var serializedObj = new SerializedObject(obj);
            var bindings      = AnimationClipCurveCache.Instance.GetCurveInfo(clip).bindings;
            var fields        = AnimatedParameterUtility.GetScriptPlayableFields(asset);

            // go through each binding and offset using the field name
            //  so the modification system can find the particle object using the asset as a root
            foreach (var b in bindings)
            {
                foreach (var f in fields)
                {
                    var propertyPath = f.Name + "." + b.propertyName;
                    if (serializedObj.FindProperty(propertyPath) != null)
                    {
                        DrivenPropertyManager.RegisterProperty(driver, obj, propertyPath);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private void StartAnimationMode()
 {
     if (!AnimationMode.InAnimationMode())
     {
         AnimationMode.StartAnimationMode();
     }
 }
Ejemplo n.º 8
0
 public static void stopAnimationMode()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
 }
Ejemplo n.º 9
0
        private UndoPropertyModification[] PostprocessAnimationRecordingModifications(UndoPropertyModification[] modifications)
        {
            //Fix for case 751009: The animationMode can be changed outside the AnimationWindow, and this callback needs to be unregistered.
            if (!AnimationMode.InAnimationMode(GetAnimationModeDriver()))
            {
                Undo.postprocessModifications -= PostprocessAnimationRecordingModifications;
                return(modifications);
            }

            if (recording)
            {
                modifications = ProcessAutoKey(modifications);
            }
            else if (previewing)
            {
                modifications = RegisterCandidates(modifications);
            }

            // Only resample when playable graph has been customized with post process nodes.
            if (m_UsesPostProcessComponents)
            {
                ResampleAnimation(ResampleFlags.None);
            }

            return(modifications);
        }
Ejemplo n.º 10
0
 void ShowHandles(SceneView sceneview)
 {
     if (muscleHandle != null && AnimationMode.InAnimationMode())
     {
         muscleHandle.ShowHandles();
     }
 }
Ejemplo n.º 11
0
 public static void startAnimationMode()
 {
     if (!AnimationMode.InAnimationMode())
     {
         AnimationMode.StartAnimationMode();
     }
 }
Ejemplo n.º 12
0
 private static void CheckInAnimationRecordMode()
 {
     AnimationIsRecording = AnimationMode.InAnimationMode();
     //if (_field_s_InAnimationRecordMode == null)
     //_field_s_InAnimationRecordMode = (typeof(AnimationMode)).GetField("s_InAnimationRecordMode", BindingFlags.NonPublic | BindingFlags.Static);
     //AnimationIsRecording = (bool)_field_s_InAnimationRecordMode.GetValue(null);
 }
Ejemplo n.º 13
0
        public static void PreviewFromCurves(GameObject animatorRoot, IEnumerable <EditorCurveBinding> keys)
        {
            if (!AnimationMode.InAnimationMode())
            {
                return;
            }

            var avatarRoot = GetAvatarRoot(animatorRoot);

            foreach (var binding in keys)
            {
                if (IsAvatarBinding(binding) || IsEuler(binding))
                {
                    continue;
                }

                bool isTransform = typeof(Transform).IsAssignableFrom(binding.type);
                if (isTransform && binding.propertyName.Equals(AnimatorBindingCache.TRPlaceHolder))
                {
                    AddTRBinding(animatorRoot, binding);
                }
                else if (isTransform && binding.propertyName.Equals(AnimatorBindingCache.ScalePlaceholder))
                {
                    AddScaleBinding(animatorRoot, binding);
                }
                else
                {
                    AnimationMode.AddEditorCurveBinding(avatarRoot, binding);
                }
            }
        }
Ejemplo n.º 14
0
        public virtual void UpdateTrack(GameObject obj, float time, float deltaTime)
        {
            _time += deltaTime;
#if UNITY_EDITOR
            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
            Animation animation = go.GetComponent <Animation>();
            if (animation == null)
            {
                return;
            }
            if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode())
            {
                AnimationMode.BeginSampling();
                animationClip.SampleAnimation(go, _time);
                AnimationMode.EndSampling();

                SceneView.RepaintAll();
            }
#endif
        }
        private void DoCurveColorIndicator(Rect rect, AnimationWindowHierarchyNode node)
        {
            if (Event.current.type == EventType.Repaint)
            {
                Color color = GUI.color;
                if (!this.state.showCurveEditor)
                {
                    GUI.color = k_KeyColorInDopesheetMode;
                }
                else if ((node.curves.Length == 1) && !node.curves[0].isPPtrCurve)
                {
                    GUI.color = CurveUtility.GetPropertyColor(node.curves[0].binding.propertyName);
                }
                else
                {
                    GUI.color = k_KeyColorForNonCurves;
                }
                bool flag = false;
                if (AnimationMode.InAnimationMode())
                {
                    foreach (AnimationWindowCurve curve in node.curves)
                    {
                        if (curve.m_Keyframes.Any <AnimationWindowKeyframe>(key => this.state.time.ContainsTime(key.time)))
                        {
                            flag = true;
                        }
                    }
                }
                Texture image = !flag?CurveUtility.GetIconCurve() : CurveUtility.GetIconKey();

                rect = new Rect(((rect.xMax - 10f) - (image.width / 2)) - 5f, rect.yMin + 3f, (float)image.width, (float)image.height);
                GUI.DrawTexture(rect, image, ScaleMode.ScaleToFit, true, 1f);
                GUI.color = color;
            }
        }
Ejemplo n.º 16
0
 private void OnDisable()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
 }
Ejemplo n.º 17
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.º 18
0
//				void copyBoneWeights ()
//				{
//
//						IKSolver.Bone[] bones = ikAnimatedValues.ik.solver.bones;
//						if (bones != null) {
//								if (ikAnimatedValues.boneWeights == null || bones.Length != ikAnimatedValues.boneWeights.Length) {
//										ikAnimatedValues.boneWeights = new float[bones.Length];
//
//										int bonesNumber = bones.Length;
//
//
//
//										for (int i=0; i<bonesNumber; i++)
//
//												ikAnimatedValues.boneWeights [i] = bones [i].weight;
//
//								}
//						}
//
//				}

        public override void OnInspectorGUI()
        {
            //copyBoneWeights ();


            EditorGUI.BeginChangeCheck();
            base.OnInspectorGUI();

            if (EditorGUI.EndChangeCheck())
            {
                //Debug.Log ("inspector");


                if (!EditorApplication.isPlaying && !AnimationMode.InAnimationMode() && ikAnimatedValues.ik != null)
                {
                    //Reset
//						Vector3 position = ikAnimatedValues.ik.gameObject.transform.position;
//						Quaternion rotation = ikAnimatedValues.ik.gameObject.transform.rotation;
//						ikAnimatedValues.ik.gameObject.ResetPropertyModification<Transform> ();
//						ikAnimatedValues.ik.gameObject.transform.position = position;
//						ikAnimatedValues.ik.gameObject.transform.rotation = rotation;
                    //ikAnimatedValues.ik.solver.FixTransforms ();

                    ikAnimatedValues.UpdateValues();
                }
            }
        }
Ejemplo n.º 19
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.º 20
0
 private void OnDestroy()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
 }
Ejemplo n.º 21
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);
    }
Ejemplo n.º 22
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 DoIconAndName(Rect rect, AnimationWindowHierarchyNode node, bool selected, bool focused, float indent)
 {
     EditorGUIUtility.SetIconSize(new Vector2(13f, 13f));
     if (Event.current.type == EventType.Repaint)
     {
         if (selected)
         {
             TreeViewGUI.s_Styles.selectionStyle.Draw(rect, false, false, true, focused);
         }
         if (AnimationMode.InAnimationMode())
         {
             rect.width -= 77f;
         }
         bool   flag    = AnimationWindowUtility.IsNodeLeftOverCurve(node, this.state.activeRootGameObject);
         bool   flag2   = AnimationWindowUtility.IsNodeAmbiguous(node, this.state.activeRootGameObject);
         string str     = string.Empty;
         string tooltip = string.Empty;
         if (flag)
         {
             str     = " (Missing!)";
             tooltip = "The GameObject or Component is missing (" + node.path + ")";
         }
         if (flag2)
         {
             str     = " (Duplicate GameObject name!)";
             tooltip = "Target for curve is ambiguous since there are multiple GameObjects with same name (" + node.path + ")";
         }
         if (node.depth == 0)
         {
             if ((this.state.activeRootGameObject != null) && (this.state.activeRootGameObject.transform.Find(node.path) == null))
             {
                 flag = true;
             }
             TreeViewGUI.s_Styles.content = new GUIContent(this.GetGameObjectName(node.path) + " : " + node.displayName + str, this.GetIconForNode(node), tooltip);
             Color textColor = this.m_AnimationLineStyle.normal.textColor;
             Color color     = !EditorGUIUtility.isProSkin ? Color.black : ((Color)(Color.gray * 1.35f));
             color = (!flag && !flag2) ? color : k_LeftoverCurveColor;
             this.SetStyleTextColor(this.m_AnimationLineStyle, color);
             rect.xMin += (int)(indent + base.k_FoldoutWidth);
             GUI.Label(rect, TreeViewGUI.s_Styles.content, this.m_AnimationLineStyle);
             this.SetStyleTextColor(this.m_AnimationLineStyle, textColor);
         }
         else
         {
             TreeViewGUI.s_Styles.content = new GUIContent(node.displayName + str, this.GetIconForNode(node), tooltip);
             Color color3 = this.m_AnimationLineStyle.normal.textColor;
             Color color4 = !EditorGUIUtility.isProSkin ? this.m_LightSkinPropertyTextColor : Color.gray;
             color4 = (!flag && !flag2) ? color4 : k_LeftoverCurveColor;
             this.SetStyleTextColor(this.m_AnimationLineStyle, color4);
             rect.xMin += (int)((indent + base.k_IndentWidth) + base.k_FoldoutWidth);
             GUI.Label(rect, TreeViewGUI.s_Styles.content, this.m_AnimationLineStyle);
             this.SetStyleTextColor(this.m_AnimationLineStyle, color3);
         }
     }
     if (this.IsRenaming(node.id) && (Event.current.type != EventType.Layout))
     {
         base.GetRenameOverlay().editFieldRect = new Rect(rect.x + base.k_IndentWidth, rect.y, (rect.width - base.k_IndentWidth) - 1f, rect.height);
     }
 }
Ejemplo n.º 24
0
 private void StopAnimationMode()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
         InitializeCurrentAnimationData();
     }
 }
Ejemplo n.º 25
0
 public void OnDisable()
 {
     if (AnimationMode.InAnimationMode())
     {
         AnimationMode.StopAnimationMode();
     }
     EditorMouseInput.onStatusChanged -= OnEditorMouseInputStatusChanged;
 }
Ejemplo n.º 26
0
 public void Toggle()
 {
     expanded = !expanded;
     if (!AnimationMode.InAnimationMode())
     {
         property.floatValue = expanded ? 1 : 0;
     }
 }
Ejemplo n.º 27
0
 public static bool InAnimationMode()
 {
             #if AFTER_UNITY_4_3
     return(AnimationMode.InAnimationMode());
             #else
     return(AnimationUtility.InAnimationMode());
             #endif
 }
Ejemplo n.º 28
0
 static void AnimationModeCheck()
 {
     if (s_InAnimationMode != AnimationMode.InAnimationMode())
     {
         SetDirty();
         s_InAnimationMode = AnimationMode.InAnimationMode();
     }
 }
Ejemplo n.º 29
0
    private bool CanUpdate()
    {
#if UNITY_EDITOR
        return((AnimationMode.InAnimationMode() && IsSelected()) || Application.isPlaying);
#else
        return(true);
#endif
    }
        static bool ProcessPlayableAssetRecording(UndoPropertyModification mod, WindowState state, ICurvesOwner curvesOwner)
        {
            if (mod.currentValue == null)
            {
                return(false);
            }

            if (!curvesOwner.IsParameterAnimatable(mod.currentValue.propertyPath))
            {
                return(false);
            }

            var localTime    = state.editSequence.time;
            var timelineClip = curvesOwner as TimelineClip;

            if (timelineClip != null)
            {
                // don't use time global to local since it will possibly loop.
                localTime = timelineClip.ToLocalTimeUnbound(state.editSequence.time);
            }

            if (localTime < 0)
            {
                return(false);
            }

            // grab the value from the current modification
            float fValue;

            if (!ExpressionEvaluator.Evaluate(mod.currentValue.value, out fValue))
            {
                // case 916913 -- 'Add Key' menu item will passes 'True' or 'False' (instead of 1, 0)
                // so we need a special case to parse the boolean string
                bool bValue;
                if (!bool.TryParse(mod.currentValue.value, out bValue))
                {
                    Debug.Assert(false, "Invalid type in PlayableAsset recording");
                    return(false);
                }

                fValue = bValue ? 1 : 0;
            }

            var added = curvesOwner.AddAnimatedParameterValueAt(mod.currentValue.propertyPath, fValue, (float)localTime);

            if (added && AnimationMode.InAnimationMode())
            {
                EditorCurveBinding binding = curvesOwner.GetCurveBinding(mod.previousValue.propertyPath);
                AnimationMode.AddPropertyModification(binding, mod.previousValue, true);
                curvesOwner.targetTrack.SetShowInlineCurves(true);
                if (state.GetWindow() != null && state.GetWindow().treeView != null)
                {
                    state.GetWindow().treeView.CalculateRowRects();
                }
            }

            return(added);
        }