示例#1
0
 public void Add(string id, string path, float delay, string into, params int[] frames)
 {
     this.animations[id] = new Animation()
     {
         Delay  = delay,
         Frames = this.GetFrames(path, frames),
         Goto   = Chooser <string> .FromString <string>(into)
     };
 }
示例#2
0
 public void Add(string id, float delay, string into, params MTexture[] frames)
 {
     this.animations[id] = new Animation()
     {
         Delay  = delay,
         Frames = frames,
         Goto   = Chooser <string> .FromString <string>(into)
     };
 }
示例#3
0
        //public UnitSprite Create()
        //{
        //    return this.Sprite.CreateClone();
        //}

        //public UnitSprite CreateOn(UnitSprite sprite)
        //{
        //    return this.Sprite.CloneInto(sprite);
        //}

        //包装sprite数据
        public void WrapUnitSprite(UnitSprite sprite)
        {
            foreach (var spriteDataSource in Sources)
            {
                HashSet <string> ids = new HashSet <string>();
                foreach (XmlElement xml1 in spriteDataSource.XML.GetElementsByTagName("Anim"))
                {
                    this.CheckAnimXML(xml1, spriteDataSource.prefix, ids);
                }
                foreach (XmlElement xml1 in spriteDataSource.XML.GetElementsByTagName("Loop"))
                {
                    this.CheckAnimXML(xml1, spriteDataSource.prefix, ids);
                }
                if (spriteDataSource.XML.HasAttr("start") && !ids.Contains(spriteDataSource.XML.Attr("start")))
                {
                    throw new Exception(spriteDataSource.prefix + "starting animation '" + spriteDataSource.XML.Attr("start") + "' is missing!");
                }
                if (spriteDataSource.XML.HasChild("Justify") && spriteDataSource.XML.HasChild("Origin"))
                {
                    throw new Exception(spriteDataSource.prefix + "has both Origin and Justify tags!");
                }
                string str1         = spriteDataSource.XML.Attr("path", "");
                float  defaultValue = spriteDataSource.XML.AttrFloat("delay", 0.0f);
                foreach (XmlElement xml1 in spriteDataSource.XML.GetElementsByTagName("Anim"))
                {
                    Chooser <string> into = !xml1.HasAttr("goto") ? (Chooser <string>)null : Chooser <string> .FromString <string>(xml1.Attr("goto"));

                    string id     = xml1.Attr("id");
                    string str2   = xml1.Attr("path", "");
                    int[]  frames = Util.ReadCSVIntWithTricks(xml1.Attr("frames", ""));
                    string path   = string.IsNullOrEmpty(spriteDataSource.OverridePath) || !this.HasFrames(this.Atlas, spriteDataSource.OverridePath + str2, frames) ? str1 + str2 : spriteDataSource.OverridePath + str2;
                    sprite.Add(id, path, xml1.AttrFloat("delay", defaultValue), into, frames);
                }
                foreach (XmlElement xml1 in spriteDataSource.XML.GetElementsByTagName("Loop"))
                {
                    string id     = xml1.Attr("id");
                    string str2   = xml1.Attr("path", "");
                    int[]  frames = Util.ReadCSVIntWithTricks(xml1.Attr("frames", ""));
                    string path   = string.IsNullOrEmpty(spriteDataSource.OverridePath) || !this.HasFrames(this.Atlas, spriteDataSource.OverridePath + str2, frames) ? str1 + str2 : spriteDataSource.OverridePath + str2;
                    sprite.AddLoop(id, path, xml1.AttrFloat("delay", defaultValue), frames);
                }
                if (spriteDataSource.XML.HasChild("Center"))
                {
                    sprite.CenterOrigin();
                    sprite.Justify = new Vector2?(new Vector2(0.5f, 0.5f));
                }
                else if (spriteDataSource.XML.HasChild("Justify"))
                {
                    sprite.JustifyOrigin(spriteDataSource.XML.ChildPosition("Justify"));
                    sprite.Justify = new Vector2?(spriteDataSource.XML.ChildPosition("Justify"));
                }
                else if (spriteDataSource.XML.HasChild("Origin"))
                {
                    sprite.Origin = spriteDataSource.XML.ChildPosition("Origin");
                }
                if (spriteDataSource.XML.HasChild("Position"))
                {
                    sprite.Position = spriteDataSource.XML.ChildPosition("Position");
                }
                if (spriteDataSource.XML.HasAttr("start"))
                {
                    sprite.Play(spriteDataSource.XML.Attr("start"), false, false);
                }
            }
        }