public override void OnInspectorGUI() { DrawDefaultInspector(); string path = AssetDatabaseUtility.GetAssetDirectory(target); PaletteMapJob targetJob = (PaletteMapJob)target; bool generationDisabled = targetJob.PaletteGroup == null; // Palette Group Button EditorGUI.BeginDisabledGroup(!generationDisabled); if (GUILayout.Button("Create New PaletteGroup from Texture")) { targetJob.CreatePaletteGroupForTexture(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.Separator(); // Generate Palette Map Button EditorGUI.BeginDisabledGroup(generationDisabled); if (GUILayout.Button("Generate PaletteMap")) { try { RBPaletteMapper.CreatePaletteMapAndKey(path, targetJob.SourceTexture, targetJob.PaletteGroup, false, targetJob.OverwriteExistingPaletteMap, "Key", targetJob.PaletteMapName); Debug.Log("<color=green>Palette Map created successfully for job: </color>" + targetJob.name + "\n<color=green>Updated PaletteGroup: </color>" + targetJob.PaletteGroup); } catch (System.Exception e) { Debug.LogError(e, targetJob); } } EditorGUI.EndDisabledGroup(); }
public override void OnInspectorGUI() { RBPaletteGroup targetRBPaletteGroup = (RBPaletteGroup)target; //DrawDefaultInspector (); serializedObject.Update(); list.elementHeight = GetElementHeight(); list.DoLayoutList(); SerializedProperty lockedProperty = serializedObject.FindProperty("Locked"); lockedProperty.boolValue = EditorGUILayout.Toggle("Locked", lockedProperty.boolValue); SetGroupLocked(lockedProperty.boolValue); EditorGUILayout.Space(); EditorGUILayout.LabelField("Colors", EditorStyles.boldLabel); if (GUILayout.Button("Add Color", GUILayout.ExpandWidth(false))) { targetRBPaletteGroup.AddColor(RBPaletteGroup.DefaultNewColor); } colorIndex = EditorGUILayout.IntSlider("Color index: ", colorIndex, 0, targetRBPaletteGroup.NumColorsInPalette - 1); if (GUILayout.Button("Remove Color At Index", GUILayout.ExpandWidth(false))) { targetRBPaletteGroup.RemoveColorAtIndex(colorIndex); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Utilities", EditorStyles.boldLabel); if (GUILayout.Button("Export As Texture", GUILayout.ExpandWidth(false))) { string outputPath = AssetDatabaseUtility.GetAssetDirectory(targetRBPaletteGroup); string extension = ".png"; string filename = targetRBPaletteGroup.GroupName + extension; try { targetRBPaletteGroup.WriteToFile(outputPath + filename, false); } catch (System.AccessViolationException) { if (EditorUtility.DisplayDialog("Warning!", "This will overwrite the existing file, " + filename + ". Are you sure you want to export the texture?", "Yes", "No")) { targetRBPaletteGroup.WriteToFile(outputPath + filename, true); } } } serializedObject.ApplyModifiedProperties(); }
void OnGUI() { GUILayout.Label("Palette Map", EditorStyles.boldLabel); sourceTexture = EditorGUILayout.ObjectField("Source Texture", sourceTexture, typeof(Texture2D), false); bool sourceTextureChanged = lastSourceTexture != sourceTexture; if (sourceTextureChanged) { lastSourceTexture = sourceTexture; paletteMapFilename = sourceTexture.name + "_PaletteMap"; paletteKeyFilename = sourceTexture.name + "_PaletteGroup"; } if (sourceTexture != null) { paletteMapFilename = EditorGUILayout.TextField("Output Filename", paletteMapFilename); } GUILayout.Label("Palette Key", EditorStyles.boldLabel); paletteKeyOption = (PaletteKeyOption)EditorGUILayout.EnumPopup("Palette Key Creation: ", paletteKeyOption); switch (paletteKeyOption) { case PaletteKeyOption.GenerateNewPaletteKey: suppliedPalleteKey = null; if (sourceTexture != null) { paletteKeyFilename = EditorGUILayout.TextField("Output Filename", paletteKeyFilename); } sortPalette = EditorGUILayout.Toggle("Sort PaletteKey", sortPalette); break; case PaletteKeyOption.SupplyCustomPaletteKey: suppliedPalleteKey = EditorGUILayout.ObjectField("Linked Palette Group", suppliedPalleteKey, typeof(RBPaletteGroup), false); sortPalette = false; break; } GUILayout.Label("Options", EditorStyles.boldLabel); overwriteExistingFiles = EditorGUILayout.Toggle("Overwite Existing files", overwriteExistingFiles); if (GUILayout.Button("Build")) { if (sourceTexture == null) { Debug.LogError("RBPaletteMapper Error: No source texture specified"); return; } // Validate source texture Texture2D inTexture = (Texture2D)sourceTexture; try { RBPaletteMapper.ValidateSourceTexture(inTexture); } catch (System.BadImageFormatException e) { Debug.LogError("RBPaletteMapper Error: " + e.Message); return; } // Validate or skip Palette Key RBPaletteGroup inPaletteKey = null; if (paletteKeyOption == PaletteKeyOption.SupplyCustomPaletteKey) { if (suppliedPalleteKey == null) { Debug.LogError("RBPaletteMapper Error: Trying to use custom palette key but no palette key specified." + "\nPlease select a RBPaletteGroup to use as the Palette Key."); return; } inPaletteKey = (RBPaletteGroup)suppliedPalleteKey; try { RBPaletteMapper.ValidatePaletteGroup(inPaletteKey); } catch { Debug.LogError("Unknown PaletteMap Error encountered while Validating supplied PaletteGroup."); return; } } string path = AssetDatabaseUtility.GetAssetDirectory(inTexture); try { RBPaletteMapper.CreatePaletteMapAndKey(path, inTexture, inPaletteKey, sortPalette, overwriteExistingFiles, paletteKeyFilename, paletteMapFilename); Debug.Log("<color=green>Palette Map and Key for file " + inTexture.name + " created successfully</color>"); // TODO: Better error handling messages } catch (System.NotSupportedException e) { LogError(e.Message, e); } catch (System.ArgumentException e) { LogError(e.Message, e); } catch (System.AccessViolationException e) { LogError(e.Message, e); } catch (System.IO.IOException e) { LogError("Encountered IO Exception: " + e.Message, e); } catch (System.Exception e) { LogError("Encountered unknown error: " + e.Message, e); } } }
public void CreatePaletteGroupForTexture() { RBPaletteGroup paletteGroup = RBPaletteCreator.ExtractPaletteFromTexture(SourceTexture, AssetDatabaseUtility.GetAssetDirectory(this), name + "_PaletteGroup.asset"); if (paletteGroup != null) { paletteGroup.BasePalette.Locked = true; paletteGroup.Locked = true; PaletteGroup = paletteGroup; } }