{"id":198,"date":"2019-09-01T17:04:42","date_gmt":"2019-09-01T09:04:42","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=198"},"modified":"2020-09-28T21:54:08","modified_gmt":"2020-09-28T13:54:08","slug":"unity%e8%b8%a9%e5%9d%91%ef%bc%9atexture2d-alphaistransparency","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=198","title":{"rendered":"[Unity]\u8e29\u5751\uff1aTexture2D.alphaIsTransparency"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\n    static public void ImportTex(string textureAsset)\n    {\n        if (string.IsNullOrEmpty(textureAsset))\n        {\n            return;\n        }\n \n        AssetDatabase.Refresh(ImportAssetOptions.Default);\n \n        TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(textureAsset);\n        if (ti != null)\n        {\n            ti.isReadable = false;\n            ti.mipmapEnabled = false;\n            ti.alphaIsTransparency = true;\n            ti.filterMode = FilterMode.Bilinear;\n            ti.wrapMode = TextureWrapMode.Clamp;\n            ti.npotScale = TextureImporterNPOTScale.None;\n            ti.textureCompression = TextureImporterCompression.Uncompressed;\n            ti.SaveAndReimport();\n        }\n        else\n        {\n            Log.Error(\"Import Fail:{0}\", textureAsset);\n        }\n    }<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801,&nbsp;\u8bbe\u7f6e\u4e86alphaIsTransparency\u5c5e\u6027;\u6216\u8005\u5728Unity\u7684Inspector\u4e2d,\u5bf9\u7eb9\u7406\u52fe\u9009\u8fd9\u4e2a\u9009\u9879,\u90a3\u4e48Unity\u4f1a\u505a\u4ec0\u4e48\u4e8b\u60c5\u5462?<\/p>\n\n\n\n<p>\u5982\u679c\u6709\u4e00\u5f20PNG\u56fe\u7247, 95%\u7684\u5730\u65b9\u662f\u5168\u900f\u660e\u7684,\u800c\u5728\u5168\u900f\u660e\u7684\u5730\u65b9,RGB\u503c\u662f\u6709\u610f\u4e49\u7684;<\/p>\n\n\n\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86alphaIsTransparency\u5c5e\u6027,\u5219\u5168\u900f\u660e\u7684\u5730\u65b9,Unity\u4f1a\u5c06RGB\u503c\u5168\u90e8\u4e22\u5931!!!<\/p>\n\n\n\n<p>\u6240\u4ee5:<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u4f7f\u7528\u6b64\u7eb9\u7406\u76844\u4e2a\u901a\u9053\u505a\u6570\u636e\u5b58\u50a8\u65f6(\u6bd4\u5982\u5730\u578b\u76844\u901a\u9053\u6df7\u5408)<\/p>\n\n\n\n<p>\u5343\u4e07\u4e0d\u80fd\u52fe\u9009alphaIsTransparency\u5c5e\u6027<\/p>\n\n\n\n<p>\u9664\u975e\u6b64PNG\u56fe\u7247\u4ec5\u4ec5\u7528\u4e8eUI\u663e\u793a;<\/p>\n\n\n\n<p>\u8fd9\u70b9\u5728\u5b98\u65b9\u6587\u6863\u4e0a\u6ca1\u6709\u8bf4\u660e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0a\u4ee3\u7801,&nbsp;\u8bbe\u7f6e\u4e86alphaIsTransparency\u5c5e\u6027;\u6216\u8005\u5728Unity\u7684Inspector\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/198"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":581,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions\/581"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}