public static bool CreatePaletteMapAndKey(string outputPath, Texture2D sourceTexture, RBPaletteGroup suppliedPaletteGroup, bool overwriteExistingFiles, string paletteKeyFileName, string paletteMapFilename) { // If no palette key texture is provided, create a new one from the source image RBPalette basePalette = null; if (suppliedPaletteGroup == null) { basePalette = RBPalette.CreatePaletteFromTexture(sourceTexture); } else { RBPaletteDiff diff = suppliedPaletteGroup.DiffWithTexture(sourceTexture); if (diff.NumChanges > 0) { var result = EditorUtility.DisplayDialogComplex("Palettes Differ", $"Current BasePalette is different from the one that would generate from this texture. {diff.Insertions.Count} colors added and {diff.Deletions.Count} removed." + "Are you sure you want to sync this PaletteGroup to this texture?", "Yes", "No", "Cancel"); if (result == 0) { suppliedPaletteGroup.ApplyDiff(diff); } else if (result == 2) { return(false); } //suppliedPaletteGroup.ApplyDiff (diff); } basePalette = suppliedPaletteGroup.BasePalette; } // Create the palette map from the palette key PaletteMap palettemap; palettemap = new PaletteMap(sourceTexture, basePalette); if (suppliedPaletteGroup == null) { // Write PaletteGroup to disk try { string paletteGroupFilename = paletteKeyFileName + ".asset"; RBPaletteGroup createdGroup = RBPaletteCreator.CreatePaletteGroup(outputPath, paletteGroupFilename, overwriteExistingFiles); createdGroup.GroupName = paletteKeyFileName; createdGroup.SetBasePalette(basePalette); createdGroup.Locked = true; } catch (IOException) { throw new System.IO.IOException("Failed to write PaletteMap. A PaletteGroup already exists by the name: " + paletteKeyFileName); } } // Write PaletteMap to disk string paletteMapFilenameWithExtension = paletteMapFilename + ".png"; string fullPathToPaletteMapFile = outputPath + paletteMapFilenameWithExtension; palettemap.WriteToFile(fullPathToPaletteMapFile, overwriteExistingFiles); return(true); }
public void DiffPaletteGroupWithTexture() { CurrentDiff = PaletteGroup.DiffWithTexture(SourceTexture); }