Exemplo n.º 1
0
        public void Register(Sprite3D sprite)
        {
            if (null == sprite || null == sprite.texture)
            {
                return;
            }
            int nativeTextureID = sprite.texture.GetNativeTextureID();

            sprite.m_textureGUID = nativeTextureID;
            AtlasInfo.UVDetail uVDetail = null;
            this.padding       = Mathf.Max(this.padding, sprite.padding);
            this.needCompress |= sprite.compress;
            if (this.textures.TryGetValue(nativeTextureID, out uVDetail))
            {
                this.sprites.Add(sprite);
                if (null != this.mat)
                {
                    sprite.SetMaterial(this.mat);
                }
                sprite.SetAutoAtlas(this.atlas, uVDetail);
                return;
            }
            uVDetail        = new AtlasInfo.UVDetail();
            uVDetail.width  = 0;
            uVDetail.height = 0;
            uVDetail.width  = sprite.texture.width;
            uVDetail.height = sprite.texture.height;
            uVDetail.rotate = false;
            this.textures.Add(nativeTextureID, uVDetail);
            this.waitForCombineTextures.Add(nativeTextureID, sprite.texture);
            this.needRebuildAtlas = true;
            this.sprites.Add(sprite);
        }
Exemplo n.º 2
0
 private void RefreshUVDetail()
 {
     if ((null != this.m_atlas) && (this.m_lastAtlasName != this.m_spriteName))
     {
         this.m_uv            = this.m_atlas.GetUV(this.m_spriteName);
         this.m_lastAtlasName = this.m_spriteName;
     }
 }
Exemplo n.º 3
0
 public void SetUV(AtlasInfo.UVDetail uv)
 {
     this.PrepareMesh();
     if (this.m_mesh == null || this.m_mesh.triangles.Length == 0 || this.m_uv == null || this.m_uv.uvBL != uv.uvBL || this.m_uv.uvBR != uv.uvBR || this.m_uv.uvTL != uv.uvTL || this.m_uv.uvTR != uv.uvTR)
     {
         this.m_propchanged = true;
     }
     this.m_uv = uv;
     this.RefreshAutoAtlasMaterial();
 }
Exemplo n.º 4
0
    public Sprite GenerateSprite()
    {
        Sprite result = null;

        if (this.m_atlas == null)
        {
            return(result);
        }
        AtlasInfo.UVDetail uV = this.m_atlas.GetUV(this.m_spriteName);
        if (uV == null)
        {
            return(result);
        }
        if (this.m_useAtlas)
        {
            result = Sprite.Create(this.m_atlas.texture, new Rect((float)uV.x, (float)(this.m_atlas.texture.height - uV.height), (float)uV.width, (float)uV.height), Vector2.zero);
        }
        else
        {
            result = Sprite.Create(this.m_texture, new Rect(0f, 0f, (float)this.m_texture.width, (float)this.m_texture.height), Vector2.zero);
        }
        return(result);
    }
Exemplo n.º 5
0
 public void SetAutoAtlas(Texture2D atlas, AtlasInfo.UVDetail uv)
 {
     this.m_texture = atlas;
     this.SetUV(uv);
 }
Exemplo n.º 6
0
        private bool Pack(int size)
        {
            int     num  = 0;
            int     num2 = 0;
            int     num3 = 0;
            int     num4 = this.padding;
            Vector2 zero = Vector2.zero;
            DictionaryView <int, AtlasInfo.UVDetail> dictionaryView = new DictionaryView <int, AtlasInfo.UVDetail>();

            DictionaryView <int, AtlasInfo.UVDetail> .Enumerator enumerator = this.textures.GetEnumerator();
            while (enumerator.MoveNext())
            {
                KeyValuePair <int, AtlasInfo.UVDetail> current = enumerator.Current;
                int width = current.get_Value().width;
                KeyValuePair <int, AtlasInfo.UVDetail> current2 = enumerator.Current;
                int height = current2.get_Value().height;
                AtlasInfo.UVDetail uVDetail = new AtlasInfo.UVDetail();
                uVDetail.rotate = false;
                DictionaryView <int, AtlasInfo.UVDetail> dictionaryView2 = dictionaryView;
                KeyValuePair <int, AtlasInfo.UVDetail>   current3        = enumerator.Current;
                dictionaryView2.Add(current3.get_Key(), uVDetail);
                if (num3 + height + num4 <= size && num2 + width + num4 <= size)
                {
                    uVDetail.x      = num2;
                    uVDetail.y      = num3;
                    uVDetail.width  = width;
                    uVDetail.height = height;
                    num3           += height + num4;
                    if (num < num2 + width + num4)
                    {
                        num = num2 + width + num4;
                    }
                }
                else
                {
                    if (num + width > size || height > size)
                    {
                        return(false);
                    }
                    num2            = num;
                    uVDetail.x      = num2;
                    uVDetail.y      = 0;
                    uVDetail.width  = width;
                    uVDetail.height = height;
                    num3            = height + num4;
                    num             = num2 + width + num4;
                }
            }
            TextureFormat textureFormat = TextureFormat.ARGB32;

            if (this.needCompress)
            {
                textureFormat = TextureFormat.ARGB32;
            }
            Texture2D texture2D = new Texture2D(size, size, textureFormat, false);

            Color[] pixels = new Color[texture2D.width * texture2D.height];
            texture2D.SetPixels(pixels);
            texture2D.name = string.Concat(new object[]
            {
                "Auto_UI3D_Atlas_",
                size,
                "_",
                this.counter,
                "_format",
                textureFormat.ToString()
            });
            this.counter++;
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                Texture2D texture2D2 = null;
                Dictionary <int, Texture2D>            dictionary = this.waitForCombineTextures;
                KeyValuePair <int, AtlasInfo.UVDetail> current4   = enumerator.Current;
                if (!dictionary.TryGetValue(current4.get_Key(), ref texture2D2))
                {
                    texture2D2 = this.atlas;
                }
                KeyValuePair <int, AtlasInfo.UVDetail> current5 = enumerator.Current;
                AtlasInfo.UVDetail value = current5.get_Value();
                DictionaryView <int, AtlasInfo.UVDetail> dictionaryView3 = dictionaryView;
                KeyValuePair <int, AtlasInfo.UVDetail>   current6        = enumerator.Current;
                AtlasInfo.UVDetail uVDetail2 = dictionaryView3[current6.get_Key()];
                Color[]            pixels2   = texture2D2.GetPixels(value.x, value.y, value.width, value.height);
                texture2D.SetPixels(uVDetail2.x, uVDetail2.y, value.width, value.height, pixels2);
                texture2D.Apply(false, false);
                uVDetail2.uvTL = new Vector2((float)uVDetail2.x / (float)texture2D.width, (float)(uVDetail2.y + uVDetail2.height) / (float)texture2D.height);
                uVDetail2.uvTR = new Vector2((float)(uVDetail2.x + uVDetail2.width) / (float)texture2D.width, (float)(uVDetail2.y + uVDetail2.height) / (float)texture2D.height);
                uVDetail2.uvBL = new Vector2((float)uVDetail2.x / (float)texture2D.width, (float)uVDetail2.y / (float)texture2D.height);
                uVDetail2.uvBR = new Vector2((float)(uVDetail2.x + uVDetail2.width) / (float)texture2D.width, (float)uVDetail2.y / (float)texture2D.height);
            }
            this.textures = dictionaryView;
            Object.Destroy(this.atlas);
            this.atlas = texture2D;
            Shader shader = Singleton <CResourceManager> .GetInstance().GetResource("Shaders/UI/UI3D.shader", typeof(Shader), enResourceType.BattleScene, true, true).m_content as Shader;

            this.mat = new Material(shader);
            this.mat.SetTexture("_MainTex", this.atlas);
            HashSet <Sprite3D> .Enumerator enumerator2 = this.sprites.GetEnumerator();
            while (enumerator2.MoveNext())
            {
                enumerator2.get_Current().SetMaterial(this.mat);
                enumerator2.get_Current().SetAutoAtlas(this.atlas, this.textures[enumerator2.get_Current().m_textureGUID]);
            }
            Dictionary <int, Texture2D> .Enumerator enumerator3 = this.waitForCombineTextures.GetEnumerator();
            this.waitForCombineTextures.Clear();
            Singleton <CResourceManager> .GetInstance().UnloadUnusedAssets();

            return(true);
        }