Exemplo 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));
            string message       = string.Format("Create a new animation for the game object '{0}':", gameObject.name);
            string directoryName = Path.GetDirectoryName(AssetDatabase.GetAssetPath(frames[0]));
            string text          = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, directoryName);

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(true);

            AssetDatabase.CreateAsset(animationClip, text);
            AnimationSelection.AddClipToAnimatorComponent(gameObject, animationClip);
            animationClip.frameRate = 12f;
            ObjectReferenceKeyframe[] array = new ObjectReferenceKeyframe[frames.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i]       = default(ObjectReferenceKeyframe);
                array[i].value = SpriteUtility.RemapObjectToSprite(frames[i]);
                array[i].time  = (float)i / animationClip.frameRate;
            }
            EditorCurveBinding binding = EditorCurveBinding.PPtrCurve(string.Empty, typeof(SpriteRenderer), "m_Sprite");

            AnimationUtility.SetObjectReferenceCurve(animationClip, binding, array);
            return(true);
        }
Exemplo n.º 2
0
        private AnimationClip CreateNewClip()
        {
            bool   flag    = this.animatedObject.GetComponent <Animator>() != null || this.animatedObject.GetComponent <Animation>() == null;
            string message = string.Format("Create a new animation for the game object '{0}':", this.animatedObject.name);
            string text    = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, ProjectWindowUtil.GetActiveFolderPath());

            if (text == string.Empty)
            {
                return(null);
            }
            AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(flag);

            AssetDatabase.CreateAsset(animationClip, text);
            this.m_AnimationWindow.EndAnimationMode();
            if (flag)
            {
                return(AnimationSelection.AddClipToAnimatorComponent(this.animatedObject, animationClip));
            }
            return(this.AddClipToAnimationComponent(animationClip));
        }