private void DrawFloodStepGUI(FloodStep step, int i)
        {
            using (new GUILayout.VerticalScope("box"))
            {
                using (new GUILayout.HorizontalScope("helpbox"))
                {
                    step.foldout = EditorGUILayout.Foldout(step.foldout, $"Step {i}:");

                    using (new EditorGUI.DisabledGroupScope(floodSteps.Count == 1))
                        if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(18)))
                        {
                            floodSteps.RemoveAt(i);
                            goto Skip;
                        }
                }

                if (step.foldout)
                {
                    EditorGUI.indentLevel++;
                    for (int j = 0; j < step.coordinates.Count; j++)
                    {
                        using (new GUILayout.HorizontalScope("box"))
                        {
                            step.coordinates[j] = EditorGUILayout.Vector2IntField(string.Empty, step.coordinates[j]);
                            if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(18)))
                            {
                                step.coordinates.RemoveAt(j);
                            }
                        }
                    }
                    if (GUILayout.Button("+", "toolbarbutton"))
                    {
                        step.coordinates.Add(new Vector2Int());
                    }

                    EditorGUI.indentLevel--;
                }
                Skip :;
            }
        }
        public static void GenerateFilledTexture(Texture2D texture)
        {
            if (!loopGradient)
            {
                gradientDistribution = 1;
            }
            if (gradientType == GradientType.DataGradient)
            {
                rangeLowerBound = 1;
                rangeUpperBound = 255;
            }

            int width = texture.width;

            modifiedBoundRange = rangeUpperBound / 255 - rangeLowerBound / 255;
            Texture2D gradientTexture = GetColors(texture, out Color[] ogColors);

            GradientFillPixel[] gradientPixels = new GradientFillPixel[ogColors.Length];

            Queue <GradientFillPixel> pixelsToExpand = new Queue <GradientFillPixel>();

            for (int i = 0; i < ogColors.Length; i++)
            {
                gradientPixels[i] = new GradientFillPixel(ogColors[i], i);
                if (!gradientPixels[i].isLimit && gradientPixels[i].isFilled)
                {
                    pixelsToExpand.Enqueue(gradientPixels[i]);
                }
            }

            if (pixelsToExpand.Count == 0)
            {
                Debug.LogWarning("<color=red>[GPFiller]</color> No start pixels were found! If start pixels exist, try adjusting the color tolerance.");
            }

            int floodIndex        = 0;
            int currentStackCount = pixelsToExpand.Count;
            int nextStackCount    = 0;

            bool IsValidFillIndex(int index, out GradientFillPixel pixelToFill)
            {
                if (index >= 0 && index < ogColors.Length)
                {
                    pixelToFill = gradientPixels[index];
                    if (!pixelToFill.isLimit && !pixelToFill.isFilled)
                    {
                        pixelsToExpand.Enqueue(pixelToFill);
                        nextStackCount++;
                        return(true);
                    }
                }

                pixelToFill = null;
                return(false);
            }

            void FillIndex(GradientFillPixel fillerPixel, int index)
            {
                if (!IsValidFillIndex(index, out GradientFillPixel nextPixel))
                {
                    return;
                }
                nextPixel.gradientValue = fillerPixel.gradientValue + gradientDistribution;
                nextPixel.isFilled      = true;
            }

            while (pixelsToExpand.Any())
            {
                FloodStep currentStep = floodSteps[floodIndex % floodSteps.Count];
                var       pixel       = pixelsToExpand.Dequeue();

                foreach (var coord in currentStep.coordinates)
                {
                    int finalX = (pixel.arrayIndex % width) + coord.x;
                    if (finalX < 0 || finalX >= width)
                    {
                        continue;
                    }

                    FillIndex(pixel, pixel.arrayIndex + coord.x + width * coord.y);
                }

                currentStackCount--;
                if (currentStackCount == 0)
                {
                    currentStackCount = nextStackCount;
                    nextStackCount    = 0;
                    floodIndex++;
                }
            }


            float maxGradientValue = gradientPixels.Max(p => p.gradientValue);

            if (gradientType == GradientType.DataGradient)
            {
                maxGradientValue /= 4;
            }

            for (int i = 0; i < ogColors.Length; i++)
            {
                var f = gradientPixels[i].GetFloatValue(maxGradientValue);

                if (f == 0)
                {
                    ogColors[i] = Color.clear;
                }
                else
                {
                    if (gradientType == GradientType.TintedGradient)
                    {
                        ogColors[i] = new Color(f * tintColor.r, f * tintColor.g, f * tintColor.b, gradientPixels[i].isLimit ? 1 : (applyGradientAlpha ? f : 1) * tintColor.a);
                    }
                    else if (gradientType == GradientType.GradientGradient)
                    {
                        Color gradColor = gradientColor.Evaluate(f);
                        gradColor.a = gradientPixels[i].isLimit ? 1 : (applyGradientAlpha ? f : 1) * gradColor.a;
                        ogColors[i] = gradColor;
                    }
                    else
                    {
                        if (f <= 1)
                        {
                            ogColors[i] = new Color(f % 1, 0, 0, 0);
                        }

                        else if (f <= 2)
                        {
                            ogColors[i] = new Color(1, f % 1, 0, 0);
                        }

                        else if (f <= 3)
                        {
                            ogColors[i] = new Color(1, 1, f % 1, 0);
                        }

                        else
                        {
                            ogColors[i] = new Color(1, 1, 1, f % 1);
                        }
                    }
                }
            }

            gradientTexture.SetPixels(ogColors);
            gradientTexture.Apply();

            string assetPath = AssetDatabase.GetAssetPath(pathTexture);
            string ext       = Path.GetExtension(assetPath);

            byte[] data;
            switch (ext)
            {
            case ".jpeg" when !applyGradientAlpha && gradientType != GradientType.DataGradient:
            case ".jpg" when !applyGradientAlpha && gradientType != GradientType.DataGradient:
                ext  = ".jpg";
                data = gradientTexture.EncodeToJPG(100);
                break;

            case ".tga":
                data = gradientTexture.EncodeToTGA();
                break;

            default:
                ext  = ".png";
                data = gradientTexture.EncodeToPNG();
                break;
            }


            DestroyImmediate(gradientTexture);

            string savePath = AssetDatabase.GenerateUniqueAssetPath($"{Path.GetDirectoryName(assetPath)}/{pathTexture.name}{ext}");

            SaveTexture(data, savePath);
            CopyTextureSettings(assetPath, savePath);
        }