You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. namespace ProGrids
  4. {
  5. /**
  6. * A substitute for GUIContent that offers some additional functionality.
  7. */
  8. [System.Serializable]
  9. public class pg_ToggleContent
  10. {
  11. public string text_on, text_off;
  12. public Texture2D image_on, image_off;
  13. public string tooltip;
  14. GUIContent gc = new GUIContent();
  15. public pg_ToggleContent(string t_on, string t_off, string tooltip)
  16. {
  17. this.text_on = t_on;
  18. this.text_off = t_off;
  19. this.image_on = (Texture2D)null;
  20. this.image_off = (Texture2D)null;
  21. this.tooltip = tooltip;
  22. gc.tooltip = tooltip;
  23. }
  24. public pg_ToggleContent(string t_on, string t_off, Texture2D i_on, Texture2D i_off, string tooltip)
  25. {
  26. this.text_on = t_on;
  27. this.text_off = t_off;
  28. this.image_on = i_on;
  29. this.image_off = i_off;
  30. this.tooltip = tooltip;
  31. gc.tooltip = tooltip;
  32. }
  33. public static bool ToggleButton(Rect r, pg_ToggleContent content, bool enabled, GUIStyle imageStyle, GUIStyle altStyle)
  34. {
  35. content.gc.image = enabled ? content.image_on : content.image_off;
  36. content.gc.text = content.gc.image == null ? (enabled ? content.text_on : content.text_off) : "";
  37. return GUI.Button(r, content.gc, content.gc.image != null ? imageStyle : altStyle);
  38. }
  39. }
  40. }