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);
        }
Пример #2
0
    public void CreatePaletteGroupForTexture()
    {
        RBPaletteGroup paletteGroup = RBPaletteCreator.ExtractPaletteFromTexture(SourceTexture, AssetDatabaseUtility.GetAssetDirectory(this),
                                                                                 name + "_PaletteGroup.asset");

        if (paletteGroup != null)
        {
            paletteGroup.Locked = true;
            PaletteGroup        = paletteGroup;
        }
    }
Пример #3
0
        public static void CreatePaletteMapAndKey(string outputPath, Texture2D sourceTexture, RBPaletteGroup suppliedPaletteGroup,
                                                  bool sortPaletteKey, 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);
                if (sortPaletteKey)
                {
                    basePalette.SortByGrayscale();
                }
            }
            else
            {
                // Sync the palette group up with the texture
                suppliedPaletteGroup.SyncWithTexture(sourceTexture);
                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.BasePalette.Locked = true;
                    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);
        }