Exemplo n.º 1
0
    public static void AddSprites(AnimationClip clip, string path, int startIdx, int endIdx, float frameRate)
    {
        Sprite[] sprites = AssetToSpriteArray(path);

        EditorCurveBinding spriteBinding = new EditorCurveBinding();

        spriteBinding.type         = typeof(SpriteRenderer);
        spriteBinding.path         = "";
        spriteBinding.propertyName = "m_Sprite";

        int numFrames = (endIdx - startIdx) + 1;

        ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[numFrames];
        for (int i = 0, idx = startIdx; idx <= endIdx; i++, idx++)
        {
            AnimationKeyTime akt = FrameToAnimationKey(i, frameRate);
            spriteKeyFrames[i]       = new ObjectReferenceKeyframe();
            spriteKeyFrames[i].time  = akt.Time;
            spriteKeyFrames[i].value = sprites[idx];
        }

        AnimationClipSettings clipSettings = new AnimationClipSettings();

        clipSettings.loopTime              = true;
        clipSettings.startTime             = 0f;
        clipSettings.keepOriginalPositionY = true;
        AnimationUtility.SetAnimationClipSettings(clip, clipSettings);

        // This function sets clipSettings.stopTime
        AnimationUtility.SetObjectReferenceCurve(clip, spriteBinding, spriteKeyFrames);
    }
Exemplo n.º 2
0
    public void Update()
    {
        float deltaTime = Time.realtimeSinceStartup - previousTime;

        m_Time.m_FrameRate = 1 / deltaTime;
        previousTime       = Time.realtimeSinceStartup;
        if (deltaTime > 0)
        {
            accumulatedTime += deltaTime;
        }
        if (accumulatedTime >= FRAME_LIMITER)
        {
            Repaint();
            accumulatedTime -= FRAME_LIMITER;
        }
        if (cutscene != null)
        {
            if (!Application.isPlaying && cutscene.State == Cutscene.CutsceneState.PreviewPlaying)
            {
                float newTime = m_Time.time + deltaTime;
                m_Time             = AnimationKeyTime.Time(newTime, directorControl.frameRate);
                Cutscene.frameRate = m_Time.frameRate;
                Cutscene.frame     = m_Time.frame;
                cutscene.UpdateCutscene(deltaTime);
            }
        }
    }
Exemplo n.º 3
0
 private void HandleHotKeys()
 {
     if (!GUI.enabled || this.m_State.disabled)
     {
         return;
     }
     if (AnimEditor.kAnimationPrevKeyframe.activated)
     {
         this.MoveToPreviousKeyframe();
     }
     if (AnimEditor.kAnimationNextKeyframe.activated)
     {
         this.MoveToNextKeyframe();
     }
     if (AnimEditor.kAnimationNextFrame.activated)
     {
         this.m_State.frame++;
     }
     if (AnimEditor.kAnimationPrevFrame.activated)
     {
         this.m_State.frame--;
     }
     if (AnimEditor.kAnimationPrevKeyframe.activated || AnimEditor.kAnimationNextKeyframe.activated || AnimEditor.kAnimationNextFrame.activated || AnimEditor.kAnimationPrevFrame.activated)
     {
         Event.current.Use();
         this.Repaint();
     }
     if (AnimEditor.kAnimationRecordKeyframe.activated)
     {
         AnimationKeyTime time = AnimationKeyTime.Time(this.m_State.currentTime, this.m_State.frameRate);
         AnimationWindowUtility.AddSelectedKeyframes(this.m_State, time);
         Event.current.Use();
     }
 }
Exemplo n.º 4
0
    private bool addKeyOnUserInteraction(float value, float curveValue, AnimationCurve curve, float scrubberPosition, bool inArea = true, float theshold = 0.000001f)
    {
        var  time            = (float)Mathf.RoundToInt(scrubberPosition * DirectorWindow.directorControl.frameRate) / DirectorWindow.directorControl.frameRate;
        bool differenceFound = false;
        var  v = Math.Abs(value - curveValue);

        if (v > theshold && !inArea)
        {
            differenceFound = true;
            if (hasUserInteracted)
            {
                AddOrMoveKey(time, curve, value);
            }
        }
        else if (Event.current.keyCode == KeyCode.K)
        {
            AnimationKeyTime akt = AnimationKeyTime.Time(time, DirectorWindow.directorControl.frameRate);
            for (int j = 0; j < curve.length; j++)
            {
                Keyframe k = curve[j];
                if (akt.ContainsTime(k.time))
                {
                    return(false);
                }
            }
            Keyframe kf = new Keyframe(time, value);
            AnimationCurveHelper.AddKey(curve, kf, akt);
            differenceFound = true;
        }
        else
        {
            RecordNeedKeyframeCurve(time, curve, value);
        }
        return(differenceFound);
    }
Exemplo n.º 5
0
    public static void AddAnimationKey(float frameRate, AnimationCurve curve, int frame, float value, AnimationUtility.TangentMode left, AnimationUtility.TangentMode right)
    {
        AnimationKeyTime a = FrameToAnimationKey(frame, frameRate);
        int idx            = curve.AddKey(new Keyframe(a.Time, value));

        AnimationUtility.SetKeyLeftTangentMode(curve, idx, left);
        AnimationUtility.SetKeyRightTangentMode(curve, idx, right);
    }
Exemplo n.º 6
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     = Mathf.RoundToInt(key.m_Time * frameRate);
        return(key);
    }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
 public int GetKeyframeIndex(AnimationKeyTime time)
 {
     for (int i = 0; i < curve.length; i++)
     {
         if (time.ContainsTime(curve[i].time))
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 9
0
        private void AddKeyframeButtonOnGUI()
        {
            bool flag = this.m_State.selection.Find((AnimationWindowSelectionItem selectedItem) => selectedItem.animationIsEditable);

            using (new EditorGUI.DisabledScope(!flag))
            {
                if (GUILayout.Button(AnimationWindowStyles.addKeyframeContent, EditorStyles.toolbarButton, new GUILayoutOption[0]) || (GUI.enabled && AnimEditor.kAnimationRecordKeyframe.activated))
                {
                    AnimationKeyTime time = AnimationKeyTime.Time(this.m_State.currentTime, this.m_State.frameRate);
                    AnimationWindowUtility.AddSelectedKeyframes(this.m_State, time);
                }
            }
        }
Exemplo n.º 10
0
    internal void PauseAtTime(float srcTime, float destTime)
    {
        AnimationKeyTime srcKeyTime  = AnimationKeyTime.Time(srcTime, DirectorWindow.directorControl.frameRate);
        AnimationKeyTime destKeyTime = AnimationKeyTime.Time(destTime, DirectorWindow.directorControl.frameRate);
        int srcNum  = GetKeyframeIndex(srcKeyTime);
        int destNum = GetKeyframeIndex(destKeyTime);

        if (srcNum >= 0 && destNum >= 0)
        {
            Keyframe srcKeyframe = curve.keys[srcNum];
            RemoveAtTime(destTime);
            AddKey(destTime, srcKeyframe.value, DirectorWindow.directorControl.DefaultTangentMode);
        }
    }
Exemplo n.º 11
0
 private void AddKeyframeButtonOnGUI()
 {
     using (new EditorGUI.DisabledScope(!this.selection.animationIsEditable))
     {
         if (GUILayout.Button(AnimationWindowStyles.addKeyframeContent, EditorStyles.toolbarButton, new GUILayoutOption[0]))
         {
             this.SaveCurveEditorKeySelection();
             AnimationKeyTime time = AnimationKeyTime.Time(this.m_State.currentTime, this.m_State.frameRate);
             AnimationWindowUtility.AddSelectedKeyframes(this.m_State, time);
             this.UpdateSelectedKeysToCurveEditor();
             GUIUtility.ExitGUI();
         }
     }
 }
Exemplo n.º 12
0
        private void AddKeyframeButtonOnGUI()
        {
            using (new EditorGUI.DisabledScope(!selection.animationIsEditable))
            {
                if (GUILayout.Button(AnimationWindowStyles.addKeyframeContent, EditorStyles.toolbarButton))
                {
                    SaveCurveEditorKeySelection();
                    var keyTime = AnimationKeyTime.Time(m_State.currentTime, m_State.frameRate);
                    AnimationWindowUtility.AddSelectedKeyframes(m_State, keyTime);
                    UpdateSelectedKeysToCurveEditor();

                    // data is scheduled for an update, bail out now to avoid using out of date data.
                    EditorGUIUtility.ExitGUI();
                }
            }
        }
Exemplo n.º 13
0
    private void AddOrMoveKey(float time, AnimationCurve curve, float value)
    {
        bool             doesKeyExist = false;
        AnimationKeyTime akt          = AnimationKeyTime.Time(time, DirectorWindow.directorControl.frameRate);

        for (int j = 0; j < curve.length; j++)
        {
            Keyframe k = curve[j];
            if (akt.ContainsTime(k.time))
            {
                Keyframe newKeyframe = new Keyframe(k.time, value, k.inTangent, k.outTangent);
                AnimationCurveHelper.MoveKey(curve, j, newKeyframe);
                doesKeyExist = true;
            }
        }
        if (!doesKeyExist)
        {
            Keyframe kf = new Keyframe(time, value);
            AnimationCurveHelper.AddKey(curve, kf, akt);
        }
    }
Exemplo n.º 14
0
 private void HandleHotKeys()
 {
     if (GUI.enabled && !this.m_State.disabled)
     {
         bool flag = false;
         if (AnimEditor.kAnimationPrevKeyframe.activated)
         {
             this.controlInterface.GoToPreviousKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationNextKeyframe.activated)
         {
             this.controlInterface.GoToNextKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationNextFrame.activated)
         {
             this.controlInterface.GoToNextFrame();
             flag = true;
         }
         if (AnimEditor.kAnimationPrevFrame.activated)
         {
             this.controlInterface.GoToPreviousFrame();
             flag = true;
         }
         if (AnimEditor.kAnimationFirstKey.activated)
         {
             this.controlInterface.GoToFirstKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationLastKey.activated)
         {
             this.controlInterface.GoToLastKeyframe();
             flag = true;
         }
         if (flag)
         {
             Event.current.Use();
             this.Repaint();
         }
         if (AnimEditor.kAnimationPlayToggle.activated)
         {
             if (this.controlInterface.playing)
             {
                 this.controlInterface.StopPlayback();
             }
             else
             {
                 this.controlInterface.StartPlayback();
             }
             Event.current.Use();
         }
         if (AnimEditor.kAnimationRecordKeyframe.activated)
         {
             this.SaveCurveEditorKeySelection();
             AnimationKeyTime time = AnimationKeyTime.Time(this.m_State.currentTime, this.m_State.frameRate);
             AnimationWindowUtility.AddSelectedKeyframes(this.m_State, time);
             this.UpdateSelectedKeysToCurveEditor();
             Event.current.Use();
         }
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Add a new key to an AnimationCurve.
        /// Ensures the integrity of other key's tangent modes.
        /// </summary>
        /// <param name="curve">The existing AnimationCurve.</param>
        /// <param name="keyframe">The new keyframe</param>
        /// <returns>The index of the newly added key.</returns>
        public static int AddKey(AnimationCurve curve, Keyframe keyframe, AnimationKeyTime akt)
        {
            if (curve.length == 0)
            {
                return(curve.AddKey(keyframe));
            }
            if (curve.length == 1)
            {
                // Save the existing keyframe data. (Unity changes the tangent info).
                Keyframe temp = curve[0];
                if (!akt.ContainsTime(temp.time))
                {
                    int newIndex = curve.AddKey(keyframe);
                    if (newIndex == -1)
                    {
                        return(0);
                    }
                    if (newIndex == 0)
                    {
                        curve.MoveKey(1, temp);
                    }
                    else
                    {
                        curve.MoveKey(0, temp);
                    }
                    return(newIndex);
                }
                curve.RemoveKey(0);
                curve.AddKey(keyframe);
                return(0);
            }
            Keyframe left  = new Keyframe();
            Keyframe right = new Keyframe();

            for (int i = 0; i < curve.length - 1; i++)
            {
                Keyframe l = curve[i];
                Keyframe r = curve[i + 1];

                if (l.time < keyframe.time && keyframe.time < r.time)
                {
                    left  = l;
                    right = r;
                }
            }

            int index = curve.AddKey(keyframe);

            // Handle left neighbour.
            if (index > 0)
            {
                // Restore the saved data.
                curve.MoveKey(index - 1, left);

                // Update tangent data based on tangent mode.
                int tangentMode = curve[index - 1].tangentMode;
                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(index - 1, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsRightLinear(tangentMode))
                    {
                        SetKeyRightLinear(curve, index - 1);
                    }
                }
            }

            // Handle the Right neighbour.
            if (index < curve.length - 1)
            {
                // Restore the saved data.
                curve.MoveKey(index + 1, right);

                // Update tangent data based on tangent mode.
                int tangentMode = curve[index + 1].tangentMode;
                if (IsAuto(tangentMode))
                {
                    curve.SmoothTangents(index + 1, 0);
                }
                if (IsBroken(tangentMode))
                {
                    if (IsLeftLinear(tangentMode))
                    {
                        SetKeyLeftLinear(curve, index + 1);
                    }
                }
            }

            return(index);
        }
Exemplo n.º 16
0
 public bool Equals(AnimationKeyTime key)
 {
     return(m_Frame == key.m_Frame && m_FrameRate == key.m_FrameRate && Mathf.Approximately(m_Time, key.m_Time));
 }
Exemplo n.º 17
0
 public bool HasKeyframe(AnimationKeyTime time)
 {
     return(GetKeyframeIndex(time) != -1);
 }
Exemplo n.º 18
0
 private void HandleHotKeys()
 {
     if (GUI.enabled && !this.m_State.disabled)
     {
         bool flag = false;
         if (AnimEditor.kAnimationPrevKeyframe.activated)
         {
             this.MoveToPreviousKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationNextKeyframe.activated)
         {
             this.MoveToNextKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationNextFrame.activated)
         {
             this.m_State.frame++;
             flag = true;
         }
         if (AnimEditor.kAnimationPrevFrame.activated)
         {
             this.m_State.frame--;
             flag = true;
         }
         if (AnimEditor.kAnimationFirstKey.activated)
         {
             this.MoveToFirstKeyframe();
             flag = true;
         }
         if (AnimEditor.kAnimationLastKey.activated)
         {
             this.MoveToLastKeyframe();
             flag = true;
         }
         if (flag)
         {
             Event.current.Use();
             this.Repaint();
         }
         if (AnimEditor.kAnimationPlayToggle.activated)
         {
             this.m_State.playing      = !this.m_State.playing;
             this.m_PreviousUpdateTime = Time.realtimeSinceStartup;
             Event.current.Use();
         }
         if (AnimEditor.kAnimationPlayToggle.activated)
         {
             this.m_State.playing      = !this.m_State.playing;
             this.m_PreviousUpdateTime = Time.realtimeSinceStartup;
             Event.current.Use();
         }
         if (AnimEditor.kAnimationRecordKeyframe.activated)
         {
             this.SaveCurveEditorKeySelection();
             AnimationKeyTime time = AnimationKeyTime.Time(this.m_State.currentTime, this.m_State.frameRate);
             AnimationWindowUtility.AddSelectedKeyframes(this.m_State, time);
             this.UpdateSelectedKeysToCurveEditor();
             Event.current.Use();
         }
     }
 }
Exemplo n.º 19
0
    public void AddKey(float time, float value, int tangentMode)
    {
        Keyframe         keyframe  = default;
        Keyframe         keyframe2 = default;
        AnimationKeyTime akt       = AnimationKeyTime.Time(time, DirectorWindow.directorControl.frameRate);

        time = (float)akt.m_Frame / DirectorWindow.directorControl.frameRate;
        int num = GetKeyframeIndex(akt);

        if (num == -1)
        {
            for (int i = 0; i < curve.length - 1; i++)
            {
                Keyframe keyframe3 = curve[i];
                Keyframe keyframe4 = curve[i + 1];
                if (keyframe3.time < time && time < keyframe4.time)
                {
                    keyframe  = keyframe3;
                    keyframe2 = keyframe4;
                }
            }
            Keyframe keyframe5 = new Keyframe(time, value);
            num = curve.AddKey(keyframe5);
            ArrayUtility.Insert(ref KeyframeControls, num, new CinemaKeyframeWrapper(this, keyframe5));
        }
        else
        {
            Keyframe keyframe5 = curve[num];
            keyframe5.value = value;
            if (num > 0)
            {
                keyframe = curve[num - 1];
            }
            if (num < curve.length - 1)
            {
                keyframe2 = curve[num + 1];
            }
        }
        if (IsAuto(num))
        {
            SmoothTangents(num, 0f);
        }
        if (IsBroken(num))
        {
            if (IsLeftLinear(num))
            {
                SetKeyLeftLinear(num);
            }
            if (IsRightLinear(num))
            {
                SetKeyRightLinear(num);
            }
            if (IsLeftConstant(num))
            {
                SetKeyLeftConstant(num);
            }
            if (IsRightConstant(num))
            {
                SetKeyRightConstant(num);
            }
        }
        if (num > 0)
        {
            curve.MoveKey(num - 1, keyframe);
            ArrayUtility.Insert(ref KeyframeControls, num, new CinemaKeyframeWrapper(this, keyframe));
            if (IsAuto(num - 1))
            {
                SmoothTangents(num - 1, 0f);
            }
            if (IsBroken(num - 1) && IsRightLinear(num - 1))
            {
                SetKeyRightLinear(num - 1);
            }
        }
        if (num < curve.length - 1)
        {
            curve.MoveKey(num + 1, keyframe2);
            ArrayUtility.Insert(ref KeyframeControls, num, new CinemaKeyframeWrapper(this, keyframe2));
            if (IsAuto(num + 1))
            {
                SmoothTangents(num + 1, 0f);
            }
            if (IsBroken(num + 1) && IsLeftLinear(num + 1))
            {
                SetKeyLeftLinear(num + 1);
            }
        }
    }