Example #1
0
 public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
 {
     foreach (AnimationWindowCurve current in state.activeCurves)
     {
         AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
     }
 }
Example #2
0
        static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, Type type, object previousValue, object currentValue)
        {
            AnimationClip clip = state.activeAnimationClip;

            if ((clip.hideFlags & HideFlags.NotEditable) != 0)
            {
                return;
            }

            AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, type);

            // Add previous value at first frame on empty curves.
            if (state.addZeroFrame)
            {
                // Is it a new curve?
                if (curve.length == 0)
                {
                    if (state.currentFrame != 0)
                    {
                        // case 1373924
                        // In the case of a new curve, we also have to convert the previousValue to float for a discrete int
                        if (binding.isDiscreteCurve)
                        {
                            previousValue = UnityEngine.Animations.DiscreteEvaluationAttributeUtilities.ConvertDiscreteIntToFloat((int)previousValue);
                        }
                        AnimationWindowUtility.AddKeyframeToCurve(curve, previousValue, type, AnimationKeyTime.Frame(0, clip.frameRate));
                    }
                }
            }

            // Add key at current frame.
            AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, type, AnimationKeyTime.Frame(state.currentFrame, clip.frameRate));

            state.SaveCurve(curve);
        }
Example #3
0
        public override bool PlaybackUpdate()
        {
            if (!playing)
            {
                return(false);
            }

            float deltaTime = Time.realtimeSinceStartup - m_PreviousUpdateTime;

            m_PreviousUpdateTime = Time.realtimeSinceStartup;

            float newTime = time.time + deltaTime;

            // looping
            if (newTime > state.maxTime)
            {
                newTime = state.minTime;
            }

            m_Time = AnimationKeyTime.Time(Mathf.Clamp(newTime, state.minTime, state.maxTime), state.frameRate);

            ResampleAnimation();

            return(true);
        }
 public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
 {
     if (state.activeCurves.Count > 0)
     {
         using (List <AnimationWindowCurve> .Enumerator enumerator = state.activeCurves.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 AnimationWindowCurve current = enumerator.Current;
                 AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
             }
         }
     }
     else
     {
         using (List <AnimationWindowCurve> .Enumerator enumerator = state.allCurves.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 AnimationWindowCurve current = enumerator.Current;
                 AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
             }
         }
     }
 }
Example #5
0
        private static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, System.Type type, PropertyModification modification)
        {
            GameObject    activeRootGameObject = state.activeRootGameObject;
            AnimationClip activeAnimationClip  = state.activeAnimationClip;

            if ((activeAnimationClip.hideFlags & HideFlags.NotEditable) == HideFlags.None)
            {
                AnimationWindowCurve curve = new AnimationWindowCurve(activeAnimationClip, binding, type);
                object currentValue        = CurveBindingUtility.GetCurrentValue(activeRootGameObject, binding);
                if (curve.length == 0)
                {
                    object outObject = null;
                    if (!ValueFromPropertyModification(modification, binding, out outObject))
                    {
                        outObject = currentValue;
                    }
                    if (state.frame != 0)
                    {
                        AnimationWindowUtility.AddKeyframeToCurve(curve, outObject, type, AnimationKeyTime.Frame(0, activeAnimationClip.frameRate));
                    }
                }
                AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, type, AnimationKeyTime.Frame(state.frame, activeAnimationClip.frameRate));
                state.SaveCurve(curve);
            }
        }
        public void SaveSelectedKeys(List <AnimationWindowKeyframe> currentSelectedKeys)
        {
            List <AnimationWindowCurve> list = new List <AnimationWindowCurve>();

            foreach (AnimationWindowKeyframe current in currentSelectedKeys)
            {
                if (!list.Contains(current.curve))
                {
                    list.Add(current.curve);
                }
                List <AnimationWindowKeyframe> list2 = new List <AnimationWindowKeyframe>();
                foreach (AnimationWindowKeyframe current2 in current.curve.m_Keyframes)
                {
                    if (!currentSelectedKeys.Contains(current2) && AnimationKeyTime.Time(current.time, this.frameRate).frame == AnimationKeyTime.Time(current2.time, this.frameRate).frame)
                    {
                        list2.Add(current2);
                    }
                }
                foreach (AnimationWindowKeyframe current3 in list2)
                {
                    current.curve.m_Keyframes.Remove(current3);
                }
            }
            foreach (AnimationWindowCurve current4 in list)
            {
                this.SaveCurve(current4);
            }
        }
Example #7
0
        static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, Type type, object previousValue, object currentValue)
        {
            AnimationClip clip = state.activeAnimationClip;

            if ((clip.hideFlags & HideFlags.NotEditable) != 0)
            {
                return;
            }

            AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, type);

            // Add previous value at first frame on empty curves.
            if (state.addZeroFrame)
            {
                // Is it a new curve?
                if (curve.length == 0)
                {
                    if (state.currentFrame != 0)
                    {
                        AnimationWindowUtility.AddKeyframeToCurve(curve, previousValue, type, AnimationKeyTime.Frame(0, clip.frameRate));
                    }
                }
            }

            // Add key at current frame.
            AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, type, AnimationKeyTime.Frame(state.currentFrame, clip.frameRate));

            state.SaveCurve(curve);
        }
Example #8
0
        public void AddKeyframe(AnimationWindowKeyframe key, AnimationKeyTime keyTime)
        {
            // If there is already key in this time, we always want to remove it
            RemoveKeyframe(keyTime);

            m_Keyframes.Add(key);
            m_Keyframes.Sort((a, b) => a.time.CompareTo(b.time));
        }
 public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowState state, AnimationWindowCurve curve, AnimationKeyTime time)
 {
     object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, curve.binding);
     System.Type editorCurveValueType = CurveBindingUtility.GetEditorCurveValueType(state.activeRootGameObject, curve.binding);
     AnimationWindowKeyframe keyframe = AddKeyframeToCurve(curve, currentValue, editorCurveValueType, time);
     state.SaveCurve(curve);
     return keyframe;
 }
Example #10
0
        public static AnimationKeyTime Frame(int frame, float frameRate)
        {
            AnimationKeyTime key = new AnimationKeyTime();

            key.m_Frame     = (frame < 0) ? 0 : frame;
            key.m_Time      = key.m_Frame / frameRate;
            key.m_FrameRate = frameRate;
            return(key);
        }
Example #11
0
 private void SetCurrentTime(float value)
 {
     if (!Mathf.Approximately(value, this.time.time))
     {
         this.m_Time = AnimationKeyTime.Time(value, this.state.frameRate);
         this.StartRecording();
         this.ResampleAnimation();
     }
 }
Example #12
0
        public static AnimationKeyTime  Time(float time, float frameRate)
        {
            AnimationKeyTime key = new AnimationKeyTime();

            key.m_Time      = Mathf.Max(time, 0f);
            key.m_FrameRate = frameRate;
            key.m_Frame     = UnityEngine.Mathf.RoundToInt(key.m_Time * frameRate);
            return(key);
        }
        public static AnimationKeyTime Frame(int frame, float frameRate)
        {
            AnimationKeyTime result = default(AnimationKeyTime);

            result.m_Frame     = ((frame >= 0) ? frame : 0);
            result.m_Time      = (float)result.m_Frame / frameRate;
            result.m_FrameRate = frameRate;
            return(result);
        }
        public static AnimationKeyTime Time(float time, float frameRate)
        {
            AnimationKeyTime result = default(AnimationKeyTime);

            result.m_Time      = Mathf.Max(time, 0f);
            result.m_FrameRate = frameRate;
            result.m_Frame     = Mathf.RoundToInt(result.m_Time * frameRate);
            return(result);
        }
 public override void OnSelectionChanged()
 {
     if (this.state != null)
     {
         this.m_Time = AnimationKeyTime.Time(0f, this.state.frameRate);
     }
     this.StopPreview();
     this.StopPlayback();
 }
Example #16
0
 private void SetCurrentFrame(int value)
 {
     if (value != this.time.frame)
     {
         this.m_Time = AnimationKeyTime.Frame(value, this.state.frameRate);
         this.StartRecording();
         this.ResampleAnimation();
     }
 }
 public void RemoveKeyframe(AnimationKeyTime time)
 {
     for (int i = this.m_Keyframes.Count - 1; i >= 0; i--)
     {
         if (time.ContainsTime(this.m_Keyframes[i].time))
         {
             this.m_Keyframes.RemoveAt(i);
         }
     }
 }
Example #18
0
 public void RemoveKeyframe(AnimationKeyTime time)
 {
     for (int index = this.m_Keyframes.Count - 1; index >= 0; --index)
     {
         if (time.ContainsTime(this.m_Keyframes[index].time))
         {
             this.m_Keyframes.RemoveAt(index);
         }
     }
 }
 private void SetCurrentFrame(int value)
 {
     if (value != this.time.frame)
     {
         this.m_Time = AnimationKeyTime.Frame(value, this.state.frameRate);
         this.StartPreview();
         this.ClearCandidates();
         this.ResampleAnimation();
     }
 }
        public AnimationWindowKeyframe FindKeyAtTime(AnimationKeyTime keyTime)
        {
            int keyframeIndex = this.GetKeyframeIndex(keyTime);

            if (keyframeIndex == -1)
            {
                return(null);
            }
            return(this.m_Keyframes[keyframeIndex]);
        }
 private void SetCurrentTime(float value)
 {
     if (!Mathf.Approximately(value, this.time.time))
     {
         this.m_Time = AnimationKeyTime.Time(value, this.state.frameRate);
         this.StartPreview();
         this.ClearCandidates();
         this.ResampleAnimation();
     }
 }
Example #22
0
 private void SetCurrentFrame(int value)
 {
     if (value != time.frame)
     {
         m_Time = AnimationKeyTime.Frame(value, state.frameRate);
         StartPreview();
         ClearCandidates();
         ResampleAnimation();
     }
 }
Example #23
0
 public int GetKeyframeIndex(AnimationKeyTime time)
 {
     for (int index = 0; index < this.m_Keyframes.Count; ++index)
     {
         if (time.ContainsTime(this.m_Keyframes[index].time))
         {
             return(index);
         }
     }
     return(-1);
 }
Example #24
0
        public AnimationWindowKeyframe FindKeyAtTime(AnimationKeyTime keyTime)
        {
            int index = GetKeyframeIndex(keyTime);

            if (index == -1)
            {
                return(null);
            }

            return(m_Keyframes[index]);
        }
Example #25
0
 public void RemoveKeyframe(AnimationKeyTime time)
 {
     // Loop backwards so key removals don't mess up order
     for (int i = m_Keyframes.Count - 1; i >= 0; i--)
     {
         if (time.ContainsTime(m_Keyframes[i].time))
         {
             m_Keyframes.RemoveAt(i);
         }
     }
 }
Example #26
0
        public override void OnSelectionChanged()
        {
            // Set back time at beginning and stop recording.
            if (state != null)
            {
                m_Time = AnimationKeyTime.Time(0f, state.frameRate);
            }

            StopPreview();
            StopPlayback();
        }
 public int GetKeyframeIndex(AnimationKeyTime time)
 {
     for (int i = 0; i < this.m_Keyframes.Count; i++)
     {
         if (time.ContainsTime(this.m_Keyframes[i].time))
         {
             return(i);
         }
     }
     return(-1);
 }
        public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
        {
            List <AnimationWindowCurve> list = (state.activeCurves.Count <= 0) ? state.allCurves : state.activeCurves;

            foreach (AnimationWindowCurve current in list)
            {
                if (current.animationIsEditable)
                {
                    AnimationWindowUtility.AddKeyframeToCurve(state, current, AnimationKeyTime.Time(time.time - current.timeOffset, time.frameRate));
                }
            }
        }
Example #29
0
        static void ProcessAnimatorModification(IAnimationRecordingState state, Animator animator, UndoPropertyModification modification, string name, float value, float scale)
        {
            AnimationClip clip = state.activeAnimationClip;

            if ((clip.hideFlags & HideFlags.NotEditable) != 0)
            {
                return;
            }

            float prevValue = value;

            object oValue;

            if (ValueFromPropertyModification(modification.currentValue, new EditorCurveBinding(), out oValue))
            {
                value = (float)oValue;
            }

            if (ValueFromPropertyModification(modification.previousValue, new EditorCurveBinding(), out oValue))
            {
                prevValue = (float)oValue;
            }

            value     = Mathf.Abs(scale) > Mathf.Epsilon ? value / scale : value;
            prevValue = Mathf.Abs(scale) > Mathf.Epsilon ? prevValue / scale : prevValue;

            var binding = new EditorCurveBinding();

            binding.propertyName = name;
            binding.path         = "";
            binding.type         = typeof(Animator);

            var prop = new PropertyModification();

            prop.target       = animator;
            prop.propertyPath = binding.propertyName;
            prop.value        = value.ToString();

            state.AddPropertyModification(binding, prop, modification.keepPrefabOverride);

            AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, typeof(float));

            if (state.addZeroFrame && state.currentFrame != 0 && curve.length == 0)
            {
                AnimationWindowUtility.AddKeyframeToCurve(curve, prevValue, typeof(float), AnimationKeyTime.Frame(0, clip.frameRate));
            }

            AnimationWindowUtility.AddKeyframeToCurve(curve, value, typeof(float), AnimationKeyTime.Frame(state.currentFrame, clip.frameRate));

            state.SaveCurve(curve);
        }
        public AnimationWindowKeyframe FindKeyAtTime(AnimationKeyTime keyTime)
        {
            int keyframeIndex = this.GetKeyframeIndex(keyTime);
            AnimationWindowKeyframe result;

            if (keyframeIndex == -1)
            {
                result = null;
            }
            else
            {
                result = this.m_Keyframes[keyframeIndex];
            }
            return(result);
        }
        public int GetKeyframeIndex(AnimationKeyTime time)
        {
            int result;

            for (int i = 0; i < this.m_Keyframes.Count; i++)
            {
                if (time.ContainsTime(this.m_Keyframes[i].time))
                {
                    result = i;
                    return(result);
                }
            }
            result = -1;
            return(result);
        }
 public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, System.Type type, AnimationKeyTime time)
 {
     AnimationWindowKeyframe keyframe = curve.FindKeyAtTime(time);
     if (keyframe != null)
     {
         keyframe.value = value;
         return keyframe;
     }
     AnimationWindowKeyframe key = new AnimationWindowKeyframe {
         time = time.time
     };
     if (curve.isPPtrCurve)
     {
         key.value = value;
         key.curve = curve;
         curve.AddKeyframe(key, time);
         return key;
     }
     if ((type == typeof(bool)) || (type == typeof(float)))
     {
         AnimationCurve curve2 = curve.ToAnimationCurve();
         Keyframe keyframe3 = new Keyframe(time.time, (float) value);
         if (type == typeof(bool))
         {
             CurveUtility.SetKeyTangentMode(ref keyframe3, 0, TangentMode.Stepped);
             CurveUtility.SetKeyTangentMode(ref keyframe3, 1, TangentMode.Stepped);
             CurveUtility.SetKeyBroken(ref keyframe3, true);
             key.m_TangentMode = keyframe3.tangentMode;
             key.m_InTangent = float.PositiveInfinity;
             key.m_OutTangent = float.PositiveInfinity;
         }
         else
         {
             int keyIndex = curve2.AddKey(keyframe3);
             if (keyIndex != -1)
             {
                 CurveUtility.SetKeyModeFromContext(curve2, keyIndex);
                 Keyframe keyframe4 = curve2[keyIndex];
                 key.m_TangentMode = keyframe4.tangentMode;
             }
         }
         key.value = value;
         key.curve = curve;
         curve.AddKeyframe(key, time);
     }
     return key;
 }
		public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowState state, AnimationWindowCurve curve, AnimationKeyTime time)
		{
			object currentValue = AnimationWindowUtility.GetCurrentValue(state.m_RootGameObject, curve.binding);
			Type editorCurveValueType = AnimationUtility.GetEditorCurveValueType(state.m_RootGameObject, curve.binding);
			AnimationWindowKeyframe result = AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, editorCurveValueType, time);
			state.SaveCurve(curve);
			return result;
		}
		public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
		{
			foreach (AnimationWindowCurve current in state.activeCurves)
			{
				AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
			}
		}
		public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, Type type, AnimationKeyTime time)
		{
			AnimationWindowKeyframe animationWindowKeyframe = curve.FindKeyAtTime(time);
			if (animationWindowKeyframe != null)
			{
				animationWindowKeyframe.value = value;
				return animationWindowKeyframe;
			}
			AnimationWindowKeyframe animationWindowKeyframe2 = new AnimationWindowKeyframe();
			animationWindowKeyframe2.time = time.time;
			if (curve.isPPtrCurve)
			{
				animationWindowKeyframe2.value = value;
				animationWindowKeyframe2.curve = curve;
				curve.AddKeyframe(animationWindowKeyframe2, time);
			}
			else
			{
				if (type == typeof(bool) || type == typeof(float))
				{
					AnimationCurve animationCurve = curve.ToAnimationCurve();
					Keyframe key = new Keyframe(time.time, (float)value);
					if (type == typeof(bool))
					{
						CurveUtility.SetKeyTangentMode(ref key, 0, TangentMode.Stepped);
						CurveUtility.SetKeyTangentMode(ref key, 1, TangentMode.Stepped);
						CurveUtility.SetKeyBroken(ref key, true);
						animationWindowKeyframe2.m_TangentMode = key.tangentMode;
						animationWindowKeyframe2.m_InTangent = float.PositiveInfinity;
						animationWindowKeyframe2.m_OutTangent = float.PositiveInfinity;
					}
					else
					{
						int num = animationCurve.AddKey(key);
						if (num != -1)
						{
							CurveUtility.SetKeyModeFromContext(animationCurve, num);
							animationWindowKeyframe2.m_TangentMode = animationCurve[num].tangentMode;
						}
					}
					animationWindowKeyframe2.value = value;
					animationWindowKeyframe2.curve = curve;
					curve.AddKeyframe(animationWindowKeyframe2, time);
				}
			}
			return animationWindowKeyframe2;
		}
 public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
 {
     if (state.activeCurves.Count > 0)
     {
         foreach (AnimationWindowCurve curve in state.activeCurves)
         {
             AddKeyframeToCurve(state, curve, time);
         }
     }
     else
     {
         foreach (AnimationWindowCurve curve2 in state.allCurves)
         {
             AddKeyframeToCurve(state, curve2, time);
         }
     }
 }
 public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, System.Type type, AnimationKeyTime time)
 {
   AnimationWindowKeyframe keyAtTime = curve.FindKeyAtTime(time);
   if (keyAtTime != null)
   {
     keyAtTime.value = value;
     return keyAtTime;
   }
   AnimationWindowKeyframe key1 = new AnimationWindowKeyframe();
   key1.time = time.time;
   if (curve.isPPtrCurve)
   {
     key1.value = value;
     key1.curve = curve;
     curve.AddKeyframe(key1, time);
   }
   else if (type == typeof (bool) || type == typeof (float))
   {
     AnimationCurve animationCurve = curve.ToAnimationCurve();
     Keyframe key2 = new Keyframe(time.time, (float) value);
     if (type == typeof (bool))
     {
       CurveUtility.SetKeyTangentMode(ref key2, 0, TangentMode.Stepped);
       CurveUtility.SetKeyTangentMode(ref key2, 1, TangentMode.Stepped);
       CurveUtility.SetKeyBroken(ref key2, true);
       key1.m_TangentMode = key2.tangentMode;
       key1.m_InTangent = float.PositiveInfinity;
       key1.m_OutTangent = float.PositiveInfinity;
     }
     else
     {
       int keyIndex = animationCurve.AddKey(key2);
       if (keyIndex != -1)
       {
         CurveUtility.SetKeyModeFromContext(animationCurve, keyIndex);
         key1.m_TangentMode = animationCurve[keyIndex].tangentMode;
       }
     }
     key1.value = value;
     key1.curve = curve;
     curve.AddKeyframe(key1, time);
   }
   return key1;
 }
 public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
 {
   if (state.activeCurves.Count > 0)
   {
     using (List<AnimationWindowCurve>.Enumerator enumerator = state.activeCurves.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         AnimationWindowCurve current = enumerator.Current;
         AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
       }
     }
   }
   else
   {
     using (List<AnimationWindowCurve>.Enumerator enumerator = state.allCurves.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         AnimationWindowCurve current = enumerator.Current;
         AnimationWindowUtility.AddKeyframeToCurve(state, current, time);
       }
     }
   }
 }