Esempio n. 1
0
 private static bool _Cutoff2RMat(Material mat, string path)
 {
     if (mat.shader.name.Contains("CutoutDiffuse") ||
         mat.shader.name.Contains("TransparentDiffuse"))
     {
         Texture2D tex = mat.mainTexture as Texture2D;
         if (tex != null)
         {
             Texture2D alphaTex = TextureModify.ConvertTexRtex(tex);
             if (mat.shader.name.Contains("RimLight/CutoutDiffuse"))
             {
                 mat.shader = Shader.Find("Custom/RimLight/CutoutDiffuseMaskR");
             }
             else if (mat.shader.name.Contains("CutoutDiffuse") && mat.shader.name.Contains("NoLight"))
             {
                 mat.shader = Shader.Find("Custom/Common/CutoutDiffuseMaskRNoLight");
             }
             else if (mat.shader.name.Contains("CutoutDiffuse"))
             {
                 mat.shader = Shader.Find("Custom/Common/CutoutDiffuseMaskR");
             }
             else if (mat.shader.name.Contains("Common/TransparentDiffuse") && mat.shader.name.Contains("NoLight"))
             {
                 mat.shader = Shader.Find("Custom/Common/TransparentDiffuseMaskRNoLight");
             }
             else if (mat.shader.name.Contains("Common/TransparentDiffuse"))
             {
                 mat.shader = Shader.Find("Custom/Common/TransparentDiffuseMaskR");
             }
             mat.SetTexture("_Mask", alphaTex);
         }
     }
     return(true);
 }
Esempio n. 2
0
 private static void _PrcessSceneMat(Material mat, bool recover)
 {
     if (!processedMat.Contains(mat) && mat.shader != null)
     {
         if (mat.shader.name == "Transparent/Cutout/Diffuse" ||
             mat.shader.name == "Custom/Scene/CutoutDiffuseMaskLM")
         {
             Texture2D tex = mat.mainTexture as Texture2D;
             if (tex != null)
             {
                 if (recover)
                 {
                     string          texPath     = AssetDatabase.GetAssetPath(tex);
                     int             size        = tex.width > tex.height ? tex.width : tex.height;
                     TextureImporter texImporter = AssetImporter.GetAtPath(texPath) as TextureImporter;
                     texImporter.textureType   = TextureImporterType.Default;
                     texImporter.anisoLevel    = 0;
                     texImporter.mipmapEnabled = size > 256;
                     texImporter.npotScale     = TextureImporterNPOTScale.ToNearest;
                     texImporter.wrapMode      = TextureWrapMode.Repeat;
                     texImporter.filterMode    = FilterMode.Bilinear;
                     TextureImporterPlatformSettings pseting = new TextureImporterPlatformSettings();
                     pseting.format         = TextureImporterFormat.RGBA16;
                     pseting.name           = BuildTarget.Android.ToString();
                     pseting.maxTextureSize = size;
                     texImporter.SetPlatformTextureSettings(pseting);
                     pseting.name = BuildTarget.iOS.ToString();
                     texImporter.SetPlatformTextureSettings(pseting);
                     texImporter.isReadable = false;
                     AssetDatabase.ImportAsset(texPath, ImportAssetOptions.ForceUpdate);
                     mat.shader = Shader.Find("Transparent/Cutout/Diffuse");
                 }
                 else
                 {
                     Texture2D alphaTex = TextureModify.ConvertTexRtex(tex);
                     mat.shader = Shader.Find("Custom/Scene/CutoutDiffuseMaskLM");
                     mat.SetTexture("_Mask", alphaTex);
                 }
             }
             processedMat.Add(mat);
         }
     }
 }
Esempio n. 3
0
        private bool _TextureCompress(Texture2D tex, TextureImporter textureImporter, string path)
        {
            textureImporter.textureType   = TextureImporterType.Default;
            textureImporter.anisoLevel    = 0;
            textureImporter.filterMode    = FilterMode.Bilinear;
            textureImporter.isReadable    = false;
            textureImporter.wrapMode      = wrapMode;
            textureImporter.mipmapEnabled = genMipmap;
            switch (compressType)
            {
            case ETextureCompress.ECompress:
                iosFormat     = TextureImporterFormat.PVRTC_RGB4;
                androidFormat = TextureImporterFormat.ETC_RGB4;
                break;

            case ETextureCompress.E16:
                if (textureImporter.DoesSourceTextureHaveAlpha())
                {
                    iosFormat     = TextureImporterFormat.RGBA32;
                    androidFormat = TextureImporterFormat.RGBA16;
                }
                else
                {
                    iosFormat     = TextureImporterFormat.RGB24;
                    androidFormat = TextureImporterFormat.RGB16;
                }
                break;

            case ETextureCompress.E32:
                if (textureImporter.DoesSourceTextureHaveAlpha())
                {
                    iosFormat     = TextureImporterFormat.RGBA32;
                    androidFormat = TextureImporterFormat.RGBA32;
                }
                else
                {
                    iosFormat     = TextureImporterFormat.RGB24;
                    androidFormat = TextureImporterFormat.RGB24;
                }
                break;

            case ETextureCompress.EA8:
                iosFormat     = TextureImporterFormat.Alpha8;
                androidFormat = TextureImporterFormat.Alpha8;
                break;
            }
            TextureImporterPlatformSettings pseting = new TextureImporterPlatformSettings();

            pseting.format         = genAlpha ? TextureImporterFormat.DXT5 : TextureImporterFormat.DXT1;
            pseting.name           = "Standalone";
            pseting.maxTextureSize = (int)compressSize;
            textureImporter.SetPlatformTextureSettings(pseting);

            if (genAlpha)
            {
                int extIndex = path.LastIndexOf(".");
                if (extIndex >= 0)
                {
                    string alphaTexPath = path.Substring(0, extIndex) + "_A.png";
                    if (genRAlpha)
                    {
                        pseting        = new TextureImporterPlatformSettings();
                        pseting.format = TextureImporterFormat.RGBA32;
                        pseting.name   = BuildTarget.Android.ToString();
                        textureImporter.SetPlatformTextureSettings(pseting);
                        pseting.name = BuildTarget.iOS.ToString();
                        textureImporter.SetPlatformTextureSettings(pseting);
                        textureImporter.isReadable = true;
                        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                        TextureModify.MakeAlphaRTex(alphaTexPath, (int)alphaSize, tex);
                        pseting.format = TextureImporterFormat.PVRTC_RGB4;
                        textureImporter.SetPlatformTextureSettings(pseting);
                        pseting.format = TextureImporterFormat.ETC_RGB4;
                        textureImporter.SetPlatformTextureSettings(pseting);
                        textureImporter.isReadable = false;
                        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
                    }
                    else
                    {
                        File.Copy(path, alphaTexPath, true);
                        AssetDatabase.ImportAsset(alphaTexPath, ImportAssetOptions.ForceUpdate);
                        TextureImporter alphaTextureImporter = AssetImporter.GetAtPath(alphaTexPath) as TextureImporter;
                        if (alphaTextureImporter != null)
                        {
                            TextureImporterSettings setting = new TextureImporterSettings();
                            setting.textureType   = TextureImporterType.Default;
                            setting.aniso         = 0;
                            setting.mipmapEnabled = false;
                            setting.readable      = false;
                            setting.npotScale     = TextureImporterNPOTScale.ToNearest;
                            textureImporter.SetTextureSettings(setting);

                            pseting                = new TextureImporterPlatformSettings();
                            pseting.format         = TextureImporterFormat.Alpha8;
                            pseting.name           = BuildTarget.Android.ToString();
                            pseting.maxTextureSize = (int)alphaSize;
                            alphaTextureImporter.SetPlatformTextureSettings(pseting);
                            pseting.name = BuildTarget.iOS.ToString();
                            alphaTextureImporter.SetPlatformTextureSettings(pseting);
                            AssetDatabase.ImportAsset(alphaTexPath, ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
 private void Compress()
 {
     TextureModify.EnumTextures(_TextureCompress, "TextureCompress");
 }