/** * 保存纹理图片相关信息 */ public string SaveTextureFormat(Texture2D tex, string texPath, string matPath, bool closemipmap = false, string ext = "png", bool normal = false) { string name = PathHelper.CheckFileName(tex.name + ".image.json"); MyJson_Tree textureItem = new MyJson_Tree(); var fileName = texPath.Substring(0, texPath.LastIndexOf(".") + 1) + ext; textureItem.SetString("name", PathHelper.CheckFileName(texPath)); textureItem.SetEnum("filterMode", tex.filterMode, true); textureItem.SetEnum("wrap", tex.wrapMode, true); textureItem.SetBool("mipmap", !closemipmap && tex.mipmapCount > 1); if (tex.anisoLevel > 1) { textureItem.SetNumber("anisotropy", tex.anisoLevel); } if (tex.format == TextureFormat.Alpha8) { textureItem.SetString("format", "Gray"); } else if (ext == "jpg" || tex.format == TextureFormat.RGB24 || tex.format == TextureFormat.PVRTC_RGB2 || tex.format == TextureFormat.PVRTC_RGB4 || tex.format == TextureFormat.RGB565 || tex.format == TextureFormat.ETC_RGB4 || tex.format == TextureFormat.ATC_RGB4 || tex.format == TextureFormat.ETC2_RGB || tex.format == TextureFormat.ASTC_RGB_4x4 || tex.format == TextureFormat.ASTC_RGB_5x5 || tex.format == TextureFormat.ASTC_RGB_6x6 || tex.format == TextureFormat.ASTC_RGB_8x8 || tex.format == TextureFormat.ASTC_RGB_10x10 || tex.format == TextureFormat.ASTC_RGB_12x12 ) { textureItem.SetString("format", "RGB"); } textureItem.SetInt("version", 2); //得到.imgdesc.json数据,并保存到bufs中 System.Text.StringBuilder sb = new System.Text.StringBuilder(); textureItem.CovertToStringWithFormat(sb, 4); byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); //相对路径 var imgdescPath = texPath.Substring(0, texPath.LastIndexOf("/") + 1) + name; this.AddFileBuffer(imgdescPath, bs); return(imgdescPath); }