void OnGUI() { if (window == null) { this.Close(); return; } if (setToPublishMenu) { presetOrPublish = 1; setToPublishMenu = false; } EditorGUILayout.BeginVertical(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false); EditorGUILayout.Separator(); EditorGUILayout.LabelField(playgroundLanguage.playgroundPresetWizard, EditorStyles.largeLabel, GUILayout.Height(20)); EditorGUILayout.Separator(); GUILayout.BeginVertical("box"); int tmpPresetOrPublish = presetOrPublish; presetOrPublish = GUILayout.Toolbar(presetOrPublish, new string[] { playgroundLanguage.preset, playgroundLanguage.publish }, EditorStyles.toolbarButton); if (presetOrPublish == 0) { EditorGUILayout.HelpBox(playgroundLanguage.presetText, MessageType.Info); } else { EditorGUILayout.HelpBox(playgroundLanguage.publishPresetText, MessageType.Info); } if (tmpPresetOrPublish != presetOrPublish && presetOrPublish == 1) { RefreshFromPresetList(); } if (presetOrPublish == 1) { GUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button(playgroundLanguage.publishingGuide, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { Application.OpenURL("http://polyfied.com/products/particle-playground/playground-resources/publishing-guide/"); } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (presetOrPublish == 0) { EditorGUILayout.PrefixLabel(playgroundLanguage.particleSystem); // Particle System to become a preset GameObject selectedObj = particleSystemObject; particleSystemObject = EditorGUILayout.ObjectField(particleSystemObject, typeof(GameObject), true) as GameObject; if (particleSystemObject != selectedObj) { // Check if this is a Particle Playground System if (particleSystemObject != null) { // Set new name if user hasn't specified one if (particleSystemName == "") { particleSystemName = particleSystemObject.name; } showError1 = false; } else { showError1 = true; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(playgroundLanguage.icon); particleSystemIcon = EditorGUILayout.ObjectField(particleSystemIcon, typeof(Texture2D), false) as Texture2D; GUILayout.EndHorizontal(); particleSystemName = EditorGUILayout.TextField(playgroundLanguage.nameText, particleSystemName); selectedCategory = EditorGUILayout.IntPopup(playgroundLanguage.category, selectedCategory, categories, categoryValues); childConnected = EditorGUILayout.Toggle(playgroundLanguage.childConnected, childConnected); } else { GUILayout.EndHorizontal(); EditorGUILayout.PrefixLabel(playgroundLanguage.presets); // Selection of presets to export totalSelected = 0; presetScroll = EditorGUILayout.BeginScrollView(presetScroll); for (int c = 0; c < PlaygroundParticleWindowC.presetCategories.Count; c++) { for (int i = 0; i < PlaygroundParticleWindowC.presetCategories[c].presetObjects.Count; i++) { GUILayout.BeginHorizontal(); PresetObjectC thisPreset = PlaygroundParticleWindowC.presetCategories[c].presetObjects[i]; thisPreset.selected = GUILayout.Toggle(thisPreset.selected, "", GUILayout.MaxWidth(24f)); if (GUILayout.Button(thisPreset.presetImage, EditorStyles.label, new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(24) })) { thisPreset.selected = !thisPreset.selected; } if (GUILayout.Button(thisPreset.presetObject.name, EditorStyles.label)) { thisPreset.selected = !thisPreset.selected; } if (thisPreset.selected) { totalSelected++; } GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.Separator(); GUI.enabled = presetOrPublish == 0 || presetOrPublish == 1 && totalSelected > 0; GUILayout.BeginHorizontal(); if (GUILayout.Button(playgroundLanguage.create, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { if (particleSystemName != null && particleSystemName != "") { particleSystemName = particleSystemName.Trim(); } if (presetOrPublish == 0 && particleSystemObject != null && particleSystemName != "") { string tmpName = particleSystemObject.name; particleSystemObject.name = particleSystemName; CreatePreset(); particleSystemObject.name = tmpName; } else if (presetOrPublish == 1) { CreatePublicPreset(); } } EditorGUILayout.Separator(); if (presetOrPublish == 1) { EditorGUILayout.LabelField(playgroundLanguage.selected + ": " + totalSelected + "/" + PlaygroundParticleWindowC.presetNames.Count, EditorStyles.miniLabel, new GUILayoutOption[] { GUILayout.ExpandWidth(false), GUILayout.MaxWidth((playgroundLanguage.selected.Length * 6f) + 30f) }); } GUILayout.EndHorizontal(); GUI.enabled = true; GUILayout.EndVertical(); // Space for error messages if (showError1 && particleSystemObject != null) { EditorGUILayout.HelpBox(playgroundLanguage.gameObjectIsNotPlayground, MessageType.Error); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
void OnGUI() { if (window == null) { this.Close(); return; } EditorGUILayout.BeginVertical(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false); EditorGUILayout.Separator(); EditorGUILayout.LabelField(playgroundLanguage.presetManager, EditorStyles.largeLabel, GUILayout.Height(20)); EditorGUILayout.Separator(); GUILayout.BeginVertical("box"); EditorGUILayout.HelpBox(playgroundLanguage.categoriesInfo, MessageType.Info); EditorGUILayout.Separator(); for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++) { GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); PresetCategory thisCategory = PlaygroundParticleWindowC.presetCategories[i]; bool isProtectedFolder = thisCategory.categoryName == "Uncategorized" || thisCategory.categoryName == "Resources"; // Category unfold thisCategory.foldout = GUILayout.Toggle(thisCategory.foldout, "", EditorStyles.foldout, GUILayout.MaxWidth(16f)); // Category name GUI.enabled = !isProtectedFolder; GUI.SetNextControlName(thisCategory.categoryName); thisCategory.tmpNewName = EditorGUILayout.TextField(thisCategory.tmpNewName, EditorStyles.toolbarTextField); GUI.enabled = true; if (!isProtectedFolder && thisCategory.tmpNewName != thisCategory.categoryName) { if (GUILayout.Button(playgroundLanguage.rename, GUILayout.ExpandWidth(false))) { bool isValidFolderName = IsValidFolderName(thisCategory.tmpNewName); if (isValidFolderName) { if (AssetDatabase.RenameAsset("Assets/" + thisCategory.categoryLocation, thisCategory.tmpNewName).Length == 0) { AssetDatabase.Refresh(); // Succesfully renamed thisCategory.categoryName = thisCategory.tmpNewName; requestFocusControl = true; focusControlName = thisCategory.categoryName; return; } else { thisCategory.tmpNewName = thisCategory.categoryName; } } else { thisCategory.tmpNewName = thisCategory.categoryName; } } } // Show amount of selected presets int selectedPresetsInCategory = 0; for (int x = 0; x < thisCategory.presetObjects.Count; x++) { if (thisCategory.presetObjects[x].selected) { selectedPresetsInCategory++; } } GUI.enabled = selectedPresetsInCategory > 0; GUILayout.Label("(" + selectedPresetsInCategory.ToString() + "/" + thisCategory.presetObjects.Count.ToString() + ")"); GUI.enabled = true; EditorGUILayout.Separator(); // Remove category GUI.enabled = !isProtectedFolder; if (GUILayout.Button("-", EditorStyles.toolbarButton, new GUILayoutOption[] { GUILayout.Width(18), GUILayout.Height(16) }) && !isProtectedFolder) { if (EditorUtility.DisplayDialog(playgroundLanguage.removeCategory, thisCategory.categoryName + " " + playgroundLanguage.removeCategoryText, playgroundLanguage.yes, playgroundLanguage.no)) { // Move all presets contained to "Uncategorized" (parent folder) before removing the category folder string[] presetsInCategory = Directory.GetFiles(Application.dataPath + "/" + thisCategory.categoryLocation); foreach (string presetLoc in presetsInCategory) { string convertedPresetPath = presetLoc.Substring(Application.dataPath.Length - 6); Object presetPathObject = (Object)AssetDatabase.LoadAssetAtPath(convertedPresetPath, typeof(Object)); if (presetPathObject != null && (presetPathObject.GetType().Name) == "GameObject") { AssetDatabase.MoveAsset(convertedPresetPath, "Assets/" + playgroundSettings.playgroundPath + playgroundSettings.examplePresetPath + presetPathObject.name); } } AssetDatabase.MoveAssetToTrash("Assets/" + thisCategory.categoryLocation); AssetDatabase.Refresh(); GUI.FocusControl(null); return; } } GUI.enabled = true; GUILayout.EndHorizontal(); // List of presets if (thisCategory.foldout) { EditorGUILayout.Separator(); // Mixed selection if (thisCategory.presetObjects.Count > 0) { EditorGUI.showMixedValue = selectedPresetsInCategory > 0 && selectedPresetsInCategory < thisCategory.presetObjects.Count; bool multiSelect = selectedPresetsInCategory > 0; EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4f); multiSelect = EditorGUILayout.Toggle(multiSelect); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { for (int x = 0; x < thisCategory.presetObjects.Count; x++) { thisCategory.presetObjects[x].selected = multiSelect; } } EditorGUI.showMixedValue = false; } EditorGUI.indentLevel++; if (thisCategory.presetObjects.Count > 0) { for (int x = 0; x < thisCategory.presetObjects.Count; x++) { GUILayout.BeginHorizontal("box"); PresetObjectC thisPreset = thisCategory.presetObjects[x]; thisPreset.selected = GUILayout.Toggle(thisPreset.selected, "", GUILayout.MaxWidth(24f)); if (GUILayout.Button(thisPreset.presetImage, EditorStyles.label, new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(24) }) || GUILayout.Button(thisPreset.presetObject.name, EditorStyles.label)) { EditorGUIUtility.PingObject(thisPreset.presetObject); } GUILayout.EndHorizontal(); } } else { GUI.enabled = false; GUILayout.Label(playgroundLanguage.empty); GUI.enabled = true; } EditorGUI.indentLevel--; } GUILayout.EndVertical(); } // New category creation EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); if (GUILayout.Button(playgroundLanguage.create, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { if (IsValidFolderName(createCategoryName)) { createCategoryName = createCategoryName.Trim(); string createdFolder = AssetDatabase.CreateFolder("Assets/" + playgroundSettings.playgroundPath + (playgroundSettings.examplePresetPath).Substring(0, playgroundSettings.examplePresetPath.Length - 1), createCategoryName); if (createdFolder != null && createdFolder.Length > 0) { AssetDatabase.Refresh(); foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { if (AssetDatabase.AssetPathToGUID("Assets/" + cat.categoryLocation) == createdFolder) { cat.foldout = true; requestFocusControl = true; focusControlName = cat.categoryName; break; } } createCategoryName = "New Category"; return; } } } createCategoryName = EditorGUILayout.TextField(createCategoryName, EditorStyles.toolbarTextField); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndScrollView(); int selectedPresets = 0; bool isResourcesPresetsOnly = true; for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++) { for (int x = 0; x < PlaygroundParticleWindowC.presetCategories[i].presetObjects.Count; x++) { if (PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].selected) { if (PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].example) { isResourcesPresetsOnly = false; } selectedPresets++; } } } // Bottom toolbar for selected presets if (selectedPresets > 0) { EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(playgroundLanguage.selected + ": " + selectedPresets.ToString(), GUILayout.MaxWidth(90)); // Move selected presets if (categoryNames == null || categoryNames.Length != PlaygroundParticleWindowC.presetCategories.Count + 1) { categoryNames = new string[PlaygroundParticleWindowC.presetCategories.Count + 1]; categoryNames[0] = playgroundLanguage.move + "..."; for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++) { categoryNames[i + 1] = PlaygroundParticleWindowC.presetCategories[i].categoryName; } } int selectedMoveCategory = 0; EditorGUI.BeginChangeCheck(); selectedMoveCategory = EditorGUILayout.Popup(selectedMoveCategory, categoryNames, EditorStyles.toolbarPopup); if (EditorGUI.EndChangeCheck()) { if (selectedMoveCategory > 0) { List <Object> movedObjects = new List <Object>(); foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { foreach (PresetObjectC obj in cat.presetObjects) { if (obj.selected) { movedObjects.Add(obj.presetObject); AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(obj.presetObject), "Assets/" + PlaygroundParticleWindowC.presetCategories[selectedMoveCategory - 1].categoryLocation + "/" + obj.presetObject.name); } } } AssetDatabase.Refresh(); // Select the moved objects once again for less confusion foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { foreach (PresetObjectC obj in cat.presetObjects) { if (movedObjects.Contains(obj.presetObject)) { obj.selected = true; } } } // Open the index, correct if 'Uncategorized' got removed in the process int openIndex = selectedMoveCategory - 1 < PlaygroundParticleWindowC.presetCategories.Count? selectedMoveCategory - 1 : selectedMoveCategory - 2; PlaygroundParticleWindowC.presetCategories[openIndex].foldout = true; } } GUILayout.Space(4f); // Convert selected presets to Resources GUI.enabled = !isResourcesPresetsOnly; if (GUILayout.Button(playgroundLanguage.convertTo + " " + playgroundLanguage.resources, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { if (EditorUtility.DisplayDialog(playgroundLanguage.convertPresetsIntoResources, playgroundLanguage.convertPresetsIntoResourcesText, playgroundLanguage.yes, playgroundLanguage.no)) { List <Object> convertedObjects = new List <Object>(); foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { foreach (PresetObjectC obj in cat.presetObjects) { if (obj.selected) { if (!Directory.Exists(Application.dataPath + "/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath)) { Directory.CreateDirectory(Application.dataPath + "/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath); AssetDatabase.Refresh(); } convertedObjects.Add(obj.presetObject); AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(obj.presetObject), "Assets/" + playgroundSettings.playgroundPath + playgroundSettings.presetPath + obj.presetObject.name); } } } // Select the converted objects once again for less confusion foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { foreach (PresetObjectC obj in cat.presetObjects) { if (convertedObjects.Contains(obj.presetObject)) { obj.selected = true; } } } PlaygroundParticleWindowC.presetCategories[PlaygroundParticleWindowC.presetCategories.Count - 1].foldout = true; } } GUI.enabled = true; GUILayout.Space(4f); // Remove selected presets if (GUILayout.Button(playgroundLanguage.remove, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { if (EditorUtility.DisplayDialog(playgroundLanguage.removeSelectedPresets, playgroundLanguage.removeSelectedPresetsText, playgroundLanguage.yes, playgroundLanguage.no)) { foreach (PresetCategory cat in PlaygroundParticleWindowC.presetCategories) { foreach (PresetObjectC obj in cat.presetObjects) { if (obj.selected) { AssetDatabase.MoveAssetToTrash(AssetDatabase.GetAssetPath(obj.presetObject)); } } } } } GUILayout.Space(4f); // Publish selected presets if (GUILayout.Button(playgroundLanguage.publish, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { PlaygroundCreatePresetWindowC.ShowWindowPublish(); } EditorGUILayout.Separator(); // Deselect selected presets if (GUILayout.Button(playgroundLanguage.deselectAll, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { for (int i = 0; i < PlaygroundParticleWindowC.presetCategories.Count; i++) { for (int x = 0; x < PlaygroundParticleWindowC.presetCategories[i].presetObjects.Count; x++) { PlaygroundParticleWindowC.presetCategories[i].presetObjects[x].selected = false; } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); if (requestFocusControl) { EditorGUI.FocusTextInControl(focusControlName); requestFocusControl = false; } }