Beispiel #1
0
 private void EnableBottomAnchors()
 {
     UIAnchor[] anchors = m_BottomBox.GetComponentsInChildren <UIAnchor>(true);
     foreach (UIAnchor anchor in anchors)
     {
         anchor.enabled = true;
     }
 }
Beispiel #2
0
    /// <summary>
    /// Fade out or fade in the active sprite and notify the OnChange event listener.
    /// If setting the initial value, call Start() first.
    /// </summary>

    public void Set(bool state, bool notify = true)
    {
        if (validator != null && !validator(state))
        {
            return;
        }

        if (!mStarted)
        {
            mIsActive    = state;
            startsActive = state;
            if (activeSprite != null)
            {
                activeSprite.alpha = invertSpriteState ? (state ? 0f : 1f) : (state ? 1f : 0f);
            }
        }
        else if (mIsActive != state)
        {
            // Uncheck all other toggles
            if (group != 0 && state)
            {
                for (int i = 0, imax = list.size; i < imax;)
                {
                    UIToggle cb = list[i];
                    if (cb != this && cb.group == group)
                    {
                        cb.Set(false);
                    }

                    if (list.size != imax)
                    {
                        imax = list.size;
                        i    = 0;
                    }
                    else
                    {
                        ++i;
                    }
                }
            }

            // Remember the state
            mIsActive = state;

            // Tween the color of the active sprite
            if (activeSprite != null)
            {
                if (instantTween || !NGUITools.GetActive(this))
                {
                    activeSprite.alpha = invertSpriteState ? (mIsActive ? 0f : 1f) : (mIsActive ? 1f : 0f);
                }
                else
                {
                    TweenAlpha.Begin(activeSprite.gameObject, 0.15f, invertSpriteState ? (mIsActive ? 0f : 1f) : (mIsActive ? 1f : 0f));
                }
            }

            if (notify && current == null)
            {
                UIToggle tog = current;
                current = this;

                if (EventDelegate.IsValid(onChange))
                {
                    EventDelegate.Execute(onChange);
                }
                else if (eventReceiver != null && !string.IsNullOrEmpty(functionName))
                {
                    // Legacy functionality support (for backwards compatibility)
                    eventReceiver.SendMessage(functionName, mIsActive, SendMessageOptions.DontRequireReceiver);
                }
                current = tog;
            }

            // Play the checkmark animation
            if (animator != null)
            {
                ActiveAnimation aa = ActiveAnimation.Play(animator, null,
                                                          state ? Direction.Forward : Direction.Reverse,
                                                          EnableCondition.IgnoreDisabledState,
                                                          DisableCondition.DoNotDisable);
                if (aa != null && (instantTween || !NGUITools.GetActive(this)))
                {
                    aa.Finish();
                }
            }
            else if (activeAnimation != null)
            {
                ActiveAnimation aa = ActiveAnimation.Play(activeAnimation, null,
                                                          state ? Direction.Forward : Direction.Reverse,
                                                          EnableCondition.IgnoreDisabledState,
                                                          DisableCondition.DoNotDisable);
                if (aa != null && (instantTween || !NGUITools.GetActive(this)))
                {
                    aa.Finish();
                }
            }
            else if (tween != null)
            {
                bool isActive = NGUITools.GetActive(this);

                if (tween.tweenGroup != 0)
                {
                    UITweener[] tws = tween.GetComponentsInChildren <UITweener>(true);

                    for (int i = 0, imax = tws.Length; i < imax; ++i)
                    {
                        UITweener t = tws[i];

                        if (t.tweenGroup == tween.tweenGroup)
                        {
                            t.Play(state);
                            if (instantTween || !isActive)
                            {
                                t.tweenFactor = state ? 1f : 0f;
                            }
                        }
                    }
                }
                else
                {
                    tween.Play(state);
                    if (instantTween || !isActive)
                    {
                        tween.tweenFactor = state ? 1f : 0f;
                    }
                }
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// Fade out or fade in the active sprite and notify the OnChange event listener.
    /// </summary>

    public void Set(bool state)
    {
        if (validator != null && !validator(state))
        {
            return;
        }

        if (!mStarted)
        {
            mIsActive    = state;
            startsActive = state;
            if (activeSprite != null)
            {
                activeSprite.alpha = state ? 1f : 0f;
            }
        }
        else if (mIsActive != state)
        {
            // Uncheck all other toggles
            if (group != "" && state)
            {
                for (int i = 0, imax = list.size; i < imax;)
                {
                    UIToggle cb = list[i];
                    if (cb != this && cb.group == group)
                    {
                        cb.Set(false);
                    }

                    if (list.size != imax)
                    {
                        imax = list.size;
                        i    = 0;
                    }
                    else
                    {
                        ++i;
                    }
                }
            }

            // Remember the state
            mIsActive = state;

            // Tween the color of the active sprite
            if (activeSprite != null)
            {
                if (instantTween || !NGUITools.GetActive(this))
                {
                    activeSprite.alpha = mIsActive ? 1f : 0f;
                }
                else
                {
                    TweenAlpha.Begin(activeSprite.gameObject, 0.15f, mIsActive ? 1f : 0f);
                }
            }
            _onChange.Invoke(this, state);

            // Play the checkmark animation
            if (animator != null)
            {
                ActiveAnimation aa = ActiveAnimation.Play(animator, null,
                                                          state ? Direction.Forward : Direction.Reverse,
                                                          EnableCondition.IgnoreDisabledState,
                                                          DisableCondition.DoNotDisable);
                if (aa != null && (instantTween || !NGUITools.GetActive(this)))
                {
                    aa.Finish();
                }
            }
            else if (activeAnimation != null)
            {
                ActiveAnimation aa = ActiveAnimation.Play(activeAnimation, null,
                                                          state ? Direction.Forward : Direction.Reverse,
                                                          EnableCondition.IgnoreDisabledState,
                                                          DisableCondition.DoNotDisable);
                if (aa != null && (instantTween || !NGUITools.GetActive(this)))
                {
                    aa.Finish();
                }
            }
            else if (tween != null)
            {
                bool isActive = NGUITools.GetActive(this);

                if (tween.tweenGroup != 0)
                {
                    UITweener[] tws = tween.GetComponentsInChildren <UITweener>();

                    for (int i = 0, imax = tws.Length; i < imax; ++i)
                    {
                        UITweener t = tws[i];

                        if (t.tweenGroup == tween.tweenGroup)
                        {
                            t.Play(state);
                            if (instantTween || !isActive)
                            {
                                t.tweenFactor = state ? 1f : 0f;
                            }
                        }
                    }
                }
                else
                {
                    tween.Play(state);
                    if (instantTween || !isActive)
                    {
                        tween.tweenFactor = state ? 1f : 0f;
                    }
                }
            }
        }
    }