Optimize texture usage with Texture Packer and Pixel Formats! Use a Dictionary to cache the loaded atlas by passing the key according to the path of the atlas, and then delete it from the outside when necessary. Just find a GameObject that will not be destroyed and bind it. A management class of atlas texture is written below to manage and load uniformly. unit圓d doesn't have a clear api for how we use this kind of atlas, but often Resources.Load() loading can only return a single image texture, so we use another method Resources.LoadAll() load the whole atlas, and this method will return an object, which contains the texture of the atlas Texture2D and all sprites in the atlas, so we can find a small picture we need according to the type and name of the object.ĥ. We also need to dynamically load the atlas in the program and use the small graphs in the atlas to be complete. At this time, we can only use the atlas in the editor.Ĥ. We just need to drag the small graph in the atlas into the Source Image just like using a single small graph.
Unity texturepacker code#
Next, you need to download and import a Unit圓d plug-in, a plug-in from TexturePacker Importer), plug-in link !/content/16641 After downloading and importing successfully, the plug-in will automatically cut the big drawing which has just been packed and put into the project into a small one according to.tpsheet without writing any code and doing any operation
![unity texturepacker unity texturepacker](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20190323/20190323120836.png)
Use the small picture in it (although you can use unit圓d's own function to manually crop the picture, the size of the cropped small picture is basically wrong)ģ. At this time, from the engineering point of view, this is only a large picture, not a atlas. Put these two files in the engineering resources. For details, please visit the following website Ģ. Pay attention to the format of "Unity - Texture2D sprite sheet" (there are some lower versions of TP that do not have this format). Pack small drawings into the atlas we need. The next part of this article is about unity 2018.2.5f1 (64 bit) and TexturePacker 5.2.0, the latest version Another familiar method is packaged with TexturePacker tool. There is another article about the first method for you. One is to use the external plug-in TexturePacker to package pictures and use them One is to use the system's own packaging tool sprite packer There are two ways to package and use the atlas in UGUI: When using UGUI, we also need to package small graphs into atlas to reduce Drawcall (like coco2d-x, package into atlas for one-time loading in exchange for image reading efficiency). We often hear that it is to package the atlas in NGUI. ③, loading or unloading multiple images at one time, improving the operation efficiency ②, pictures of different modules can be classified ①, reduce performance consumption and improve processing efficiency Obviously, this is very performance consuming.
![unity texturepacker unity texturepacker](https://pic3.zhimg.com/v2-2505b98bfa95a2317af8440af1a342c2_r.jpg)
![unity texturepacker unity texturepacker](https://pic1.zhimg.com/v2-23c501187e0c63f40ce232e0961e87e0_b.png)
In GPU, if we want to draw an image, we need to submit the image (texture) to display memory, and then draw it (in this process, a DrawCall will be generated), that is to say, if we want to draw 100 pictures, we need to generate 100 drawcalls. As we all know, CPU is used to process the logical operation of the game, while GPU is used to process the image in the game.