Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        static bool CreateAnimation(GameObject gameObject, Object[] frames, ShowFileDialogDelegate saveFileDialog)
        {
            saveFileDialog = saveFileDialog ?? EditorUtility.SaveFilePanelInProject;

            // Use same name compare as when we sort in the backend: See AssetDatabase.cpp: SortChildren
            System.Array.Sort(frames, (a, b) => EditorUtility.NaturalCompare(a.name, b.name));

            Animator animator = AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject)
                ? AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform)
                : null;

            bool createSuccess = animator != null;

            if (animator != null)
            {
                // Go forward with presenting user a save clip dialog
                string message          = string.Format(SpriteUtilityStrings.saveAnimDialogMessage.text, gameObject.name);
                string newClipDirectory = ProjectWindowUtil.GetActiveFolderPath();
                string newClipPath      = saveFileDialog(SpriteUtilityStrings.saveAnimDialogTitle.text, SpriteUtilityStrings.saveAnimDialogName.text, "anim", message, newClipDirectory);

                if (string.IsNullOrEmpty(newClipPath))
                {
                    Undo.ClearUndo(animator);
                    Object.DestroyImmediate(animator);
                    return(false);
                }
                else
                {
                    AnimationClip newClip = AnimationWindowUtility.CreateNewClipAtPath(newClipPath);
                    if (newClip != null)
                    {
                        AddSpriteAnimationToClip(newClip, frames);
                        createSuccess = AnimationWindowUtility.AddClipToAnimatorComponent(animator, newClip);
                    }
                }
            }

            if (createSuccess == false)
            {
                Debug.LogError(SpriteUtilityStrings.failedToCreateAnimationError.text);
            }

            return(createSuccess);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames, SpriteUtility.ShowFileDialogDelegate saveFileDialog)
        {
            SpriteUtility.ShowFileDialogDelegate arg_26_0;
            if ((arg_26_0 = saveFileDialog) == null)
            {
                if (SpriteUtility.< > f__mg$cache1 == null)
                {
                    SpriteUtility.< > f__mg$cache1 = new SpriteUtility.ShowFileDialogDelegate(EditorUtility.SaveFilePanelInProject);
                }
                arg_26_0 = SpriteUtility.< > f__mg$cache1;
            }
            saveFileDialog = arg_26_0;
            Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name));
            Animator animator = (!AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject)) ? null : AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform);
            bool     flag     = animator != null;
            bool     result;

            if (animator != null)
            {
                string message          = string.Format(SpriteUtility.SpriteUtilityStrings.saveAnimDialogMessage.text, gameObject.name);
                string activeFolderPath = ProjectWindowUtil.GetActiveFolderPath();
                string text             = saveFileDialog(SpriteUtility.SpriteUtilityStrings.saveAnimDialogTitle.text, SpriteUtility.SpriteUtilityStrings.saveAnimDialogName.text, "anim", message, activeFolderPath);
                if (string.IsNullOrEmpty(text))
                {
                    UnityEngine.Object.DestroyImmediate(animator);
                    result = false;
                    return(result);
                }
                AnimationClip animationClip = AnimationWindowUtility.CreateNewClipAtPath(text);
                if (animationClip != null)
                {
                    SpriteUtility.AddSpriteAnimationToClip(animationClip, frames);
                    flag = AnimationWindowUtility.AddClipToAnimatorComponent(animator, animationClip);
                }
            }
            if (!flag)
            {
                Debug.LogError(SpriteUtility.SpriteUtilityStrings.failedToCreateAnimationError.text);
            }
            result = flag;
            return(result);
        }