Active.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace EnhancedHierarchy.Icons {
  4. public sealed class Active : IconBase {
  5. public override IconPosition Side { get { return IconPosition.All; } }
  6. public override Texture2D PreferencesPreview { get { return Utility.GetBackground(Styles.activeToggleStyle, true); } }
  7. //public override string PreferencesTooltip { get { return "Some tag for the tooltip here"; } }
  8. public override void DoGUI(Rect rect) {
  9. using(new GUIBackgroundColor(EnhancedHierarchy.CurrentGameObject.activeSelf ? Styles.backgroundColorEnabled : Styles.backgroundColorDisabled)) {
  10. GUI.changed = false;
  11. GUI.Toggle(rect, EnhancedHierarchy.CurrentGameObject.activeSelf, Styles.activeContent, Styles.activeToggleStyle);
  12. if (!GUI.changed)
  13. return;
  14. var objs = GetSelectedObjectsAndCurrent();
  15. var active = !EnhancedHierarchy.CurrentGameObject.activeSelf;
  16. Undo.RecordObjects(objs.ToArray(), EnhancedHierarchy.CurrentGameObject.activeSelf ? "Disabled GameObject" : "Enabled GameObject");
  17. foreach (var obj in objs)
  18. obj.SetActive(active);
  19. }
  20. }
  21. }
  22. }