public void DrawGui() { GUILayout.BeginVertical(GUI.skin.box); using (new GUILayout.HorizontalScope()) { EditorGUILayout.TextField("Path to store atlases", _atlasesPath); if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { _atlasesPath = EditorUtility.OpenFolderPanel("Select folder", _atlasesPath, ""); _atlasesPath = _atlasesPath.Substring(_atlasesPath.IndexOf("Assets", StringComparison.Ordinal)); } } _format = (TextureImporterFormat)EditorGUILayout.EnumPopup("Texture format", _format); _compression = (TextureImporterCompression)EditorGUILayout.EnumPopup("Texture compression", _compression); if (GUILayout.Button("Apply compression to ALL textures in project")) { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to change all textures compression settings? This action cannot be undone!", "You bet!", "Hell, no!")) { var guids = AssetDatabase.FindAssets("t:Sprite"); var paths = guids.Select(AssetDatabase.GUIDToAssetPath).ToArray(); for (var i = 0; i < paths.Length; i++) { var path = paths[i]; if (!EditorUtility.DisplayCancelableProgressBar("Operation in progress", "Applying settings: " + Path.GetFileNameWithoutExtension(path), (float)i / paths.Length)) { TextureUtils.ApplyTextureCompression(path, Format, _compression); } else { EditorUtility.ClearProgressBar(); break; } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); } } GUILayout.EndVertical(); }
private void DrawSpritesCollectionGui(string atlasName, IList <Texture2D> sprites) { GUILayout.BeginHorizontal(GUI.skin.box); _foldoutsHelper[atlasName] = EditorGUILayout.Foldout(_foldoutsHelper[atlasName], atlasName + ", " + sprites.Count + " sprites"); if (GUILayout.Button("Process this scene", GUILayout.ExpandWidth(false))) { if (sprites.Count > 0) { MoveSprites(atlasName, sprites); #if UNITY_2017_1_OR_NEWER CreateAtlas(atlasName); #endif } } if (GUILayout.Button("Apply compression", GUILayout.ExpandWidth(false))) { foreach (var sprite in sprites) { var path = AssetDatabase.GetAssetPath(sprite); TextureUtils.ApplyTextureCompression(path, _settings.Format, _settings.Compression); } } GUILayout.EndHorizontal(); if (_foldoutsHelper[atlasName]) { foreach (var sprite in sprites) { DrawSpriteGui(sprite); } } }