コード例 #1
0
        public void SetBoth(TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, false);
                AnimationUtility.SetKeyRightTangentMode(ref key, mode);
                AnimationUtility.SetKeyLeftTangentMode(ref key, mode);

                // Smooth Tangents based on neighboring nodes
                // Note: not needed since the UpdateTangentsFromModeSurrounding call below will handle it
                //if (mode == TangentMode.ClampedAuto) animationCurve.SmoothTangents(keyToSet.key, 0.0F);
                // Smooth tangents based on existing tangents
                if (mode == TangentMode.Free)
                {
                    float slope = CurveUtility.CalculateSmoothTangent(key);
                    key.inTangent  = slope;
                    key.outTangent = slope;
                }
                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
コード例 #2
0
        // (case 1029160) Modified version of EditorGUI.DoPopup to fit large data list query.
        private AnimationClip DoClipPopup(AnimationClip clip, GUIStyle style)
        {
            Rect position  = EditorGUILayout.GetControlRect(false, EditorGUI.kSingleLineHeight, style);
            int  controlID = GUIUtility.GetControlID(s_ClipPopupHash, FocusType.Keyboard, position);

            clip = ClipPopupCallbackInfo.GetSelectedClipForControl(controlID, clip);

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.Repaint:
                Font originalFont = style.font;
                if (originalFont && EditorGUIUtility.GetBoldDefaultFont() && originalFont == EditorStyles.miniFont)
                {
                    style.font = EditorStyles.miniBoldFont;
                }

                GUIContent buttonContent = EditorGUIUtility.TempContent(CurveUtility.GetClipName(clip));
                buttonContent.tooltip = AssetDatabase.GetAssetPath(clip);

                style.Draw(position, buttonContent, controlID, false);

                style.font = originalFont;
                break;

            case EventType.MouseDown:
                if (evt.button == 0 && position.Contains(evt.mousePosition))
                {
                    DisplayClipMenu(position, controlID, clip);
                    GUIUtility.keyboardControl = controlID;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (evt.MainActionKeyForControl(controlID))
                {
                    DisplayClipMenu(position, controlID, clip);
                    evt.Use();
                }
                break;
            }

            return(clip);
        }
コード例 #3
0
        private AnimationClip[] GetOrderedClipList()
        {
            AnimationClip[] clips = new AnimationClip[0];
            if (state.activeRootGameObject != null)
            {
                clips = AnimationUtility.GetAnimationClips(state.activeRootGameObject);
            }

            if (!string.IsNullOrEmpty(animClipName))
            {
                if (clips != null && clips.Length > 0)
                {
                    List <AnimationClip> clipsByName = new List <AnimationClip>();
                    string nameInClip = animClipName;

                    for (int i = 0; i < clips.Length; i++)
                    {
                        if (clips[i].name.Contains(nameInClip))
                        {
                            clipsByName.Add(clips[i]);
                        }
                    }

                    if (clipsByName.Count > 0)
                    {
                        clips = clipsByName.ToArray();
                    }
                }
            }

                        #if UNITY_EDITOR_WIN
            // So we don't break in windows even though it worked before, only up to 999 because you need one more for New Clip
            System.Array.Resize(ref clips, 999);
                        #endif

            Array.Sort(clips, (AnimationClip clip1, AnimationClip clip2) => CurveUtility.GetClipName(clip1).CompareTo(CurveUtility.GetClipName(clip2)));

            return(clips);
        }
コード例 #4
0
        private GUIContent[] GetClipMenuContent(AnimationClip[] clips)
        {
            int size = clips.Length;

            if (state.selection.canCreateClips)
            {
                size += 2;
            }

            GUIContent[] content = new GUIContent[size];
            for (int i = 0; i < clips.Length; i++)
            {
                content[i] = new GUIContent(CurveUtility.GetClipName(clips[i]));
            }

            if (state.selection.canCreateClips)
            {
                content[content.Length - 2] = GUIContent.none;
                content[content.Length - 1] = AnimationWindowStyles.createNewClip;
            }

            return(content);
        }
コード例 #5
0
        public void OnGUI()
        {
            // Check for the animation clip name and create array of clips based on name
            animClipName = EditorGUILayout.TextField("Animation Clip Name:", animClipName, GUILayout.Width(300));

            if (state.selection.canChangeAnimationClip)
            {
                EditorGUI.BeginChangeCheck();

                var newClip = DoClipPopup(state.activeAnimationClip, AnimationWindowStyles.animClipToolbarPopup);
                if (EditorGUI.EndChangeCheck())
                {
                    state.activeAnimationClip = newClip;

                    //  Layout has changed, bail out now.
                    EditorGUIUtility.ExitGUI();
                }
            }
            else if (state.activeAnimationClip != null)
            {
                Rect r = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, AnimationWindowStyles.toolbarLabel);
                EditorGUI.LabelField(r, CurveUtility.GetClipName(state.activeAnimationClip), AnimationWindowStyles.toolbarLabel);
            }
        }