void ReimportNonReadableTextures() { IEnumerable <Texture> allTextures = drawCallTarget.GetComponentsInChildren <Renderer> ().SelectMany(X => ShaderPropertyUtility.GetAllTextures(X.sharedMaterial)).Distinct(); AssetPostprocessor postProcessor = new AssetPostprocessor(); float currentCount = 0.0f; int targetCount = allTextures.Count(); foreach (Texture t in allTextures) { EditorUtility.DisplayProgressBar("Turning Off Readonly", "Analyzing texture " + ((int)currentCount + 1).ToString() + " of " + targetCount.ToString(), currentCount / targetCount); currentCount += 1; string assetPath = AssetDatabase.GetAssetPath(t); if (assetPath != null) { postProcessor.assetPath = assetPath; TextureImporter importer = (TextureImporter)postProcessor.assetImporter; if (importer != null && !importer.isReadable) { importer.isReadable = true; importer.textureFormat = TextureImporterFormat.ARGB32; AssetDatabase.ImportAsset(assetPath); AssetDatabase.Refresh(); } } } EditorUtility.ClearProgressBar(); }
void OnEnable() { drawCallTarget = target as DrawCallMinimizer; destroyOriginalGameObject = serializedObject.FindProperty("destroyOriginalGameObject"); textureAtlasProperties = serializedObject.FindProperty("_textureAtlasProperties"); skipAtlasingTextures = serializedObject.FindProperty("skipTextureAtlasing"); propertiesToLookFor = drawCallTarget.textureAtlasProperties; if (propertiesToLookFor == null) { propertiesToLookFor = new DrawCallMinimizerInfo(); } IEnumerable<string> propertiesList = ShaderPropertyUtility.GetUniqueShaderPropertyNames(drawCallTarget.GetComponentsInChildren<Renderer>().Select(X => X.sharedMaterial).Distinct()); //here we clear out properties that are no longer referenced IList<ShaderProperties> activeProperties = propertiesToLookFor.shaderPropertiesToLookFor.Where(x => propertiesList.Contains(x.propertyName)).ToList(); //then we figure out which properties still need to be added to the list propertiesList = propertiesList.Where(x => !activeProperties.Select(property => property.propertyName).Contains(x)); foreach (string s in propertiesList) { activeProperties.Add(new ShaderProperties(false, s)); } propertiesToLookFor.shaderPropertiesToLookFor = activeProperties; serializedObject.ApplyModifiedProperties(); ReimportNonReadonly(); //Reimport anything that is needed }
void OnEnable() { drawCallTarget = target as DrawCallMinimizer; destroyOriginalGameObject = serializedObject.FindProperty("destroyOriginalGameObject"); textureAtlasProperties = serializedObject.FindProperty("_textureAtlasProperties"); skipAtlasingTextures = serializedObject.FindProperty("skipTextureAtlasing"); propertiesToLookFor = drawCallTarget.textureAtlasProperties; if (propertiesToLookFor == null) { propertiesToLookFor = new DrawCallMinimizerInfo(); } IEnumerable <string> propertiesList = ShaderPropertyUtility.GetUniqueShaderPropertyNames(drawCallTarget.GetComponentsInChildren <Renderer>().Select(X => X.sharedMaterial).Distinct()); //here we clear out properties that are no longer referenced IList <ShaderProperties> activeProperties = propertiesToLookFor.shaderPropertiesToLookFor.Where(x => propertiesList.Contains(x.propertyName)).ToList(); //then we figure out which properties still need to be added to the list propertiesList = propertiesList.Where(x => !activeProperties.Select(property => property.propertyName).Contains(x)); foreach (string s in propertiesList) { activeProperties.Add(new ShaderProperties(false, s)); } propertiesToLookFor.shaderPropertiesToLookFor = activeProperties; serializedObject.ApplyModifiedProperties(); ReimportNonReadonly(); //Reimport anything that is needed }