コード例 #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);
        }
コード例 #2
0
        private static void AddSpriteAnimationToClip(AnimationClip newClip, UnityEngine.Object[] frames)
        {
            newClip.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 / newClip.frameRate;
            }
            EditorCurveBinding binding = EditorCurveBinding.PPtrCurve("", typeof(SpriteRenderer), "m_Sprite");

            AnimationUtility.SetObjectReferenceCurve(newClip, binding, array);
        }
コード例 #3
0
        private static void AddSpriteAnimationToClip(AnimationClip newClip, UnityEngine.Object[] frames)
        {
            newClip.frameRate = 12f;
            ObjectReferenceKeyframe[] keyframes = new ObjectReferenceKeyframe[frames.Length];
            for (int index = 0; index < keyframes.Length; ++index)
            {
                keyframes[index]       = new ObjectReferenceKeyframe();
                keyframes[index].value = (UnityEngine.Object)SpriteUtility.RemapObjectToSprite(frames[index]);
                keyframes[index].time  = (float)index / newClip.frameRate;
            }
            EditorCurveBinding binding = EditorCurveBinding.PPtrCurve(string.Empty, typeof(SpriteRenderer), "m_Sprite");

            AnimationUtility.SetObjectReferenceCurve(newClip, binding, keyframes);
        }