Пример #1
0
        public SpriteData(Atlas atlas)
        {
            UnitSprite spritePrefab = Resources.Load <UnitSprite>("UnitSprite");

            //Sprite = GameObject.Instantiate<UnitSprite>(spritePrefab);
            //this.Sprite.Init(atlas, "");
            this.Atlas = atlas;
        }
Пример #2
0
 internal UnitSprite CloneInto(UnitSprite clone)
 {
     clone.Texture               = this.Texture;
     clone.Position              = this.Position;
     clone.Justify               = this.Justify;
     clone.Origin                = this.Origin;
     clone.animations            = new Dictionary <string, Animation>((IDictionary <string, Animation>) this.animations, (IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
     clone.currentAnimation      = this.currentAnimation;
     clone.animationTimer        = this.animationTimer;
     clone.width                 = this.width;
     clone.height                = this.height;
     clone.Animating             = this.Animating;
     clone.CurrentAnimationID    = this.CurrentAnimationID;
     clone.LastAnimationID       = this.LastAnimationID;
     clone.CurrentAnimationFrame = this.CurrentAnimationFrame;
     return(clone);
 }
Пример #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);
                }
            }
        }