public override void OnInspectorGUI() { DrawDefaultInspector(); RBPaletteGroup targetRBPaletteGroup = (RBPaletteGroup)target; EditorGUILayout.Space(); EditorGUILayout.LabelField("Colors", EditorStyles.boldLabel); if (GUILayout.Button("Add Color", GUILayout.ExpandWidth(false))) { targetRBPaletteGroup.AddColor(); } 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("Palettes", EditorStyles.boldLabel); if (GUILayout.Button("Add Palette", GUILayout.ExpandWidth(false))) { targetRBPaletteGroup.AddPalette(); } paletteIndex = EditorGUILayout.IntSlider("Palette index: ", paletteIndex, 0, targetRBPaletteGroup.Count - 1); if (GUILayout.Button("Remove Palette At Index", GUILayout.ExpandWidth(false))) { targetRBPaletteGroup.RemovePaletteAtIndex(paletteIndex); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Utilities", EditorStyles.boldLabel); if (GUILayout.Button("Export As Texture", GUILayout.ExpandWidth(false))) { string outputPath = GetPathToAsset(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); } } } }
public static RBPaletteGroup CreateInstanceFromPaletteTexture(Texture2D paletteTexture, string groupPaletteName = DefaultGroupName) { RBPalette[] palettesInTexture = ExtractRBPalettesFromPaletteTexture(paletteTexture); // Create the paletteGroup with the base Palette RBPaletteGroup paletteGroup = CreateInstance(groupPaletteName, palettesInTexture [0]); for (int i = 1; i < palettesInTexture.Length; i++) { paletteGroup.AddPalette(palettesInTexture [i]); } return(paletteGroup); }