/// <summary> /// Cache the components and register a listener callback. /// </summary> void Awake() { mList = GetComponent<NGUIPopupList>(); mCheck = GetComponent<NGUICheckbox>(); if (mList != null) mList.onSelectionChange += SaveSelection; if (mCheck != null) mCheck.onStateChange += SaveState; }
/// <summary> /// Load and set the state of the checkboxes. /// </summary> void OnEnable() { if (mList != null) { string s = PlayerPrefs.GetString(key); if (!string.IsNullOrEmpty(s)) { mList.selection = s; } return; } if (mCheck != null) { mCheck.isChecked = (PlayerPrefs.GetInt(key, 1) != 0); } else { string s = PlayerPrefs.GetString(key); NGUICheckbox[] checkboxes = GetComponentsInChildren <NGUICheckbox>(true); for (int i = 0, imax = checkboxes.Length; i < imax; ++i) { NGUICheckbox ch = checkboxes[i]; ch.isChecked = (ch.name == s); } } }
void OnEnable() { NGUICheckbox chk = GetComponent <NGUICheckbox>(); if (chk != null) { OnActivate(chk.isChecked); } }
void Start() { NGUICheckbox chk = GetComponent <NGUICheckbox>(); if (chk != null) { mUsingDelegates = true; chk.onStateChange += OnActivateDelegate; } }
/// <summary> /// Cache the components and register a listener callback. /// </summary> void Awake() { mList = GetComponent <NGUIPopupList>(); mCheck = GetComponent <NGUICheckbox>(); if (mList != null) { mList.onSelectionChange += SaveSelection; } if (mCheck != null) { mCheck.onStateChange += SaveState; } }
/// <summary> /// Save the state on destroy. /// </summary> void OnDisable() { if (mCheck == null && mList == null) { NGUICheckbox[] checkboxes = GetComponentsInChildren <NGUICheckbox>(true); for (int i = 0, imax = checkboxes.Length; i < imax; ++i) { NGUICheckbox ch = checkboxes[i]; if (ch.isChecked) { SaveSelection(ch.name); break; } } } }
/// <summary> /// Fade out or fade in the checkmark and notify the target of OnChecked event. /// </summary> void Set(bool state) { if (!mStarted) { mChecked = state; startsChecked = state; if (checkSprite != null) { checkSprite.alpha = state ? 1f : 0f; } } else if (mChecked != state) { // Uncheck all other checkboxes if (radioButtonRoot != null && state) { NGUICheckbox[] cbs = radioButtonRoot.GetComponentsInChildren <NGUICheckbox>(true); for (int i = 0, imax = cbs.Length; i < imax; ++i) { NGUICheckbox cb = cbs[i]; if (cb != this && cb.radioButtonRoot == radioButtonRoot) { cb.Set(false); } } } // Remember the state mChecked = state; // Tween the color of the checkmark if (checkSprite != null) { if (instantTween) { checkSprite.alpha = mChecked ? 1f : 0f; } else { TweenAlpha.Begin(checkSprite.gameObject, checkDuration, mChecked ? 1f : 0f); } } current = this; // Notify the delegate if (onStateChange != null) { onStateChange(mChecked); } // Send out the event notification if (eventReceiver != null && !string.IsNullOrEmpty(functionName)) { eventReceiver.SendMessage(functionName, mChecked, SendMessageOptions.DontRequireReceiver); } current = null; // Play the checkmark animation if (checkAnimation != null) { ActiveAnimation.Play(checkAnimation, state ? Direction.Forward : Direction.Reverse); } } }
/// <summary> /// Fade out or fade in the checkmark and notify the target of OnChecked event. /// </summary> void Set(bool state) { if (!mStarted) { mChecked = state; startsChecked = state; if (checkSprite != null) checkSprite.alpha = state ? 1f : 0f; } else if (mChecked != state) { // Uncheck all other checkboxes if (radioButtonRoot != null && state) { NGUICheckbox[] cbs = radioButtonRoot.GetComponentsInChildren<NGUICheckbox>(true); for (int i = 0, imax = cbs.Length; i < imax; ++i) { NGUICheckbox cb = cbs[i]; if (cb != this && cb.radioButtonRoot == radioButtonRoot) cb.Set(false); } } // Remember the state mChecked = state; // Tween the color of the checkmark if (checkSprite != null) { if (instantTween) { checkSprite.alpha = mChecked ? 1f : 0f; } else { TweenAlpha.Begin(checkSprite.gameObject, checkDuration, mChecked ? 1f : 0f); } } current = this; // Notify the delegate if (onStateChange != null) onStateChange(mChecked); // Send out the event notification if (eventReceiver != null && !string.IsNullOrEmpty(functionName)) { eventReceiver.SendMessage(functionName, mChecked, SendMessageOptions.DontRequireReceiver); } current = null; // Play the checkmark animation if (checkAnimation != null) { ActiveAnimation.Play(checkAnimation, state ? Direction.Forward : Direction.Reverse); } } }