public void OnGUI()
        {
            if (state.selection.canChangeAnimationClip)
            {
                var newClip = DoClipPopup(state.activeAnimationClip, AnimationWindowStyles.animClipToolbarPopup);
                if (state.selection.canCreateClips)
                {
                    addCI.SetSourceView();
                    if (GUILayout.Button(new GUIContent("+", "Create New Clip..."), EditorStyles.toolbarButton))
                    {
                        newClip = AnimationWindowUtility.CreateNewClip(state.selection.rootGameObject.name);
                        if (newClip)
                        {
                            AnimationWindowUtility.AddClipToAnimationPlayerComponent(state.activeAnimationPlayer, newClip);
                            addCI.selectedClip = newClip;
                            addCI.SendEvent();
                        }
                    }
                }
                if (state.activeAnimationClip != newClip)
                {
                    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);
            }
        }
        private void DisplayClipMenu(Rect position, int controlID, AnimationClip clip)
        {
            AnimationClip[] clips       = GetOrderedClipList();
            GUIContent[]    menuContent = GetClipMenuContent(clips);
            int             selected    = ClipToIndex(clips, clip);

            // Center popup menu around button widget
            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                position.y = position.y - selected * EditorGUI.kSingleLineHeight - kMenuOffsetMac;
            }

            ClipPopupCallbackInfo.instance = new ClipPopupCallbackInfo(controlID);

            EditorUtility.DisplayCustomMenu(position, menuContent, null, selected, (userData, options, index) =>
            {
                if (index < clips.Length)
                {
                    ClipPopupCallbackInfo.SetSelectedClip(clips[index]);
                }
                else
                {
                    AnimationClip newClip = AnimationWindowUtility.CreateNewClip(state.selection.rootGameObject.name);
                    if (newClip)
                    {
                        AnimationWindowUtility.AddClipToAnimationPlayerComponent(state.activeAnimationPlayer, newClip);
                        ClipPopupCallbackInfo.SetSelectedClip(newClip);
                    }
                }

                ClipPopupCallbackInfo.SendEvent();
            }, null);
        }
        public void OnGUI()
        {
            AnimationWindowSelectionItem selectedItem = this.state.selectedItem;

            if (!(selectedItem == null) && selectedItem.canChangeAnimationClip)
            {
                string[] clipMenuContent = this.GetClipMenuContent();
                EditorGUI.BeginChangeCheck();
                this.selectedIndex = EditorGUILayout.Popup(this.ClipToIndex(this.state.activeAnimationClip), clipMenuContent, EditorStyles.toolbarPopup, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    if (clipMenuContent[this.selectedIndex] == AnimationWindowStyles.createNewClip.text)
                    {
                        AnimationClip animationClip = AnimationWindowUtility.CreateNewClip(selectedItem.rootGameObject.name);
                        if (animationClip)
                        {
                            AnimationWindowUtility.AddClipToAnimationPlayerComponent(this.state.activeAnimationPlayer, animationClip);
                            this.state.selection.UpdateClip(this.state.selectedItem, animationClip);
                            this.state.currentTime = 0f;
                            this.state.ResampleAnimation();
                            GUIUtility.ExitGUI();
                        }
                    }
                    else
                    {
                        this.state.selection.UpdateClip(this.state.selectedItem, this.IndexToClip(this.selectedIndex));
                        this.state.currentTime = 0f;
                        this.state.ResampleAnimation();
                    }
                }
            }
        }
 public void OnGUI()
 {
     if (this.state.selection.canChangeAnimationClip)
     {
         string[] clipMenuContent = this.GetClipMenuContent();
         EditorGUI.BeginChangeCheck();
         this.selectedIndex = EditorGUILayout.Popup(this.ClipToIndex(this.state.activeAnimationClip), clipMenuContent, EditorStyles.toolbarPopup, new GUILayoutOption[0]);
         if (EditorGUI.EndChangeCheck())
         {
             if (clipMenuContent[this.selectedIndex] == AnimationWindowStyles.createNewClip.text)
             {
                 AnimationClip animationClip = AnimationWindowUtility.CreateNewClip(this.state.selection.rootGameObject.name);
                 if (animationClip)
                 {
                     AnimationWindowUtility.AddClipToAnimationPlayerComponent(this.state.activeAnimationPlayer, animationClip);
                     this.state.activeAnimationClip = animationClip;
                 }
                 GUIUtility.ExitGUI();
             }
             else
             {
                 this.state.activeAnimationClip = this.IndexToClip(this.selectedIndex);
             }
         }
     }
     else if (this.state.activeAnimationClip != null)
     {
         Rect controlRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, AnimationWindowStyles.toolbarLabel, new GUILayoutOption[0]);
         EditorGUI.LabelField(controlRect, CurveUtility.GetClipName(this.state.activeAnimationClip), AnimationWindowStyles.toolbarLabel);
     }
 }
        public void OnGUI()
        {
            if (state.selection.canChangeAnimationClip)
            {
                string[] menuContent = GetClipMenuContent();
                EditorGUI.BeginChangeCheck();
                // TODO: Make this more robust
                selectedIndex = EditorGUILayout.Popup(ClipToIndex(state.activeAnimationClip), menuContent, EditorStyles.toolbarPopup);
                if (EditorGUI.EndChangeCheck())
                {
                    if (menuContent[selectedIndex] == AnimationWindowStyles.createNewClip.text)
                    {
                        AnimationClip newClip = AnimationWindowUtility.CreateNewClip(state.selection.rootGameObject.name);
                        if (newClip)
                        {
                            AnimationWindowUtility.AddClipToAnimationPlayerComponent(state.activeAnimationPlayer, newClip);
                            state.activeAnimationClip = newClip;
                        }

                        //  Layout has changed, bail out now.
                        EditorGUIUtility.ExitGUI();
                    }
                    else
                    {
                        state.activeAnimationClip = IndexToClip(selectedIndex);
                    }
                }
            }
            else if (state.activeAnimationClip != null)
            {
                Rect r = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, AnimationWindowStyles.toolbarLabel);
                EditorGUI.LabelField(r, CurveUtility.GetClipName(state.activeAnimationClip), AnimationWindowStyles.toolbarLabel);
            }
        }
Ejemplo n.º 6
0
        private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames)
        {
            Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name));
            bool result;

            if (!AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject))
            {
                result = false;
            }
            else
            {
                Animator closestAnimatorInParents = AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform);
                if (closestAnimatorInParents == null)
                {
                    result = false;
                }
                else
                {
                    AnimationClip animationClip = AnimationWindowUtility.CreateNewClip(gameObject.name);
                    if (animationClip == null)
                    {
                        result = false;
                    }
                    else
                    {
                        SpriteUtility.AddSpriteAnimationToClip(animationClip, frames);
                        result = AnimationWindowUtility.AddClipToAnimatorComponent(closestAnimatorInParents, animationClip);
                    }
                }
            }
            return(result);
        }
 public void OnGUI()
 {
     string[] clipMenuContent = this.GetClipMenuContent();
     EditorGUI.BeginChangeCheck();
     this.selectedIndex = EditorGUILayout.Popup(this.ClipToIndex(this.state.activeAnimationClip), clipMenuContent, EditorStyles.toolbarPopup, new GUILayoutOption[0]);
     if (EditorGUI.EndChangeCheck())
     {
         if (clipMenuContent[this.selectedIndex] == AnimationWindowStyles.createNewClip.text)
         {
             AnimationClip animationClip = AnimationWindowUtility.CreateNewClip(this.state.activeRootGameObject.name);
             if (animationClip)
             {
                 AnimationWindowUtility.AddClipToAnimationPlayerComponent(this.state.activeAnimationPlayer, animationClip);
                 this.state.activeAnimationClip = animationClip;
             }
         }
         else
         {
             this.state.activeAnimationClip = this.IndexToClip(this.selectedIndex);
         }
     }
 }
Ejemplo n.º 8
0
        private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames)
        {
            Array.Sort <UnityEngine.Object>(frames, (Comparison <UnityEngine.Object>)((a, b) => EditorUtility.NaturalCompare(a.name, b.name)));
            if (!(bool)((UnityEngine.Object)AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject)))
            {
                return(false);
            }
            Animator animatorInParents = AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform);

            if ((UnityEngine.Object)animatorInParents == (UnityEngine.Object)null)
            {
                return(false);
            }
            AnimationClip newClip = AnimationWindowUtility.CreateNewClip(gameObject.name);

            if ((UnityEngine.Object)newClip == (UnityEngine.Object)null)
            {
                return(false);
            }
            SpriteUtility.AddSpriteAnimationToClip(newClip, frames);
            return(AnimationWindowUtility.AddClipToAnimatorComponent(animatorInParents, newClip));
        }