Example #1
0
        public AMKey[] removeSelectedKeysFromTrack(AMTakeData take, AMITarget itarget, int track_id)
        {
            List <AMKey> dkeys = new List <AMKey>();

            bool    didDeleteKeys = false;
            AMTrack track         = take.getTrack(track_id);

            for (int i = 0; i < track.keys.Count; i++)
            {
                if (!isFrameInContextSelection(track.keys[i].frame))
                {
                    continue;
                }
                dkeys.Add(track.keys[i]);
                track.keys.Remove(track.keys[i]);
                i--;
                didDeleteKeys = true;
            }
            if (didDeleteKeys)
            {
                track.updateCache(itarget);
            }

            return(dkeys.ToArray());
        }
Example #2
0
        /// <summary>
        /// This will only duplicate the tracks and groups, includeKeys=true to also duplicate keys
        /// </summary>
        /// <param name="take"></param>
        public void DuplicateTake(AMTakeData dupTake, bool includeKeys, bool addCompUndo)
        {
            AMTakeData a = new AMTakeData();

            a.name = dupTake.name;
            MakeTakeNameUnique(a);
            a.numLoop         = dupTake.numLoop;
            a.loopMode        = dupTake.loopMode;
            a.frameRate       = dupTake.frameRate;
            a.endFramePadding = dupTake.endFramePadding;
            //a.lsTracks = new List<AMTrack>();
            //a.dictTracks = new Dictionary<int,AMTrack>();

            if (dupTake.rootGroup != null)
            {
                a.rootGroup = dupTake.rootGroup.duplicate();
            }
            else
            {
                a.initGroups();
            }

            a.group_count = dupTake.group_count;

            if (dupTake.groupValues != null)
            {
                a.groupValues = new List <AMGroup>();
                foreach (AMGroup grp in dupTake.groupValues)
                {
                    a.groupValues.Add(grp.duplicate());
                }
            }

            a.track_count = dupTake.track_count;

            if (dupTake.trackValues != null)
            {
                a.trackValues = new List <AMTrack>();
                foreach (AMTrack track in dupTake.trackValues)
                {
                    GameObject holderGO = (this as AMITarget).holder.gameObject;
                    AMTrack    dupTrack = (addCompUndo ? UnityEditor.Undo.AddComponent(holderGO, track.GetType()) : holderGO.AddComponent(track.GetType())) as AMTrack;
                    dupTrack.enabled = false;
                    track.CopyTo(dupTrack);
                    a.trackValues.Add(dupTrack);

                    dupTrack.maintainTrack(mDataTarget);

                    Object tgtObj = dupTrack.GetTarget(mDataTarget);

                    //if there's no target, then we can't add the keys for events and properties
                    if (includeKeys && !(tgtObj == null && (dupTrack is AMPropertyTrack || dupTrack is AMEventTrack)))
                    {
                        foreach (AMKey key in track.keys)
                        {
                            AMKey dupKey = (addCompUndo ? UnityEditor.Undo.AddComponent(holderGO, key.GetType()) : holderGO.AddComponent(key.GetType())) as AMKey;
                            if (dupKey)
                            {
                                key.CopyTo(dupKey);
                                dupKey.enabled = false;
                                dupKey.maintainKey(mDataTarget, tgtObj);
                                dupTrack.keys.Add(dupKey);
                            }
                        }

                        dupTrack.updateCache(mDataTarget);
                    }
                }
            }

            takes.Add(a);
        }
Example #3
0
        void OnGUI()
        {
        #if UNITY_5
            titleContent = new GUIContent("Ease: " + (oData.time_numbering ? AMTimeline.frameToTime(key.frame, (float)aData.currentTake.frameRate) + " s" : key.frame.ToString()));
        #else
            title = "Ease: " + (oData.time_numbering ? AMTimeline.frameToTime(key.frame, (float)aData.currentTake.frameRate) + " s" : key.frame.ToString());
        #endif
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            bool updateEasingCurve = false;

            GUIStyle styleBox = new GUIStyle(GUI.skin.button);
            styleBox.normal = GUI.skin.button.active;
            styleBox.hover  = styleBox.normal;
            styleBox.border = GUI.skin.button.border;
            GUILayout.BeginArea(new Rect(5f, 5f, position.width - 10f, position.height - 10f));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("", styleBox, GUILayout.Width(500f), GUILayout.Height(100f)))
            {
                selectedSpeedIndex = (selectedSpeedIndex + 1) % speedValues.Length;
                percent            = waitPercent * -1f;
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(5f);
            GUILayout.BeginHorizontal();
            int  prevCategory         = category;
            bool updatedSelectedIndex = false;
            if (setCategory(GUILayout.SelectionGrid(category, categories, (position.width >= 715f ? 12 : 6), GUILayout.Width(position.width - 16f))))
            {
                selectedIndex = getSelectedEaseIndex(prevCategory, selectedIndex);
                selectedIndex = getCategoryIndexForEase(selectedIndex);
                if (selectedIndex < 1)
                {
                    selectedIndex        = 1;
                    percent              = waitPercent * -1f;
                    updatedSelectedIndex = true;
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5f);

            GUILayout.BeginVertical(GUILayout.Height(233f));
            if (updatedSelectedIndex || setSelectedIndex(GUILayout.SelectionGrid(selectedIndex, easeTypesFiltered[category].ToArray(), 3)))
            {
                percent           = waitPercent * -1f;
                updateEasingCurve = true;
                if (getSelectedEaseName(category, selectedIndex) == "Custom")
                {
                    isCustomEase = true;
                    if (key.customEase.Count > 0)
                    {
                        curve = key.getCustomEaseCurve();
                    }
                    else
                    {
                        setEasingCurve();
                    }
                }
                else
                {
                    isCustomEase = false;
                }
            }
            GUILayout.EndVertical();
            GUILayout.Space(5f);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Apply"))
            {
                int  nease             = AMTimeline.GetEaseIndex(getSelectedEaseIndex(category, selectedIndex));
                bool shouldUpdateCache = false;
                if (isCustomEase)
                {
                    key.setCustomEase(curve);
                    shouldUpdateCache = true;
                }
                if (key.easeType != nease)
                {
                    shouldUpdateCache = true;
                }
                if (shouldUpdateCache)
                {
                    AnimatorDataEdit.RecordUndoTrackAndKeys(track, false, "Change Ease");
                    key.setEaseType(nease);
                    // update cache when modifying varaibles
                    track.updateCache(aData.target);
                    // preview new position
                    aData.currentTake.previewFrame(aData.target, aData.currentTake.selectedFrame);
                }
                this.Close();
            }
            if (GUILayout.Button("Cancel"))
            {
                this.Close();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            // orb texture
            GUI.DrawTexture(new Rect(x_pos, 15f, 80f, 80f), tex_orb);
            // speed label
            GUIStyle styleLabelRight = new GUIStyle(GUI.skin.label);
            styleLabelRight.alignment        = TextAnchor.MiddleRight;
            styleLabelRight.normal.textColor = Color.white;
            EditorGUI.DropShadowLabel(new Rect(475f, 5f, 25f, 25f), speedNames[selectedSpeedIndex], styleLabelRight);
            // draw border
            GUI.color = GUI.skin.window.normal.textColor;
            GUI.DrawTexture(new Rect(0f, 0f, 7f, 110f), EditorGUIUtility.whiteTexture);
            GUI.DrawTexture(new Rect(position.width - 209f, 0f, 208f, 110f), EditorGUIUtility.whiteTexture);
            GUI.color = Color.white;

            // curve field
            if (updateEasingCurve)
            {
                setEasingCurve();
            }
            else if (!isCustomEase && didChangeCurve())
            {
                isCustomEase  = true;
                selectedIndex = getCategoryIndexForEaseName("Custom");
                if (selectedIndex < 0)
                {
                    category      = 0;
                    selectedIndex = getCategoryIndexForEaseName("Custom");
                }
            }
            curve = EditorGUI.CurveField(new Rect(500f, 5f, 208f, 100f), curve);
        }
Example #4
0
        /*public AMKey[] getContextSelectionKeys() {
         *  List<AMKey> keys = new List<AMKey>();
         *  foreach(AMKey key in getSelectedTrack().keys) {
         *      for(int i=0;i<contextSelection.Count;i+=2) {
         *          // if selection start frame > frame, break out of sorted list
         *          if(contextSelection[i] > key.frame) break;
         *          if(contextSelection[i] <= key.frame && contextSelection[i+1] >= key.frame) keys.Add(key);
         *      }
         *  }
         *  return keys.ToArray();
         * }*/

        // offset context selection frames by an amount. can be positive or negative
        //returns keys that are to be deleted
        public AMKey[] offsetContextSelectionFramesBy(AMTakeData take, AMITarget itarget, int offset)
        {
            if (offset == 0)
            {
                return(new AMKey[0]);
            }
            if (contextSelection.Count <= 0)
            {
                return(new AMKey[0]);
            }

            List <AMKey> rkeys        = new List <AMKey>();
            List <AMKey> keysToDelete = new List <AMKey>();

            foreach (int track_id in contextSelectionTracks)
            {
                bool    shouldUpdateCache = false;
                AMTrack _track            = take.getTrack(track_id);
                foreach (AMKey key in _track.keys)
                {
                    for (int i = 0; i < contextSelection.Count; i += 2)
                    {
                        // move context selection
                        if (contextSelection[i] <= key.frame && contextSelection[i + 1] >= key.frame)
                        {
                            // if there is already a key in the new frame position, mark for deletion
                            bool keyToOverwriteInContextSelection = false;
                            if (_track.hasKeyOnFrame(key.frame + offset))
                            {
                                // check if the key is in the selection
                                for (int j = 0; j < contextSelection.Count; j += 2)
                                {
                                    if (contextSelection[j] <= (key.frame + offset) && contextSelection[j + 1] >= (key.frame + offset))
                                    {
                                        keyToOverwriteInContextSelection = true;
                                        break;
                                    }
                                }
                                // if not key is not in selection, mark for deletion
                                if (!keyToOverwriteInContextSelection)
                                {
                                    keysToDelete.Add(_track.getKeyOnFrame(key.frame + offset));
                                }
                            }
                            key.frame += offset;
                            if (!shouldUpdateCache)
                            {
                                shouldUpdateCache = true;
                            }
                            break;
                        }
                    }
                }

                // delete keys that were overwritten
                foreach (AMKey key in keysToDelete)
                {
                    _track.keys.Remove(key);
                    rkeys.Add(key);
                }
                keysToDelete.Clear();

                // update cache
                if (shouldUpdateCache)
                {
                    _track.updateCache(itarget);
                }
            }
            // update context selection
            for (int i = 0; i < contextSelection.Count; i++)
            {
                // move context selection
                contextSelection[i] += offset;
            }
            // clear ghost selection
            ghostSelection = new List <int>();

            return(rkeys.ToArray());
        }