Advertisement
KpoKec

Toggle as button

Jul 16th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1.         private static GUIStyle _toggleOff;
  2.         private static GUIStyle _toggleOn;
  3.         public static bool ToggleButton(string name, bool state, GUILayoutOption option = null) {
  4.             if (_toggleOff == null) {
  5.                 _toggleOff       = new GUIStyle(GUI.skin.button);
  6.                 _toggleOn        = new GUIStyle(GUI.skin.button);
  7.                 _toggleOn.normal = _toggleOn.onActive;
  8.             }
  9.             if (option == null) {
  10.                 if (GUILayout.Button(name, state ? _toggleOn : _toggleOff))
  11.                     return !state;
  12.             }
  13.             else {
  14.                 if (GUILayout.Button(name, state ? _toggleOn : _toggleOff, option))
  15.                     return !state;
  16.             }          
  17.             return state;
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement