Exemplo n.º 1
0
 void UpdateCacheOverridesIfNeeded()
 {
     if (m_CategoryEntryCache == null || m_PreviousSpriteLibraryAsset != m_SpriteLibraryAsset?.GetInstanceID())
     {
         CacheOverrides();
     }
 }
Exemplo n.º 2
0
        internal void CacheOverrides()
        {
            m_PreviousSpriteLibraryAsset = 0;
            m_PreviousModificationHash   = 0;
            m_CategoryEntryHashCache     = new Dictionary <int, CategoryEntrySprite>();
            m_CategoryEntryCache         = new Dictionary <string, HashSet <string> >();
            if (m_SpriteLibraryAsset)
            {
                m_PreviousSpriteLibraryAsset = m_SpriteLibraryAsset.GetInstanceID();
                m_PreviousModificationHash   = m_SpriteLibraryAsset.modificationHash;
                foreach (var category in m_SpriteLibraryAsset.categories)
                {
                    var catName = category.name;
                    m_CategoryEntryCache.Add(catName, new HashSet <string>());
                    var cacheEntryName = m_CategoryEntryCache[catName];
                    foreach (var entry in category.categoryList)
                    {
                        m_CategoryEntryHashCache.Add(GetHashForCategoryAndEntry(catName, entry.name), new CategoryEntrySprite()
                        {
                            category = catName,
                            entry    = entry.name,
                            sprite   = entry.sprite
                        });
                        cacheEntryName.Add(entry.name);
                    }
                }
            }

            foreach (var category in m_Library)
            {
                var catName = category.name;
                if (!m_CategoryEntryCache.ContainsKey(catName))
                {
                    m_CategoryEntryCache.Add(catName, new HashSet <string>());
                }
                var cacheEntryName = m_CategoryEntryCache[catName];

                foreach (var ent in category.categoryList)
                {
                    if (!cacheEntryName.Contains(ent.name))
                    {
                        cacheEntryName.Add(ent.name);
                    }

                    var hash = GetHashForCategoryAndEntry(catName, ent.name);
                    if (!m_CategoryEntryHashCache.ContainsKey(hash))
                    {
                        m_CategoryEntryHashCache.Add(hash, new CategoryEntrySprite()
                        {
                            category = catName,
                            entry    = ent.name,
                            sprite   = ent.sprite
                        });
                    }
                    else
                    {
                        var e = m_CategoryEntryHashCache[hash];
                        e.sprite = ent.sprite;
                        m_CategoryEntryHashCache[hash] = e;
                    }
                }
            }
        }