UIToggledComponents.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. [RequireComponent(typeof(UIToggle))]
  6. [AddComponentMenu("NGUI/Interaction/Toggled Components")]
  7. public class UIToggledComponents : MonoBehaviour
  8. {
  9. private void Awake()
  10. {
  11. if (this.target != null)
  12. {
  13. if (this.activate.Count == 0 && this.deactivate.Count == 0)
  14. {
  15. if (this.inverse)
  16. {
  17. this.deactivate.Add(this.target);
  18. }
  19. else
  20. {
  21. this.activate.Add(this.target);
  22. }
  23. }
  24. else
  25. {
  26. this.target = null;
  27. }
  28. }
  29. UIToggle component = base.GetComponent<UIToggle>();
  30. EventDelegate.Add(component.onChange, new EventDelegate.Callback(this.Toggle));
  31. }
  32. public void Toggle()
  33. {
  34. if (base.enabled)
  35. {
  36. for (int i = 0; i < this.activate.Count; i++)
  37. {
  38. MonoBehaviour monoBehaviour = this.activate[i];
  39. monoBehaviour.enabled = UIToggle.current.value;
  40. }
  41. for (int j = 0; j < this.deactivate.Count; j++)
  42. {
  43. MonoBehaviour monoBehaviour2 = this.deactivate[j];
  44. monoBehaviour2.enabled = !UIToggle.current.value;
  45. }
  46. }
  47. }
  48. public List<MonoBehaviour> activate;
  49. public List<MonoBehaviour> deactivate;
  50. [HideInInspector]
  51. [SerializeField]
  52. private MonoBehaviour target;
  53. [HideInInspector]
  54. [SerializeField]
  55. private bool inverse;
  56. }