Beispiel #1
0
        public static AnimationClip CreateAnimationClip(DBAnimation dataAnimation, List <Object> animSprites,
                                                        string animationClipsDestination, int framerate, DetailedTextureInfo data)
        {
            var animationClipName = string.Format("{0}/{1}_{2}{3}",
                                                  DataLoader.GetProjectPathFromFullPath(animationClipsDestination), data.FileName, dataAnimation.NewName, ".anim");

            var origClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(animationClipName);


            var animationClip = origClip ?? new AnimationClip();

            animationClip.name      = dataAnimation.NewName;
            animationClip.frameRate = framerate;
            EditorCurveBinding curveBinding = new EditorCurveBinding
            {
                // I want to change the sprites of the sprite renderer, so I put the typeof(SpriteRenderer) as the binding type.
                type = typeof(SpriteRenderer),
                // Regular path to the gameobject that will be changed (empty string means root)
                path = "",
                // This is the property name to change the sprite of a sprite renderer

                propertyName = "m_Sprite"
            };
            var keyFrames = new List <ObjectReferenceKeyframe>();

            for (int j = 0; j < animSprites.Count; j++)
            {
                var frame = new ObjectReferenceKeyframe
                {
                    value = animSprites[j],
                    time  = j / animationClip.frameRate
                };
                keyFrames.Add(frame);
            }

            AnimationUtility.SetAnimationClipSettings(animationClip, new AnimationClipSettings
            {
                loopTime = true
            });

            AnimationUtility.SetObjectReferenceCurve(animationClip, curveBinding, keyFrames.ToArray());

            if (origClip == null)
            {
                AssetDatabase.CreateAsset(animationClip, animationClipName);
            }

            AssetDatabase.SaveAssets();
            return(animationClip);
        }
Beispiel #2
0
        private static List <DBAnimation> ExtractAnimations(SubTexture[] rawSubTexture)
        {
            var ret = new List <DBAnimation>();

            foreach (var t in rawSubTexture)
            {
                var animName = ExtractAnimName(t.name);

                var anim = ret.FirstOrDefault(r => r.Name == animName);

                if (anim == null)
                {
                    anim = new DBAnimation
                    {
                        Name = animName
                    };
                    ret.Add(anim);
                }

                anim.Sprites.Add(t);
            }

            return(ret);
        }