Ejemplo n.º 1
0
        public CachedSpriteInformation GetSprite(uint spriteId)
        {
            var cachedInformation = FindCachedInformation(spriteId);

            if (cachedInformation != null)
            {
                return(cachedInformation);
            }

            string    filename;
            Rect      spriteRect;
            Vector2   realSize;
            Texture2D tex2D;

            if (!GetSpriteInfo(spriteId, out filename, out spriteRect, out realSize, out tex2D))
            {
                return(null);
            }

            cachedInformation            = new CachedSpriteInformation();
            cachedInformation.id         = spriteId;
            cachedInformation.rect       = spriteRect;
            cachedInformation.spriteSize = realSize;
            cachedInformation.texture    = tex2D;

            BinaryInsert(cachedInformation);
            return(cachedInformation);
        }
Ejemplo n.º 2
0
        private void BinaryInsert(CachedSpriteInformation cachedInformation)
        {
            int index     = 0;
            int lastIndex = _spriteCachedInformation.Count - 1;

            while (index <= lastIndex)
            {
                int tmpIndex   = index + lastIndex >> 1;
                var foundCache = _spriteCachedInformation[tmpIndex];
                if (foundCache.id < cachedInformation.id)
                {
                    index = tmpIndex + 1;
                }
                else if (foundCache.id > cachedInformation.id)
                {
                    lastIndex = tmpIndex - 1;
                }
                else
                {
                    return;
                }
            }

            _spriteCachedInformation.Insert(index, cachedInformation);
        }
Ejemplo n.º 3
0
        public CachedSpriteInformation GetSprite(uint spriteID)
        {
            CachedSpriteInformation cachedInformation = FindCachedInformation(spriteID);

            if (cachedInformation != null)
            {
                return(cachedInformation);
            }

            string  filename;
            Rect    spriteRect;
            Vector2 realSize;

            if (!GetSpriteInfo(spriteID, out filename, out spriteRect, out realSize))
            {
                return(null);
            }


            Texture2D tex2D;

            if (!m_CachedTextures.TryGetValue(filename, out tex2D))
            {
                tex2D = LoadTexture(filename);
            }

            if (tex2D == null)
            {
                return(null);
            }

            cachedInformation            = new CachedSpriteInformation();
            cachedInformation.id         = spriteID;
            cachedInformation.rect       = spriteRect;
            cachedInformation.spriteSize = realSize;
            cachedInformation.texture    = tex2D;

            BinaryInsert(cachedInformation);
            return(cachedInformation);
        }