Beispiel #1
0
    //Called by the BiomeColorGradientEditorWindow to keep a stack of undoStates
    public static BiomeColorGradient Clone(BiomeColorGradient gradient)
    {
        BiomeColorGradient clone = new BiomeColorGradient();

        clone.mimic(gradient);
        return(clone);
    }
Beispiel #2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Event guiEvent = Event.current; //Tracks inspector events like clicks and re-draws

        BiomeColorGradient biomeGradient = (BiomeColorGradient)fieldInfo.GetValue(property.serializedObject.targetObject);
        float labelWidth          = GUI.skin.label.CalcSize(label).x + 5; //THe 5 is just a buffer for looks
        Rect  gradientTextureRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height);

        if (guiEvent.type == EventType.Repaint)
        {
            GUI.Label(position, label); //Rendering the name of the field

            //We want to draw the biomeGradient gradient in the inspector, but GUI.draw texture is buggy.
            //So, we'll draw the gradent as a label instead
            GUIStyle gradientStyle = new GUIStyle();
            gradientStyle.normal.background = biomeGradient.GetTexture((int)position.width);
            GUI.Label(gradientTextureRect, GUIContent.none, gradientStyle);
        }
        else if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0) //0 is the left mouse button
        {
            if (gradientTextureRect.Contains(guiEvent.mousePosition))
            {
                BiomeColorGradientEditorWindow window = EditorWindow.GetWindow <BiomeColorGradientEditorWindow>();
                window.setGradient(biomeGradient);
                window.setBiome((Biome)property.serializedObject.targetObject);
            }
        }
    }
Beispiel #3
0
    //Copies all the properties of one gradient onto another
    public void mimic(BiomeColorGradient gradient)
    {
        forceClear();
        blendMode = gradient.blendMode;
        randomizeNewLayerColors = gradient.randomizeNewLayerColors;

        for (int i = 0; i < gradient.numberOfLayers; i++)
        {
            addLayer(gradient.getlayer(i).Color, gradient.getlayer(i).upperBound);
        }
    }
Beispiel #4
0
 public UndoState(BiomeColorGradient gradient, int selectedIndex)
 {
     this.gradient      = BiomeColorGradient.Clone(gradient);
     this.selectedIndex = selectedIndex;
 }
Beispiel #5
0
 public void setGradient(BiomeColorGradient grad)
 {
     biomeGradient = grad;
     undoStack.Clear();
 }