• NGUI 制作动态图集


    List<Texture2Dtextures=new List<Texture2D>();
            List<UIAtlas.Spritesprits = new List<UIAtlas.Sprite> ();

            for (int i=batch*batchQuantityi<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(20482048);
                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=0i<rects.Length ; ++i)
                {
                    rects[i]=NGUIMath.ConvertToPixels(rects[i], atlas.widthatlas.heighttrue);
                    sprits[i].inner=rects[i];
                    sprits[i].outer=rects[i];
                    //Logger.log(rects[i]);
                }


                Material mat = new Material("atlasMat"+batch.ToString());
                mat.shaderShader.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 (batchnewAtlas);
                batchCompleted.Add (batch);
                batchProcessing.Remove (batch);
            }
            else{
                batchProcessing.Remove (batch);
                Logger.log("picture download failed " +batch.ToString());
            }

  • 相关阅读:
    第四次作业
    第三次作业
    作业,11
    作业,10
    作业,9
    作业,8
    作业,7
    作业,6
    作业,5
    作业,4
  • 原文地址:https://www.cnblogs.com/qqqeeebbb/p/3549535.html
Copyright © 2020-2023  润新知