Click or drag to resize

GuiColorScope Class

A utility class to render big disabled blocks of GUI.
Inheritance Hierarchy
SystemObject
  KSPDev.GUIUtilsGuiColorScope

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.5 (in KSPDev_Utils.2.5.dll) Version: 2.5 for KSP v1
Syntax
C#
public class GuiColorScope : IDisposable
Request Example View Source

The GuiColorScope type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleGuiColorScope
Stores the old state and sets a new one.
Top
Methods
  NameDescription
Public methodDispose
Restores the colors that were set before the scope started.
Top
Examples
public class GuiColorScopeDemo1 : MonoBehaviour {
  void OnGUI() {
    // Set any color settings.
    GUI.contentColor = Color.white;
    GUI.backgroundColor = Color.black;
    GUILayout.Button("B&W button");

    // Make any changes to the colors in this block.
    using (new GuiColorScope()) {
      GUI.color = Color.red;
      GUILayout.Button("Red button");
      GUI.contentColor = Color.green;
      GUI.backgroundColor = Color.blue;
      GUILayout.Button("Green on Blue button");
    }

    // From here all the colors will be restored back.
    GUILayout.Button("B&W button");
  }
}
Examples
public class GuiColorScopeDemo2 : MonoBehaviour {
  void OnGUI() {
    // Set any color settings.
    GUI.contentColor = Color.white;
    GUI.backgroundColor = Color.black;
    GUILayout.Button("B&W button");

    using (new GuiColorScope(color: Color.red)) {
      GUILayout.Button("Red button");
    }
    using (new GuiColorScope(backgroundColor: Color.red)) {
      GUILayout.Button("White on Red button");
    }
    using (new GuiColorScope(contentColor: Color.red)) {
      GUILayout.Button("red on balck button");
    }

    GUILayout.Button("B&W button");
  }
}
See Also