zoukankan      html  css  js  c++  java
  • 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());
            }

  • 相关阅读:
    Python 必备神器
    python 常用库
    Sublime Text3 配置 Python2 Python3
    Python JSON
    Sublime Text3 3143 注册码
    EFCode First 导航属性
    EF Code First:实体映射,数据迁移,重构(1)
    Entity Framework 复杂类型
    EF 7 Code First
    EF Code First 导航属性 与外键
  • 原文地址:https://www.cnblogs.com/qqqeeebbb/p/3549535.html
Copyright © 2011-2022 走看看