Esempio n. 1
0
    /// <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);
            }
        }
    }