There are three main factors that determine the size of a texture resource: Resolution, format, and Mipmap are turned on.
The loading recommendations for texture resources are as follows:
1, strictly control the use of RGBA32 and ARGB32 texture, in the premise of ensuring the visual effect, as far as possible to use "good enough" principle, reduce the resolution of texture resources, and the use of hardware support texture format.
2, in the hardware format (ETC, PVRTC) can not meet the visual effects, RGBA16 format is a more ideal compromise choice, both to increase the visual effect, but also to maintain a low load time.
3, strictly check the mipmap function of texture resources, pay special attention to whether the UI texture mipmap open. Many of the project's UI textures turn on the mipmap feature, which not only creates a waste of memory consumption, but also increases the load time.
4. ETC2 is a good handling of translucent texture formats for Android mobile devices that support OpenGL ES3.0. However, if your game needs to run on a large number of OpenGL ES2.0 devices, we do not recommend using ETC2 format textures. Because it will not only cause a lot of memory consumption (ETC2 to RGBA32), but also add a certain load time. The following figure shows the performance of the test textures used in Test 2 on Samsung S3 and S4 devices. It can be seen that on OpenGL ES2.0 devices, the ETC2 format texture is loaded significantly higher than the ETC1 format and slightly above the RGBA16 format texture. Therefore, it is recommended that the development team carefully use the ETC2 format texture in the project.
Article loading module depth analysis of the use of the format of the image method is described in detail
batch detection and modification of texture format codes are as follows:
Using System;
Using System.Collections.Generic;
Using Unityeditor;
Using Unityengine;
Using System.IO; Public partial class Resourceexporter {static list<textureformatinfo> Getalltex (bool Bfilter, Checkplatformtex Format checkandroid, Checkplatformtexformat checkiphone, Replaceplatformtexformat replaceaction = null) {List
<string> Texpathls = new list<string> ();
Getassetstexinsubfolderforatlas ("Assets", ref Texpathls);
list<textureformatinfo> infols = new list<textureformatinfo> ();
int totalcount = Texpathls.count;
if (texpathls.count>0) {int icurcount = 0; foreach (var path in Texpathls) {Textureimporter teximporter = Textureimporter.getatpath (path
) as Textureimporter; if (null! = Teximporter) {textureformatinfo texformatinfo = new Textureformatinfo (Tex
Importer.assetpath); Teximporter.getplatformtexturesettings ("Standalone", out Texformatinfo.windowsmaxsize, out
Texformatinfo.texformatwindows); Teximporter.getplatformtexturesettings ("IPhone", out of Texformatinfo.iphonemaxsize, out
Texformatinfo.texformatiphone); Teximporter.getplatformtexturesettings ("Android", out Texformatinfo.androidmaxsize, out
Texformatinfo.texformatandroid);
texformatinfo.bmipmapenabled = teximporter.mipmapenabled;
BOOL Badd = true;
Texformatinfo.bneedandroidformat = Checkandroid (texformatinfo.texformatandroid);
Texformatinfo.bneediphoneformat = Checkiphone (Texformatinfo.texformatiphone); if (bfilter) {badd = texformatinfo.bmipmapenabled | | (!texformatinfo.bneedandroidformat) | |
(!texformatinfo.bneediphoneformat);
} if (badd) { Debug.Log (Texformatinfo.tostring ());
if (null! = replaceaction) {replaceaction (teximporter,texformatinfo);
} infols.add (Texformatinfo); }} editorutility.displaycancelableprogressbar ("Check Texformat", "Wait ...", (++icurcou
NT) * 1f/totalcount);
}} totalcount = Infols.count;
Debug.Log ("Pathcount:" + texpathls.count);
Debug.Log ("Infocount:" + infols.count);
Editorutility.clearprogressbar ();
return infols; } static void Savetextureformatinfopath (List<textureformatinfo> infols) {string filesavepath = ":
/alltextureformatinfopath ";
int totalcount = Infols.count; using (StreamWriter SW = file.createtext (Filesavepath + ". html")) {SW. WriteLine ("size =" + TotalCount + "</br> "); foreach (var info in infols) {SW. WriteLine (info.
Tohtmlstring ()); } SW.
Close (); }} static bool Checkandroidformat (Textureimporterformat format) {return format = = Textureimporterfo Rmat.
ETC_RGB4; } static bool Checkiphoneformat (Textureimporterformat format) {return format. ToString ().
Contains ("PVRTC");
} delegate bool Checkplatformtexformat (textureimporterformat format);
delegate void Replaceplatformtexformat (Textureimporter textureimporter,textureformatinfo texInfo); static void Replaceplatformformat (Textureimporter textureimporter, Textureformatinfo texInfo) {Textureimporte
r.mipmapenabled = false;
Textureimporter.setplatformtexturesettings ("Android", Texinfo.androidmaxsize, TEXTUREIMPORTERFORMAT.ETC_RGB4);
Assetdatabase.importasset (Textureimporter.assetpath); } class Textureformatinfo {public string path;
public bool bmipmapenabled;
public bool Bneedandroidformat;
public bool Bneediphoneformat;
Public Textureimporterformat Texformatiphone;
Public Textureimporterformat texformatandroid;
Public Textureimporterformat texformatwindows;
public int androidmaxsize;
public int iphonemaxsize;
public int windowsmaxsize;
Public Textureformatinfo (String filePath) {path = FilePath; } public string ToString () {string Strformat = "{0}: Mipmapenabled:{1},\nandroid:{2},\niphon
E:{3} "; return string.
Format (Strformat, Path, bmipmapenabled, Texformatandroid, Texformatiphone, texformatwindows); } public string tohtmlstring () {//<font color= "red" ><b> size = 2357 </B>&L t;/font></br> string Strformat = "{0}:     {1}, & ; nbsp {2}, {3}</br> "; String bmipstr = String.
Format ("mipmapenabled:{0}", bmipmapenabled); String parm1 = bmipmapenabled?
Getspecialtip (Bmipstr, "Red"): Bmipstr; String androidstr = String.
Format ("android:{0}", texformatandroid); String parm2 =!bneedandroidformat?
Getspecialtip (Androidstr, "Blue"): ANDROIDSTR; String iphonestr = String.
Format ("iphone:{0}", Texformatiphone); String parm3 =!bneediphoneformat?
Getspecialtip (Iphonestr, "Yellowgreen"): Iphonestr; return string.
Format (Strformat, Path, Parm1, Parm2, PARM3); private string Getspecialtip (String name,string fontcolor) {return string.
Format ("<font color=\" {0}\ "><b>{1}</b></font>", FontColor, name);
}} static void Getassetstexinsubfolderforatlas (string srcfolder, ref list<string> Atlas) {String searchPattern0 = "*.png";
String searchPattern1 = "*.tga";
String searchPattern2 = "*.PSD";
String searchfolder = Srcfolder.replace (@ "\", @ "/");
string searchDir0 = SearchFolder;
if (directory.exists (searchDir0)) {//string[] files = Directory.GetFiles (searchDir0, searchpattern);
Addfilepathtolist (Directory.GetFiles (SearchDir0, searchPattern0), ref Atlas);
Addfilepathtolist (Directory.GetFiles (SearchDir0, searchPattern1), ref Atlas);
Addfilepathtolist (Directory.GetFiles (SearchDir0, searchPattern2), ref Atlas);
} string[] dirs = directory.getdirectories (SearchFolder);
foreach (String onedir in dirs) {Getassetstexinsubfolderforatlas (Onedir, ref Atlas); }} static void Addfilepathtolist (string[] files, ref list<string> ls) {foreach (String onefil E in files) {string srcfile = ONefile.replace (@ "\", @ "/");
String lowerfile = Srcfile.tolower (); Ls.
ADD (Lowerfile); }} [MenuItem ("Myeditor/check Texture Format")] public static void Checktextureformat () {list< ;
textureformatinfo> Infols = Getalltex (True, Checkandroidformat, Checkiphoneformat);
Savetextureformatinfopath (Infols); } [MenuItem ("Myeditor/replace Texture Format")] public static void Replacetextureformat () {Getalltex
(True, Checkandroidformat, Checkiphoneformat, Replaceplatformformat);
Savetextureformatinfopath (Infols); }
}