Esempio n. 1
0
    public RBPaletteDiff DiffWithTexture(Texture2D textureToDiff)
    {
        RBPalette     paletteFromTexture = RBPalette.CreatePaletteFromTexture(textureToDiff);
        RBPaletteDiff diff = RBPaletteDiff.Diff(BasePalette, paletteFromTexture);

        return(diff);
    }
        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);
        }
Esempio n. 3
0
    public void ApplyDiff(RBPaletteDiff diff)
    {
        // Unlock the PaletteGroup so that we can edit it.
        bool wasLocked = Locked;

        Locked = false;

        // Add new colors to the palette
        for (int i = 0; i < diff.Insertions.Count; i++)
        {
            AddColor(diff.Insertions [i]);
        }

        // Remove unused colors
        for (int i = 0; i < diff.Deletions.Count; i++)
        {
            int unusedColorIndex = BasePalette.IndexOf(diff.Deletions [i]);
            RemoveColorAtIndex(unusedColorIndex);
        }

        // Relock the palette group
        Locked = wasLocked;
    }
Esempio n. 4
0
    public static RBPaletteDiff Diff(RBPalette paletteA, RBPalette paletteB)
    {
        RBPaletteDiff diffResults = new RBPaletteDiff();

        // Find deletions (colors in A that aren't in B)
        for (int i = 0; i < paletteA.Count; i++)
        {
            if (!paletteB.ContainsColor(paletteA[i]))
            {
                diffResults.Deletions.Add(paletteA[i]);
            }
        }

        // Find insertions (colors in B that aren't in A)
        for (int i = 0; i < paletteB.Count; i++)
        {
            if (!paletteA.ContainsColor(paletteB[i]))
            {
                diffResults.Insertions.Add(paletteB[i]);
            }
        }

        return(diffResults);
    }
Esempio n. 5
0
 public void DiffPaletteGroupWithTexture()
 {
     CurrentDiff = PaletteGroup.DiffWithTexture(SourceTexture);
 }