NGUI 制作动态图集

List<Texture2D> textures=new List<Texture2D>();
        List<UIAtlas.Sprite> sprits = new List<UIAtlas.Sprite> ();

        for (int i=batch*batchQuantity; i<batchQuantity*(batch+1); ++i) {

            if(i==itemGos.Count)
            {
                Logger.log("i = "+i+" itemGos = "+itemGos.Count);

                break;
            }

            UIFriendItem fi=itemGos[i].GetComponent<UIFriendItem>();
            string tempUrl=facebookGraphURL+"/"+fi.firendId+"/picture?access_token="+FacebookCenter.instance.GetAccessToken();
            if(WebTextureCache.InstantiateGlobal().ImageCache.ContainsKey(tempUrl))
            {
                if(WebTextureCache.InstantiateGlobal().ImageCache[tempUrl].width==50)
                {
                    textures.Add(WebTextureCache.InstantiateGlobal().ImageCache[tempUrl]);
                    UIAtlas.Sprite sp = new UIAtlas.Sprite ();
                    sp.name=fi.firendId;
                    sprits.Add(sp);
                }
            }

        }

        //
        if(textures.Count>0)
        {
            textures.Add((Texture2D)Resources.Load("Others/photoFrame"));
            UIAtlas.Sprite sp = new UIAtlas.Sprite ();
            sp.name="photoFrame";
            sprits.Add(sp);
            ///------------
            Texture2D atlas = new Texture2D(2048, 2048);
            Rect[] rects;
            rects = atlas.PackTextures ((Texture2D[])textures.ToArray (),0,2048);
            Logger.log("the length is + "+rects.Length);

            if (rects.Length != sprits.Count) {
                Logger.log("error!! length not match ");
                    }

            for(int i=0; i<rects.Length ; ++i)
            {
                rects[i]=NGUIMath.ConvertToPixels(rects[i], atlas.width, atlas.height, true);
                sprits[i].inner=rects[i];
                sprits[i].outer=rects[i];
                //Logger.log(rects[i]);
            }


            Material mat = new Material("atlasMat"+batch.ToString());
            mat.shader= Shader.Find("Unlit/Transparent Colored");
            if (mat.shader == null) {
                Logger.logError("shader is null");
                }
            mat.mainTexture=atlas;

            var gameobject = new GameObject ("atlasBatch"+batch.ToString());
            UIAtlas newAtlas=gameobject.AddComponent<UIAtlas> ();
            newAtlas.spriteList = sprits;
            newAtlas.spriteMaterial = mat;
            //newAtlas.coordinates = UIAtlas.Coordinates.TexCoords;

            Logger.log("successfully build atlas for batch " +batch.ToString());
            //Logger.log(newAtlas.spriteMaterial.ToString());


            createdAtlas.Add (batch, newAtlas);
            batchCompleted.Add (batch);
            batchProcessing.Remove (batch);
        }
        else{
            batchProcessing.Remove (batch);
            Logger.log("picture download failed " +batch.ToString());
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值