Пример #1
0
 public Anim Copy(Sprite _parent)
 {
     Anim anim = new Anim(_parent);
     anim.fps = fps;
     anim.size = size;
     foreach (var f in frames)
     {
         anim.frames.Add(f.Copy());
     }
     return anim;
 }
Пример #2
0
        public static SpriteAni CreateAni(Anim data,string aniname)
        {
            SpriteAni ani = new SpriteAni();
            ani.fps = data.fps;
            while (ani.frames.Count < data.frames.Count)
            {
                ani.frames.Add(new DrawFrame(data.size, ani.frames.Count,aniname));
            }
            int lastframe = 0;

            for (int i = 0; i < data.frames.Count; i++)
            {
                //while (ani.frames[i].drawElements.Count < data.frames[i].elems.Count)
                //{
                //    ani.frames[i].drawElements.Add(new DrawElement());
                //}
                #region fill frame
                for (int j = data.frames[i].elems.Count - 1; j >= 0; j--)
                {
                    if (string.IsNullOrEmpty(data.frames[i].elems[j].seednow))
                        continue;
                    //DrawElement e = new DrawElement();

                    //在这里要反转层顺序
                    Element se = data.frames[i].elems[j];
                    if(string.IsNullOrEmpty(se.sound)==false)
                    {
                        ani.frames[i].sounds.Add(System.IO.Path.GetFileNameWithoutExtension(se.sound));
                    }

                    //e.Fill(data, se);
                    bool e_isdummy = (se.tag.IndexOf("dummy:") == 0);
                    if (e_isdummy == true || string.IsNullOrEmpty(se.seedasdummy) == false)
                    {
                        Dummy dm = new Dummy();
                        dm.pos = se.pos;
                        dm.rotate = se.rotate;

                        if (string.IsNullOrEmpty(se.seedasdummy) == false)
                            dm.name = se.seedasdummy;
                        else
                            dm.name = se.tag.Substring(6);
                        ani.frames[i].dummys.Add(dm);
                    }
                    if(!e_isdummy)
                    {
                        Rect e_bounds = Calc_Bound(data, se);
                        //ani.frames[i].drawElements.Add(e);

                        string tag = "";
                        if (string.IsNullOrEmpty(se.tag) == false)
                        {
                            tag = se.tag;
                        }
                        else
                        {
                            tag = "";
                        }
                        if (tag != "")
                        {
                            if (ani.frames[i].bounds.ContainsKey("") == false)
                            {
                                ani.frames[i].bounds[""] = e_bounds;
                            }
                            else
                            {
                                Rect src = ani.frames[i].bounds[""];
                                ani.frames[i].bounds[""] = Rect_Union(src, e_bounds);
                            }
                        }
                        if (ani.frames[i].bounds.ContainsKey(tag) == false)
                        {
                            ani.frames[i].bounds[tag] = e_bounds;
                        }
                        else
                        {
                            Rect src = ani.frames[i].bounds[tag];
                            ani.frames[i].bounds[tag] = Rect_Union(src, e_bounds);
                        }
                    }
                }
                #endregion
                if (i == 0 && data.frames[0].frametags.Count == 0)
                {
                    ani.elements["in"] = new AniElement(ani, 0, data.frames.Count - 1, false);
                }
                if (i == data.frames.Count - 1 && data.frames[i].frametags.Count == 0 && lastframe > 0)
                {
                    ani.elements["out"] = new AniElement(ani, lastframe + 1, data.frames.Count - 1, false);
                }
                if (data.frames[i].frametags.Count > 0)
                {
                    lastframe = i;
                    if (ani.elements.ContainsKey("in"))
                    {
                        if (ani.elements["in"].frameend == data.frames.Count - 1)
                        {
                            ani.elements["in"].frameend = i - 1;
                            ani.elements["in"].FixLife();
                        }
                    }
                }
                foreach (var tag in data.frames[i].frametags)
                {

                    if (ani.elements.ContainsKey(tag))
                    {
                        ani.elements[tag].frameend = i;
                        ani.elements[tag].FixLife();
                    }
                    else
                    {
                        ani.elements[tag] = new AniElement(ani, i, i, true);

                    }
                }

            }
            string[] ttags = new string[ani.framecount];
            foreach (var e in ani.elements)
            {
                for (int i = e.Value.framestart; i <= e.Value.frameend; i++)
                {
                    ttags[i] = e.Key;
                }
            }
            string begintag = "";
            int begini = 0;
            for (int i = 0; i < ani.framecount; i++)
            {
                if (string.IsNullOrEmpty(ttags[i]) == false)
                {
                    if (begintag != ttags[i])
                    {
                        if (begintag == "")
                        {

                        }
                        else
                        {
                            string endtag = ttags[i];
                            if (begini + 1 <= i - 1)
                                ani.elements[begintag + "-" + endtag] = new AniElement(ani, begini + 1, i - 1, false);
                        }
                    }
                    begintag = ttags[i];
                    begini = i;
                }

            }
            ani.allelement = new AniElement(ani, 0, ani.framecount - 1, true);
            return ani;
        }
Пример #3
0
    KAnim.Anim GetAnim(string aniname)
    {
        //Debug.Log("GetAnim:" + aniname);
            if (dataK == null)
                return null;

            aniname = aniname.Replace('\\', '/');
            if (dataK.anims.ContainsKey(aniname) == false)
            {
                var anis = Resources.Load(aniname, typeof(TextAsset)) as TextAsset;
                if (anis == null)
                {
                    //Debug.Log("GetAnim Fail:" + aniname);
                    return null;
                }
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(anis.bytes))
                {
                    KAnim.Anim anim = new KAnim.Anim(dataK);
                    anim.Read(ms);
                    dataK.anims[aniname] = anim;
                }

            }

            if (dataK.anims.ContainsKey(aniname) == false)
            {
                Debug.Log("GetAnim Fail:" + aniname);
                return null;
            }
            return dataK.anims[aniname];
    }