Exemple #1
0
        public void SetPalette()
        {
            if (!texture || !texture.isReadable)
            {
                return;
            }

            PaletteTextureGenerator gen     = GetComponent <PaletteTextureGenerator>();
            HashSet <Color>         palette = new HashSet <Color>();

            for (int y = 0; y < texture.height; y++)
            {
                for (int x = 0; x < texture.width; x++)
                {
                    palette.Add(texture.GetPixel(x, y));
                }
            }
            gen.palette = new Color[palette.Count];
            int i = 0;

            foreach (Color c in palette)
            {
                gen.palette[i] = c;
                i++;
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            PaletteTextureGenerator gen = (PaletteTextureGenerator)target;
            int expectedSize            = gen.ExpectedPaletteComplexity();

            if (expectedSize >= COMPLEXITY_WARNING_THRESHOLD)
            {
                EditorGUILayout.HelpBox("These settings will generate a very complex dithered palette (" + expectedSize + " entries) and may crash Unity and your GPU. Consider lowering the dither depth or using a smaller palette", MessageType.Warning);
                if (warningOverride > 0 && GUILayout.Button("Override warning " + warningOverride))
                {
                    warningOverride--;
                }
            }
            else
            {
                warningOverride = 5;
            }
            if ((warningOverride <= 0 || expectedSize < COMPLEXITY_WARNING_THRESHOLD) && GUILayout.Button("Generate & Save Palette"))
            {
                Texture3D[] textures = gen.Generate();

                if (!AssetDatabase.IsValidFolder(ASSET_PATH + "/" + DITHERED_PATH))
                {
                    AssetDatabase.CreateFolder(ASSET_PATH, DITHERED_PATH);
                }
                AssetDatabase.CreateAsset(textures[0], ASSET_PATH + "/" + DITHERED_PATH + "/" + gen.name + "_primary.asset");
                AssetDatabase.CreateAsset(textures[1], ASSET_PATH + "/" + DITHERED_PATH + "/" + gen.name + "_secondary.asset");
                Debug.Log("Saved palettes to " + ASSET_PATH + "/" + DITHERED_PATH + "/" + gen.name);
            }
        }
Exemple #3
0
        public void SetPalette()
        {
            PaletteTextureGenerator gen = GetComponent <PaletteTextureGenerator>();
            int rDepth = (int)Mathf.Pow(2, redDepth);
            int gDepth = (int)Mathf.Pow(2, greenDepth);
            int bDepth = (int)Mathf.Pow(2, blueDepth);

            Color[] cols  = new Color[rDepth * gDepth * bDepth];
            int     index = 0;

            for (int r = 0; r < rDepth; r++)
            {
                for (int g = 0; g < gDepth; g++)
                {
                    for (int b = 0; b < bDepth; b++)
                    {
                        float red = 0f;
                        if (rDepth > 1)
                        {
                            red = r / (rDepth - 1f);
                        }
                        float green = 0f;
                        if (gDepth > 1)
                        {
                            green = g / (gDepth - 1f);
                        }
                        float blue = 0f;
                        if (bDepth > 1)
                        {
                            blue = b / (bDepth - 1f);
                        }
                        cols[index] = new Color(red, green, blue, 1f);
                        index++;
                    }
                }
            }
            gen.palette = cols;
        }