private void PreprocessTexture_Role_Scene() { if (!this.assetPath.Contains("OriginalRes/Role/") && !this.assetPath.Contains("OriginalRes/Scene/")) { return; } TextureImporter rTexImporter = this.assetImporter as TextureImporter; TextureImporterPlatformSettings rSettings = new TextureImporterPlatformSettings(); rSettings.name = "Standalone"; rSettings.maxTextureSize = 1024; rSettings.compressionQuality = 0; rSettings.textureCompression = TextureImporterCompression.CompressedHQ; rTexImporter.SetPlatformTextureSettings(rSettings); }
public bool IsFormatTexture(TextureInfo tInfo) { TextureImporter tImporter = AssetImporter.GetAtPath(tInfo.Path) as TextureImporter; if (tImporter == null) { return(false); } if (tImporter.isReadable != ReadWriteEnable) { return(false); } if (tImporter.mipmapEnabled != MipmapEnable) { return(false); } if (tImporter.textureType != TexType) { return(false); } TextureImporterPlatformSettings settingAndroid = tImporter.GetPlatformTextureSettings(EditorConst.PlatformAndroid); if (!settingAndroid.overridden || settingAndroid.format != GetFormatByAlphaMode(AndroidFormat, tImporter)) { return(false); } TextureImporterPlatformSettings settingIos = tImporter.GetPlatformTextureSettings(EditorConst.PlatformIos); if (!settingIos.overridden || settingIos.format != GetFormatByAlphaMode(IosFormat, tImporter)) { return(false); } if (MaxSize != -1 && tImporter.maxTextureSize != MaxSize) { return(false); } if (tImporter.maxTextureSize != settingAndroid.maxTextureSize) { return(false); } if (tImporter.maxTextureSize != settingIos.maxTextureSize) { return(false); } return(true); }
internal TextureImporterPlatformSettings GetPlatformTextureSettings(BuildTarget buildTarget) { var buildTargetName = TexturePlatformSettingsModal.kValidBuildPlatform.FirstOrDefault(x => x.buildTarget.Contains(buildTarget)); var defaultTargetName = TexturePlatformSettingsModal.kValidBuildPlatform.FirstOrDefault(x => x.buildTarget.Contains(BuildTarget.NoTarget)); TextureImporterPlatformSettings platformSettings = null; platformSettings = m_PlatformSettings.SingleOrDefault(x => x.name == buildTargetName.buildTargetName); platformSettings = platformSettings ?? m_PlatformSettings.SingleOrDefault(x => x.name == defaultTargetName.buildTargetName); if (platformSettings == null) { platformSettings = new TextureImporterPlatformSettings(); platformSettings.name = name; platformSettings.overridden = false; } return(platformSettings); }
public static TextureInfo CreateTextureInfo(string assetPath) { TextureInfo tInfo = null; if (!m_dictTexInfo.TryGetValue(assetPath, out tInfo)) { tInfo = new TextureInfo(); m_dictTexInfo.Add(assetPath, tInfo); } TextureImporter tImport = AssetImporter.GetAtPath(assetPath) as TextureImporter; Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath); if (tImport == null || texture == null) { return(null); } tInfo.Path = tImport.assetPath; tInfo.ImportType = tImport.textureType; tInfo.ReadWriteEnable = tImport.isReadable; tInfo.MipmapEnable = tImport.mipmapEnabled; tInfo.WrapMode = tImport.wrapMode; tInfo.FilterMode = tImport.filterMode; TextureImporterPlatformSettings settingAndroid = tImport.GetPlatformTextureSettings(EditorConst.PlatformAndroid); tInfo.AndroidFormat = settingAndroid.format; TextureImporterPlatformSettings settingIos = tImport.GetPlatformTextureSettings(EditorConst.PlatformIos); tInfo.IosFormat = settingIos.format; tInfo.MemSize = Mathf.Max( EditorCommon.CalculateTextureSizeBytes(texture, tInfo.AndroidFormat), EditorCommon.CalculateTextureSizeBytes(texture, tInfo.IosFormat)); if (Selection.activeObject != texture) { Resources.UnloadAsset(texture); } if (++m_loadCount % 256 == 0) { Resources.UnloadUnusedAssets(); } return(tInfo); }
public static void Deal(TextureImporter textureImporter, string assetPath) { var quality = _GetTextureQuaility(assetPath); textureImporter.mipmapEnabled = false; TextureImporterPlatformSettings androidTexture = textureImporter.GetPlatformTextureSettings("Android");// new TextureImporterPlatformSettings(); TextureImporterPlatformSettings iosTexture = textureImporter.GetPlatformTextureSettings("iPhone"); androidTexture.overridden = true; androidTexture.name = "Android"; androidTexture.allowsAlphaSplitting = false; iosTexture.overridden = true; iosTexture.name = "Ios"; iosTexture.allowsAlphaSplitting = false; textureImporter.textureCompression = TextureImporterCompression.Compressed; if (assetPath.StartsWith(Defines.SpritePackerSourceImagePath)) { textureImporter.textureType = TextureImporterType.Sprite; textureImporter.maxTextureSize = 1024; if (!string.IsNullOrEmpty(textureImporter.spritePackingTag)) { androidTexture.maxTextureSize = 1024; iosTexture.maxTextureSize = 1024; } } if (quality == TextureQuaility.Low) { androidTexture.format = TextureImporterFormat.ASTC_RGBA_4x4; iosTexture.format = TextureImporterFormat.ASTC_RGBA_4x4; } else { androidTexture.format = TextureImporterFormat.RGBA32; iosTexture.format = TextureImporterFormat.RGBA32; } textureImporter.SetPlatformTextureSettings(androidTexture); textureImporter.SetPlatformTextureSettings(iosTexture); }
bool CompareImporterPlatformSettings(TextureImporterPlatformSettings c1, TextureImporterPlatformSettings c2) { if (c1.allowsAlphaSplitting != c2.allowsAlphaSplitting) { return(false); } if (c1.androidETC2FallbackOverride != c2.androidETC2FallbackOverride) { return(false); } if (c1.compressionQuality != c2.compressionQuality) { return(false); } if (c1.crunchedCompression != c2.crunchedCompression) { return(false); } if (c1.format != c2.format) { return(false); } if (c1.maxTextureSize != c2.maxTextureSize) { return(false); } if (c1.name != c2.name) { return(false); } if (c1.overridden != c2.overridden) { return(false); } if (c1.resizeAlgorithm != c2.resizeAlgorithm) { return(false); } if (c1.textureCompression != c2.textureCompression) { return(false); } return(true); }
// texture void OnPreprocessTexture() { if (assetPath.Contains("Textures")) { TextureImporter textureImporter = (TextureImporter)assetImporter; textureImporter.textureType = TextureImporterType.Default; textureImporter.isReadable = false; TextureImporterPlatformSettings androidTexFMT = textureImporter.GetPlatformTextureSettings("Android"); androidTexFMT.overridden = true; if (textureImporter.DoesSourceTextureHaveAlpha()) { androidTexFMT.format = TextureImporterFormat.ETC2_RGBA8; } else { androidTexFMT.format = TextureImporterFormat.ETC2_RGB4; } textureImporter.SetPlatformTextureSettings(androidTexFMT); TextureImporterPlatformSettings iosTexFMT = textureImporter.GetPlatformTextureSettings("iPhone"); iosTexFMT.overridden = true; if (textureImporter.DoesSourceTextureHaveAlpha()) { iosTexFMT.format = TextureImporterFormat.ASTC_RGBA_4x4; } else { iosTexFMT.format = TextureImporterFormat.ASTC_RGB_4x4; } textureImporter.SetPlatformTextureSettings(iosTexFMT); TextureImporterPlatformSettings pcTexFMT = textureImporter.GetPlatformTextureSettings("Standalone"); pcTexFMT.overridden = true; if (textureImporter.DoesSourceTextureHaveAlpha()) { pcTexFMT.format = TextureImporterFormat.DXT5; } else { pcTexFMT.format = TextureImporterFormat.DXT1; } textureImporter.SetPlatformTextureSettings(pcTexFMT); } }
static void FixPictureSheets(string path) { TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter; if (ti == null) { return; } ti.textureType = TextureImporterType.Sprite; ti.textureShape = TextureImporterShape.Texture2D; ti.sRGBTexture = true; ti.alphaSource = TextureImporterAlphaSource.FromInput; ti.spriteImportMode = SpriteImportMode.Multiple; ti.spritePixelsPerUnit = 100; ti.alphaIsTransparency = true; ti.mipmapEnabled = false; ti.isReadable = false; ti.wrapMode = TextureWrapMode.Repeat; ti.filterMode = FilterMode.Bilinear; TextureImporterPlatformSettings setIos = ti.GetPlatformTextureSettings("iPhone"); setIos.overridden = true; setIos.maxTextureSize = 2048; setIos.format = TextureImporterFormat.PVRTC_RGB4; setIos.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; setIos.textureCompression = TextureImporterCompression.Compressed; setIos.compressionQuality = 70; ti.SetPlatformTextureSettings(setIos); TextureImporterPlatformSettings setAnd = ti.GetPlatformTextureSettings("Android"); setAnd.overridden = true; setAnd.maxTextureSize = 2048; setAnd.format = TextureImporterFormat.ETC2_RGB4; setAnd.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; setAnd.textureCompression = TextureImporterCompression.Compressed; setAnd.compressionQuality = 70; ti.SetPlatformTextureSettings(setAnd); ti.SaveAndReimport(); }
static void FixCarMaterialSelectionNormal(Material mat) { Texture tex = mat.GetTexture("_NormalTex"); string path = AssetDatabase.GetAssetPath(tex); Debug.Log("Begin " + mat.name + " Normal texture:" + path); TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter; if (ti == null) { return; } ti.textureType = TextureImporterType.Default; ti.textureShape = TextureImporterShape.Texture2D; ti.sRGBTexture = false; ti.alphaSource = TextureImporterAlphaSource.None; ti.mipmapEnabled = false; ti.isReadable = false; ti.wrapMode = TextureWrapMode.Repeat; ti.filterMode = FilterMode.Bilinear; TextureImporterPlatformSettings setIos = ti.GetPlatformTextureSettings("iPhone"); setIos.overridden = true; setIos.maxTextureSize = 1024; setIos.format = TextureImporterFormat.PVRTC_RGB4; setIos.textureCompression = TextureImporterCompression.CompressedHQ; setIos.compressionQuality = 80; setIos.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; ti.SetPlatformTextureSettings(setIos); TextureImporterPlatformSettings setAnd = ti.GetPlatformTextureSettings("Android"); setAnd.overridden = true; setAnd.maxTextureSize = 1024; setAnd.format = TextureImporterFormat.ETC_RGB4; setAnd.textureCompression = TextureImporterCompression.CompressedHQ; setAnd.compressionQuality = 80; setAnd.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; ti.SetPlatformTextureSettings(setAnd); ti.SaveAndReimport(); }
static void FixCarMaterialCombatMainTex(Material mat) { Texture tex = mat.GetTexture("_MainTex"); string path = AssetDatabase.GetAssetPath(tex); Debug.Log("Begin " + mat.name + " MainTex:" + path); TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter; if (ti == null) { return; } ti.textureType = TextureImporterType.Default; ti.textureShape = TextureImporterShape.Texture2D; ti.sRGBTexture = true; ti.mipmapEnabled = false; //Disable mip map ti.isReadable = false; ti.alphaSource = TextureImporterAlphaSource.FromInput; //Alpha channel used as manual smoothness ti.wrapMode = TextureWrapMode.Repeat; ti.filterMode = FilterMode.Bilinear; TextureImporterPlatformSettings setIos = ti.GetPlatformTextureSettings("iPhone"); setIos.overridden = true; setIos.maxTextureSize = 256; setIos.format = TextureImporterFormat.PVRTC_RGBA4; setIos.textureCompression = TextureImporterCompression.Compressed; setIos.compressionQuality = 60; setIos.resizeAlgorithm = TextureResizeAlgorithm.Bilinear; ti.SetPlatformTextureSettings(setIos); TextureImporterPlatformSettings setAnd = ti.GetPlatformTextureSettings("Android"); setAnd.overridden = true; setAnd.maxTextureSize = 256; setAnd.format = TextureImporterFormat.ETC2_RGBA8Crunched; setAnd.textureCompression = TextureImporterCompression.Compressed; setAnd.compressionQuality = 60; setAnd.resizeAlgorithm = TextureResizeAlgorithm.Bilinear; ti.SetPlatformTextureSettings(setAnd); ti.SaveAndReimport(); }
protected void PlatformTextureSetting(TextureImporter textureImporter, string platfrom, PlatformOverrideContence targetPlatformFomat, bool isUsingUnityDefaultCompress) { //if (m_PlatformOverrideContence == null || !m_PlatformOverrideContence.ContainsKey(platfrom)) //{ // return; //} //OverrideContence targetPlatformFomat = m_PlatformOverrideContence[platfrom]; TextureImporterPlatformSettings sourcePlatformImporterSettings = textureImporter.GetPlatformTextureSettings(platfrom); sourcePlatformImporterSettings.overridden = targetPlatformFomat.IsOverride; if (targetPlatformFomat.MaxSize <= 3 && targetPlatformFomat.MaxSize != -1) { sourcePlatformImporterSettings.maxTextureSize = GetLowLevelSize(textureImporter.maxTextureSize, targetPlatformFomat.MaxSize); } else if (targetPlatformFomat.MaxSize != -1) { sourcePlatformImporterSettings.maxTextureSize = targetPlatformFomat.MaxSize; } //if(isUsingUnityDefaultCompress) //{ // textureImporter.SetPlatformTextureSettings(sourcePlatformImporterSettings); // return; //} if (textureImporter.textureType == TextureImporterType.Default) { // 优化策略,只修改不是ETC或者PVRTC压缩格式的图为指定的压缩格式 [11:49 27/4/2018 BingLau] if (CheckNeedChangeFormat(sourcePlatformImporterSettings.format)) { sourcePlatformImporterSettings.format = targetPlatformFomat.DefaultFormat; } textureImporter.SetPlatformTextureSettings(sourcePlatformImporterSettings); } else if (textureImporter.textureType == TextureImporterType.NormalMap) { if (CheckNeedChangeFormat(sourcePlatformImporterSettings.format)) { sourcePlatformImporterSettings.format = targetPlatformFomat.NormalFormat; } textureImporter.SetPlatformTextureSettings(sourcePlatformImporterSettings); } }
static void SetTextureFormat16() { Object[] selects = Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets); foreach (Object o in selects) { string path = AssetDatabase.GetAssetPath(o); TextureImporter asset = TextureImporter.GetAtPath(path) as TextureImporter; TextureImporterPlatformSettings texSettings = new TextureImporterPlatformSettings(); texSettings.overridden = true; texSettings.format = TextureImporterFormat.RGBA16; texSettings.name = "iPhone"; asset.SetPlatformTextureSettings(texSettings); asset.SaveAndReimport(); AssetDatabase.ImportAsset(path); } AssetDatabase.Refresh(); Debug.Log("Set Texture Format Success.."); }
protected void SetDefaultSettings(TextureImporter textureImporter) { foreach (var platform in Platforms) { var platformTextureSetting = textureImporter.GetPlatformTextureSettings(platform.ToString()); var settings = new TextureImporterPlatformSettings(); platformTextureSetting.CopyTo(settings); settings.overridden = false; if (!platformTextureSetting.Equals(settings)) { textureImporter.SetPlatformTextureSettings(settings); } } }
void OnPreprocessTexture() { Debug.Log(assetPath); var importer = (assetImporter as TextureImporter); TextureImporterPlatformSettings pts = importer.GetPlatformTextureSettings("iPhone"); if (CanModifier()) { pts.overridden = true; pts.format = TextureImporterFormat.RGBA32; } else { pts.overridden = false; } importer.SetPlatformTextureSettings(pts); }
void OnPreprocessTexture() { // Automatically convert any texture file (put in folders when Editor run) with "UI_Image" // in its file name into an uncompressed unchanged GUI Image. // All setting taked from example from Lesson // If file contain name corresponding foler if (assetPath.Contains("UI_Images")) { //Debug.Log("Importing new GUI Image!"); Replaced by OnPostprocessTexture Debug.Log() TextureImporter myTextureImporter = (TextureImporter)assetImporter; myTextureImporter.textureType = TextureImporterType.GUI; myTextureImporter.textureCompression = TextureImporterCompression.Uncompressed; // Some parameters for TextureImporte set through TextureImporterPlatformSettings now TextureImporterPlatformSettings platformSettings = new TextureImporterPlatformSettings { // Set special setting for PC, Mac & Unix name = "Standalone", overridden = true, maxTextureSize = 2048, format = TextureImporterFormat.RGBA32 }; myTextureImporter.SetPlatformTextureSettings(platformSettings); //myTextureImporter.textureFormat = TextureImporterFormat.ARGB32; obsolete //myTextureImporter.maxTextureSize = 2048; move to platformSettings myTextureImporter.convertToNormalmap = false; myTextureImporter.alphaSource = TextureImporterAlphaSource.FromInput; //myTextureImporter.generateCubemap = TextureImporterGenerateCubemap.None; obsolete myTextureImporter.textureShape = TextureImporterShape.Texture2D; myTextureImporter.npotScale = TextureImporterNPOTScale.None; myTextureImporter.isReadable = true; myTextureImporter.mipmapEnabled = false; myTextureImporter.mipmapFilter = TextureImporterMipFilter.BoxFilter; myTextureImporter.fadeout = false; myTextureImporter.convertToNormalmap = false; //myTextureImporter.lightmap = false; obsolete //myTextureImporter.ClearPlatformTextureSettings("Web"); doesn't touched in this scrpit // Return to default setting for PC, Mac & Unix myTextureImporter.ClearPlatformTextureSettings("Standalone"); //myTextureImporter.ClearPlatformTextureSettings("iPhone"); doesn't touched in this scrpit } }
public static bool ProcessAndroidAssetSpriteImport(TextureImporter textureImporter) { bool needOverride = false; if (textureImporter.alphaSource != TextureImporterAlphaSource.FromInput) { textureImporter.alphaSource = TextureImporterAlphaSource.FromInput; needOverride = true; } if (!needOverride && textureImporter.DoesSourceTextureHaveAlpha()) { return(false); } int maxTextureSize; TextureImporterFormat textureFormat; int compressionQuality; TextureImporterFormat targetTextureImporterFormat = TextureImporterFormat.ETC2_RGB4; if (!textureImporter.GetPlatformTextureSettings("Android", out maxTextureSize, out textureFormat, out compressionQuality)) { needOverride = true; } if (textureFormat != targetTextureImporterFormat) { needOverride = true; } if (needOverride) { TextureImporterPlatformSettings setting = new TextureImporterPlatformSettings(); setting.overridden = true; setting.name = "Android"; setting.crunchedCompression = false; setting.maxTextureSize = 2048; setting.compressionQuality = 50; setting.format = targetTextureImporterFormat; textureImporter.SetPlatformTextureSettings(setting); } return(needOverride); }
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); } } }
public override bool OnFormat(Object _obj, string _path, AssetImporter _importer) { var texImporter = _importer as TextureImporter; if (texImporter) { TextureImporterPlatformSettings android = texImporter.GetPlatformTextureSettings("Android"); TextureImporterPlatformSettings ios = texImporter.GetPlatformTextureSettings("iPhone"); //是否带alpha通道 bool isAlpha = texImporter.DoesSourceTextureHaveAlpha(); android.format = isAlpha ? TextureImporterFormat.ETC2_RGBA8 : TextureImporterFormat.ETC_RGB4; ios.format = isAlpha ? TextureImporterFormat.PVRTC_RGBA4 : TextureImporterFormat.PVRTC_RGB4; texImporter.SaveAndReimport(); } return(base.OnFormat(_obj, _path, _importer)); }
private TextureImporterPlatformSettings getIPhoneAtlasTIPS(string path) { string name = System.IO.Path.GetFileNameWithoutExtension(path); TextureImporterPlatformSettings iostps = new TextureImporterPlatformSettings(); iostps.name = "iPhone"; iostps.overridden = true; // iostps.compressionQuality = 0; if (name == "ui_atlas_icon_0" || name == "ui_atlas_pic_1" || name == "ui_atlas_pic_2") { iostps.format = TextureImporterFormat.RGBA32; } else { iostps.compressionQuality = (int)UnityEditor.TextureCompressionQuality.Fast; iostps.format = TextureImporterFormat.RGBA32; } return(iostps); }
public static TextureImporterPlatformSettings GetIOSStandardImportSetting(TextureImporter importer, TextureType type, bool hasAlpha) { TextureImporterCompression compression = TextureImporterCompression.Compressed; var format = hasAlpha ? TextureImporterFormat.ASTC_RGBA_6x6 : TextureImporterFormat.ASTC_RGB_6x6; TextureResizeAlgorithm resizeAlgorithm = TextureResizeAlgorithm.Mitchell; var ti = new TextureImporterPlatformSettings { name = "iPhone", overridden = true, format = format, textureCompression = compression, maxTextureSize = textureMaxSize(type), compressionQuality = GetTextureCompressQuality(), resizeAlgorithm = resizeAlgorithm }; return(ti); }
// Apply settings Method which searches and adds all texture files in an array, and for each file, adds the settings, overrides it for the selected platform // and imports the newly applied asset again, therefore applying all the settings properly. static void ApplySettings(int maxSize, int anisoLevel, bool alphaSplitting, TextureImporterCompression compressionType, string platform) { Object[] textures = GetSelectedTextures(); Selection.objects = new Object[0]; foreach (Texture texture in textures) { string path = AssetDatabase.GetAssetPath(texture); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; TextureImporterPlatformSettings texturesettings = textureImporter.GetDefaultPlatformTextureSettings(); texturesettings.maxTextureSize = maxSize; texturesettings.name = platform; texturesettings.overridden = true; texturesettings.textureCompression = compressionType; texturesettings.allowsAlphaSplitting = alphaSplitting; textureImporter.anisoLevel = anisoLevel; textureImporter.SetPlatformTextureSettings(texturesettings); AssetDatabase.ImportAsset(path); } }
public static void SetTextureImporterSettings(string path, TextureImporterFormat format, bool isReadEnabled) { TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; if (textureImporter == null) { return; } textureImporter.spriteImportMode = SpriteImportMode.None; TextureImporterSettings ts = new TextureImporterSettings(); textureImporter.ReadTextureSettings(ts); ts.readable = isReadEnabled; ts.mipmapEnabled = false; ts.aniso = 4; ts.alphaIsTransparency = true; ts.wrapMode = TextureWrapMode.Clamp; textureImporter.SetTextureSettings(ts); switch (EditorUserBuildSettings.activeBuildTarget) { case BuildTarget.Android: TextureImporterPlatformSettings tspAndroid = new TextureImporterPlatformSettings(); tspAndroid.name = "Android"; tspAndroid.format = format; tspAndroid.overridden = true; tspAndroid.maxTextureSize = 1024; textureImporter.SetPlatformTextureSettings(tspAndroid); break; case BuildTarget.iOS: TextureImporterPlatformSettings tspiOS = new TextureImporterPlatformSettings(); tspiOS.name = "iPhone"; tspiOS.format = format; tspiOS.overridden = true; tspiOS.maxTextureSize = 1024; textureImporter.SetPlatformTextureSettings(tspiOS); break; } AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
bool CompareImporterPlatformSettings(TextureImporterPlatformSettings c1, TextureImporterPlatformSettings c2) { if (c1.allowsAlphaSplitting != c2.allowsAlphaSplitting) { return(false); } if (c1.compressionQuality != c2.compressionQuality) { return(false); } if (c1.crunchedCompression != c2.crunchedCompression) { return(false); } if (c1.format != c2.format) { return(false); } if (c1.maxTextureSize != c2.maxTextureSize) { return(false); } if (c1.name != c2.name) { return(false); } if (c1.overridden != c2.overridden) { return(false); } if (c1.textureCompression != c2.textureCompression) { return(false); } #if UNITY_2017_2_OR_NEWER if (c1.resizeAlgorithm != c2.resizeAlgorithm) { return(false); } #endif return(true); }
private static void SetiOSTextureFormat(TextureImporter import, bool isAlpha) { TextureImporterFormat textureFormat = TextureImporterFormat.ASTC_RGBA_4x4; int compressionQuality = 50; if (!isAlpha) { textureFormat = TextureImporterFormat.ASTC_RGB_4x4; } TextureImporterPlatformSettings iosFormat = import.GetPlatformTextureSettings("iPhone"); if (!iosFormat.overridden || iosFormat.format != textureFormat || iosFormat.compressionQuality != compressionQuality) { iosFormat.overridden = true; iosFormat.format = textureFormat; iosFormat.compressionQuality = compressionQuality; import.SetPlatformTextureSettings(iosFormat); } }
private static void SetAndroidTextureFormat(TextureImporter import, bool isAlpha) { TextureImporterFormat textureFormat = TextureImporterFormat.ASTC_RGBA_4x4; int compressionQuality = 50; if (!isAlpha) { textureFormat = TextureImporterFormat.ASTC_RGB_4x4; } TextureImporterPlatformSettings andFormat = import.GetPlatformTextureSettings("Android"); if (!andFormat.overridden || andFormat.format != textureFormat || andFormat.compressionQuality != compressionQuality) { andFormat.overridden = true; andFormat.format = textureFormat; andFormat.compressionQuality = compressionQuality; import.SetPlatformTextureSettings(andFormat); } }
static void OnPreprocessSpine(string assetPath, TextureImporter importer) { Debug.Log("Spine Preprocess Texture: " + assetPath); importer.textureType = TextureImporterType.Default; importer.sRGBTexture = true; importer.isReadable = false; importer.mipmapEnabled = false; importer.wrapMode = TextureWrapMode.Clamp; importer.filterMode = FilterMode.Bilinear; importer.alphaSource = TextureImporterAlphaSource.None; importer.alphaIsTransparency = false; importer.npotScale = TextureImporterNPOTScale.ToNearest; importer.textureCompression = TextureImporterCompression.Compressed; var iPhone = new TextureImporterPlatformSettings(); iPhone.name = "iPhone"; iPhone.overridden = true; iPhone.format = TextureImporterFormat.ASTC_RGBA_4x4; iPhone.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; iPhone.textureCompression = TextureImporterCompression.Compressed; importer.SetPlatformTextureSettings(iPhone); var android = new TextureImporterPlatformSettings(); android.name = "Android"; android.overridden = true; android.format = TextureImporterFormat.RGBA32; //android.compressionQuality = 100; android.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; android.textureCompression = TextureImporterCompression.Compressed; android.androidETC2FallbackOverride = AndroidETC2FallbackOverride.Quality32BitDownscaled; importer.SetPlatformTextureSettings(android); var standalone = new TextureImporterPlatformSettings(); standalone.name = "Standalone"; standalone.overridden = true; standalone.format = TextureImporterFormat.RGBA32; standalone.resizeAlgorithm = TextureResizeAlgorithm.Mitchell; standalone.textureCompression = TextureImporterCompression.Uncompressed; importer.SetPlatformTextureSettings(standalone); }
static void SetTexture(Texture texture) { if (texture == null) { return; } string assetPath = AssetDatabase.GetAssetPath(texture); TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; string endFolderName = new DirectoryInfo(Path.GetDirectoryName(assetPath)).Name; textureImporter.textureType = TextureImporterType.Sprite; textureImporter.spriteImportMode = SpriteImportMode.Single; //采用新版SpriteAtlas //string spritePackingTag = endFolderName; //textureImporter.spritePackingTag = spritePackingTag; textureImporter.mipmapEnabled = false; textureImporter.npotScale = TextureImporterNPOTScale.None; textureImporter.alphaIsTransparency = true; textureImporter.isReadable = false; TextureImporterPlatformSettings tips = new TextureImporterPlatformSettings(); tips.name = "Android"; tips.maxTextureSize = 2048; tips.format = textureImporter.alphaIsTransparency ? TextureImporterFormat.ETC2_RGBA8 : TextureImporterFormat.ETC2_RGB4; tips.compressionQuality = (int)TextureCompressionQuality.Normal; tips.allowsAlphaSplitting = false; tips.overridden = true; textureImporter.SetPlatformTextureSettings(tips); tips.name = "iPhone"; tips.maxTextureSize = 2048; tips.format = textureImporter.alphaIsTransparency ? TextureImporterFormat.PVRTC_RGBA4 : TextureImporterFormat.PVRTC_RGB4; tips.compressionQuality = (int)TextureCompressionQuality.Normal; tips.allowsAlphaSplitting = false; tips.overridden = true; textureImporter.SetPlatformTextureSettings(tips); textureImporter.SaveAndReimport(); }
protected virtual void SetCompressionSettings(TextureImporter textureImporter) { var pathSplit = textureImporter.assetPath.Split(PathUtility.PathSeparator); var size = GetPreImportTextureSize(textureImporter); if (IgnoreCompressionFolders.Any(x => pathSplit.Contains(x))) { SetDefaultSettings(textureImporter); return; } // ブロックが使えるか(4の倍数なら圧縮設定). var isMultipleOf4 = IsMultipleOf4(size.x) && IsMultipleOf4(size.y); if (!isMultipleOf4) { SetDefaultSettings(textureImporter); return; } foreach (var platform in Platforms) { var platformTextureSetting = textureImporter.GetPlatformTextureSettings(platform.ToString()); var settings = new TextureImporterPlatformSettings(); platformTextureSetting.CopyTo(settings); settings.overridden = true; settings.compressionQuality = (int)UnityEngine.TextureCompressionQuality.Normal; settings.textureCompression = TextureImporterCompression.Compressed; settings.androidETC2FallbackOverride = AndroidETC2FallbackOverride.UseBuildSettings; settings.format = GetPlatformCompressionType(textureImporter, platform); if (!platformTextureSetting.Equals(settings)) { textureImporter.SetPlatformTextureSettings(settings); } } }
private void CreatAndSetBlendTex(Material mt) { string blendTexFolder = "Assets/BrushTerrain/BlendTex/"; Texture2D blendTexAs = new Texture2D(256, 256, TextureFormat.ARGB32, true); Color[] col = new Color[256 * 256]; for (int i = 0; i < col.Length; i++) { col[i] = new Color(0, 0, 0, 0); } blendTexAs.SetPixels(col); string path = blendTexFolder + blendTexAs.GetHashCode() + ".png"; byte[] bytes = blendTexAs.EncodeToPNG(); File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); //==AssetDatabase.Refresh(); //AssetDatabase.Refresh(); TextureImporter imt = TextureImporter.GetAtPath(path) as TextureImporter; imt.isReadable = true; #if UNITY_5_5_OR_NEWER TextureImporterPlatformSettings tips = imt.GetDefaultPlatformTextureSettings(); tips.textureCompression = TextureImporterCompression.Uncompressed; tips.format = TextureImporterFormat.RGBA32; tips.overridden = true; imt.SetPlatformTextureSettings(tips); #else imt.textureFormat = TextureImporterFormat.RGBA32; #endif imt.wrapMode = TextureWrapMode.Clamp; imt.anisoLevel = 9; imt.mipmapEnabled = false; AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); Texture2D blendTex = AssetDatabase.LoadAssetAtPath <Texture2D>(path); mt.SetTexture("_BlendTex", blendTex); }
public TexturePlatformNorm GetPlatformNorm(TextureImporterPlatformSettings setting, TextureFormatKey[] normRecommend, TextureFormatKey[] normForbid) { TexturePlatformNorm tpn = new TexturePlatformNorm() { setting = setting, normRecommend = normRecommend, }; string format = setting.format.ToString(); if (isInclude(normRecommend, format)) { tpn.formatLevel = 0; } else if (isInclude(normForbid, format)) { tpn.formatLevel = 2; errorNum++; } else { tpn.formatLevel = 1; warnNum++; } //maxSize int maxSize = setting.maxTextureSize; if (maxSize <= textureSize) { if (maxSize >= ResourceAuditingSetting.GetIntance().Tex_Recommend_Size&& maxSize < ResourceAuditingSetting.GetIntance().Tex_Max_Size) { tpn.maxSizeLevel = 1; warnNum++; } else if (maxSize >= ResourceAuditingSetting.GetIntance().Tex_Max_Size) { tpn.maxSizeLevel = 2; errorNum++; } } return(tpn); }