public void OnGUI()
        {
            changed = false;
            if (focusedMat != null)
            {
                XSStyles.ShurikenHeader("Current Material: " + focusedMat.name);
            }
            else
            {
                XSStyles.ShurikenHeader("Current Material: None");
            }

            if (preButton == null)
            {
                iconToolbarPlus  = EditorGUIUtility.IconContent("Toolbar Plus", "Add Gradient");
                iconToolbarMinus = EditorGUIUtility.IconContent("Toolbar Minus", "Remove Gradient");
                preButton        = new GUIStyle("RL FooterButton");
                buttonBackground = new GUIStyle("RL Header");
            }

            if (gradients.Count == 0)
            {
                gradients.Add(new Gradient());
                gradients.Add(new Gradient());
                gradients.Add(new Gradient());
                gradients.Add(new Gradient());
                gradients.Add(new Gradient());
            }

            if (grad_index_reorderable == null)
            {
                makeReorderedList();
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            Rect  r         = EditorGUILayout.GetControlRect();
            float rightEdge = r.xMax;
            float leftEdge  = rightEdge - 48f;

            r = new Rect(leftEdge, r.y, rightEdge - leftEdge, r.height);
            if (Event.current.type == EventType.Repaint)
            {
                buttonBackground.Draw(r, false, false, false, false);
            }
            leftEdge += 18f;
            EditorGUI.BeginDisabledGroup(gradients_index.Count == 5);
            bool addE = GUI.Button(new Rect(leftEdge + 4, r.y, 25, 13), iconToolbarPlus, preButton);

            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(gradients_index.Count == 1);
            bool removeE = GUI.Button(new Rect(leftEdge - 19, r.y, 25, 13), iconToolbarMinus, preButton);

            EditorGUI.EndDisabledGroup();

            if (addE)
            {
                grad_index_reorderable.index++;
                int wat = 0;
                for (int i = 0; i < 5; i++)
                {
                    if (!gradients_index.Contains(i))
                    {
                        wat = i;
                        break;
                    }
                }
                gradients_index.Add(wat);
                changed = true;
            }
            if (removeE)
            {
                gradients_index.Remove(gradients_index[gradients_index.Count - 1]);
                grad_index_reorderable.index--;
                changed = true;
            }

            GUIStyle button = new GUIStyle(EditorStyles.miniButton);

            button.normal = !reorder ? EditorStyles.miniButton.normal : EditorStyles.miniButton.onNormal;
            if (GUILayout.Button(new GUIContent("Reorder", "Don't use Reorder if you want to undo a gradient change"), button, GUILayout.ExpandWidth(false)))
            {
                reorder = !reorder;
            }
            GUILayout.EndHorizontal();

            SerializedObject serializedObject = new SerializedObject(this);

            if (reorder)
            {
                grad_index_reorderable.DoLayoutList();
            }
            else
            {
                SerializedProperty colorGradients = serializedObject.FindProperty("gradients");
                if (colorGradients.arraySize == 5)
                {
                    for (int i = 0; i < gradients_index.Count; i++)
                    {
                        Rect _r = EditorGUILayout.GetControlRect();
                        _r.x      += 16f;
                        _r.width  -= 2f + 16f;
                        _r.height += 5f;
                        _r.y      += 2f + (3f * i);
                        EditorGUI.PropertyField(_r, colorGradients.GetArrayElementAtIndex(gradients_index[i]), new GUIContent(""));
                    }
                    GUILayout.Space(Mathf.Lerp(9f, 24f, gradients_index.Count / 5f));
                }
            }
            if (serializedObject.ApplyModifiedProperties())
            {
                changed = true;
            }

            if (oldFocusedMat != focusedMat)
            {
                changed = true;
                if (this.oldTexture != null)
                {
                    if (this.oldTexture == EditorGUIUtility.whiteTexture)
                    {
                        this.oldTexture = null;
                    }
                    oldFocusedMat.SetTexture(rampProperty, this.oldTexture);
                    this.oldTexture = null;
                }
                oldFocusedMat = focusedMat;
            }

            Resolutions oldRes = res;

            res = (Resolutions)EditorGUILayout.EnumPopup("Resolution: ", res);
            if (oldRes != res)
            {
                changed = true;
            }

            int width  = (int)res;
            int height = 30;

            if (gradients_index.Count == 1)
            {
                height = 8;
            }
            else
            {
                height = 150;
            }
            if (tex == null)
            {
                tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
            }

            bool old_isLinear = isLinear;

            drawAdvancedOptions();
            if (old_isLinear != isLinear)
            {
                changed = true;
            }

            if (manualMaterial)
            {
                focusedMat = (Material)EditorGUILayout.ObjectField(new GUIContent("", ""), focusedMat, typeof(Material), true);
            }

            if (focusedMat != null)
            {
                if (focusedMat.HasProperty("_Ramp"))
                {
                    rampProperty = "_Ramp";
                }
                else
                {
                    rampProperty = EditorGUILayout.TextField("Ramp Property Name", rampProperty);
                    if (!focusedMat.HasProperty(rampProperty))
                    {
                        GUILayout.Label("Property not found!");
                    }
                }
            }

            if (changed)
            {
                updateTexture(width, height);
                if (focusedMat != null)
                {
                    if (focusedMat.HasProperty(rampProperty))
                    {
                        if (this.oldTexture == null)
                        {
                            if (focusedMat.GetTexture(rampProperty) == null)
                            {
                                this.oldTexture = EditorGUIUtility.whiteTexture;
                            }
                            else
                            {
                                this.oldTexture = focusedMat.GetTexture(rampProperty);
                            }
                        }
                        tex.wrapMode = TextureWrapMode.Clamp;
                        tex.Apply(false, false);
                        focusedMat.SetTexture(rampProperty, tex);
                    }
                }
            }

            XSStyles.Separator();
            drawMGInputOutput();


            if (GUILayout.Button("Save Ramp"))
            {
                finalFilePath = XSStyles.findAssetPath(finalFilePath);
                string path = EditorUtility.SaveFilePanel("Save Ramp as PNG", finalFilePath + "/Textures/Shadow Ramps/Generated", "gradient", "png");
                if (path.Length != 0)
                {
                    updateTexture(width, height);
                    bool success = GenTexture(tex, path);
                    if (success)
                    {
                        if (focusedMat != null)
                        {
                            string  s    = path.Substring(path.IndexOf("Assets"));
                            Texture ramp = AssetDatabase.LoadAssetAtPath <Texture>(s);
                            if (ramp != null)
                            {
                                focusedMat.SetTexture(rampProperty, ramp);
                                this.oldTexture = null;
                            }
                        }
                    }
                }
            }
            drawHelpText();
        }