1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [ExecuteInEditMode]
- [RequireComponent(typeof(UIToggle))]
- [AddComponentMenu("NGUI/Interaction/Toggled Components")]
- public class UIToggledComponents : MonoBehaviour
- {
- private void Awake()
- {
- if (this.target != null)
- {
- if (this.activate.Count == 0 && this.deactivate.Count == 0)
- {
- if (this.inverse)
- {
- this.deactivate.Add(this.target);
- }
- else
- {
- this.activate.Add(this.target);
- }
- }
- else
- {
- this.target = null;
- }
- }
- UIToggle component = base.GetComponent<UIToggle>();
- EventDelegate.Add(component.onChange, new EventDelegate.Callback(this.Toggle));
- }
- public void Toggle()
- {
- if (base.enabled)
- {
- for (int i = 0; i < this.activate.Count; i++)
- {
- MonoBehaviour monoBehaviour = this.activate[i];
- monoBehaviour.enabled = UIToggle.current.value;
- }
- for (int j = 0; j < this.deactivate.Count; j++)
- {
- MonoBehaviour monoBehaviour2 = this.deactivate[j];
- monoBehaviour2.enabled = !UIToggle.current.value;
- }
- }
- }
- public List<MonoBehaviour> activate;
- public List<MonoBehaviour> deactivate;
- [HideInInspector]
- [SerializeField]
- private MonoBehaviour target;
- [HideInInspector]
- [SerializeField]
- private bool inverse;
- }
|