Example #1
0
        protected void StopOneTimeEffectIfPlaying(UIEffects effect)
        {
            if (mCurrentOneTimeEffect == null || mCurrentOneTimeEffect != effect)
            {
                return;
            }

            mCurrentOneTimeEffect.PlayParticle(false);
            mCurrentOneTimeEffect.PlaySound(false);
            mCurrentOneTimeEffect = null;
        }
Example #2
0
 protected void PlayOneTimeEffect(UIEffects effect)
 {
     if (mCurrentOneTimeEffect != null)
     {
         mCurrentOneTimeEffect.PlayParticle(false);
         mCurrentOneTimeEffect.PlaySound(false);
     }
     if (effect != null)
     {
         effect.PlayParticle(true);
         effect.PlaySound(true);
     }
     mCurrentOneTimeEffect = effect;
 }
Example #3
0
        protected void FillEffectReferences(UIEffects effects)
        {
            effects._PositionEffect._ApplyTo = new UIEffects.PositionEffectData[mGraphicsStates.Count];
            effects._ScaleEffect._ApplyTo    = new UIEffects.ScaleEffectData[mGraphicsStates.Count];
            effects._ColorEffect._ApplyTo    = new UIEffects.ColorEffectData[mGraphicsStates.Count];
            effects._SpriteEffect._ApplyTo   = new UIEffects.SpriteEffectData[mGraphicsStates.Count];

            for (int i = 0; i < mGraphicsStates.Count; ++i)
            {
                effects._PositionEffect._ApplyTo[i] = new UIEffects.PositionEffectData {
                    _Widget = mGraphicsStates[i].pGraphic
                };
                effects._ScaleEffect._ApplyTo[i] = new UIEffects.ScaleEffectData {
                    _Widget = mGraphicsStates[i].pGraphic
                };
                effects._ColorEffect._ApplyTo[i] = new UIEffects.ColorEffectData {
                    _Widget = mGraphicsStates[i].pGraphic
                };
                effects._SpriteEffect._ApplyTo[i] = new UIEffects.SpriteEffectData {
                    _Widget = mGraphicsStates[i].pGraphic
                };
            }
        }
Example #4
0
        protected void ApplyEffect(UIEffects effect)
        {
            if (mCurrentEffect == effect)
            {
                return;
            }

            UIEffects previousEffect = mCurrentEffect;

            mCurrentEffect = effect;

            foreach (GraphicState graphicState in mGraphicsStates)
            {
                if (graphicState == null || graphicState.pGraphic == null) // when we delete the widget, togglebutton is calling ApplyEffect after deleting which causes null ref exception.
                {
                    return;
                }

                Tween.Stop(graphicState.pGraphic.gameObject);

                // The supported tween value types are - Position, Scale, Color, Sprite
                // We have to calculate the following in order to tween the values:
                // (1) Initial Value, (2) Duration, (3) EaseType and the (4) Final Value
                //
                // (1) The initial value of the tween will always be the current value of the Graphic (position, scale, color etc)
                // (2) If the current effect has specified the value type (has _UseEffect checked), the duration will be taken,
                //     or else the duration of the previous effect will be taken
                // (3) Same as above
                // (4) If the current effect has specified the value type (has _UseEffect checked), the value specified by the current effect will be used
                //     or it will be the value cached in Graphic States.

                Graphic         graphic          = graphicState.pGraphic;
                RectTransform   graphicTransform = graphicState.pGraphic.rectTransform;
                MaskableGraphic maskableGraphic  = graphicState.pGraphic as MaskableGraphic;
                Image           graphicImage     = graphicState.pGraphic as Image;

                Vector3 initialPosition = graphicTransform.localPosition;
                Vector3 initialScale    = graphicTransform.localScale;
                Color   initialColor    = (maskableGraphic != null) ? maskableGraphic.color : Color.white;

                Vector3 finalPosition = graphicState.pOriginalPosition;
                Vector3 finalScale    = graphicState.pOriginalScale;
                Color   finalColor    = graphicState.pOriginalColor;
                Sprite  finalSprite   = graphicState.pOriginalSprite;

                float positionDuration = 0;
                float scaleDuration    = 0;
                float colorDuration    = 0;

                EaseType positionEaseType = EaseType.Linear;
                EaseType scaleEaseType    = EaseType.Linear;
                EaseType colorEaseType    = EaseType.Linear;

                bool playPositionEffect = false;
                bool playScaleEffect    = false;
                bool playColorEffect    = false;
                bool playSpriteEffect   = false;

                if (previousEffect != null)
                {
                    if (previousEffect._PositionEffect._UseEffect)
                    {
                        UIEffects.PositionEffectData positionEffectData = Array.Find(previousEffect._PositionEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (positionEffectData != null)
                        {
                            positionDuration   = positionEffectData._Time;
                            positionEaseType   = positionEffectData._PositionEffect;
                            playPositionEffect = true;
                        }
                    }
                    if (previousEffect._ScaleEffect._UseEffect)
                    {
                        UIEffects.ScaleEffectData scaleEffectData = Array.Find(previousEffect._ScaleEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (scaleEffectData != null)
                        {
                            scaleDuration   = scaleEffectData._Time;
                            scaleEaseType   = scaleEffectData._ScaleEffect;
                            playScaleEffect = true;
                        }
                    }
                    if (previousEffect._ColorEffect._UseEffect)
                    {
                        UIEffects.ColorEffectData colorEffectData = Array.Find(previousEffect._ColorEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (colorEffectData != null)
                        {
                            colorDuration   = colorEffectData._Time;
                            colorEaseType   = colorEffectData._ColorEffect;
                            playColorEffect = true;
                        }
                    }
                    if (previousEffect._SpriteEffect._UseEffect)
                    {
                        playSpriteEffect = true;
                    }
                }

                if (mCurrentEffect != null)
                {
                    mCurrentEffectStartTime = Time.realtimeSinceStartup;

                    if (mCurrentEffect._PositionEffect._UseEffect)
                    {
                        UIEffects.PositionEffectData positionEffectData = Array.Find(mCurrentEffect._PositionEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (positionEffectData != null)
                        {
                            finalPosition      = positionEffectData._Offset;
                            positionDuration   = positionEffectData._Time;
                            positionEaseType   = positionEffectData._PositionEffect;
                            playPositionEffect = true;
                        }
                    }
                    if (mCurrentEffect._ScaleEffect._UseEffect)
                    {
                        UIEffects.ScaleEffectData scaleEffectData = Array.Find(mCurrentEffect._ScaleEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (scaleEffectData != null)
                        {
                            finalScale      = scaleEffectData._Scale;
                            scaleDuration   = scaleEffectData._Time;
                            scaleEaseType   = scaleEffectData._ScaleEffect;
                            playScaleEffect = true;
                        }
                    }
                    if (mCurrentEffect._ColorEffect._UseEffect)
                    {
                        UIEffects.ColorEffectData colorEffectData = Array.Find(mCurrentEffect._ColorEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (colorEffectData != null)
                        {
                            finalColor      = colorEffectData._Color;
                            colorDuration   = colorEffectData._Time;
                            colorEaseType   = colorEffectData._ColorEffect;
                            playColorEffect = true;
                        }
                    }
                    if (mCurrentEffect._SpriteEffect._UseEffect)
                    {
                        UIEffects.SpriteEffectData spriteEffectData = Array.Find(mCurrentEffect._SpriteEffect._ApplyTo, x => x._Widget == graphicState.pGraphic);
                        if (spriteEffectData != null)
                        {
                            finalSprite      = spriteEffectData._Sprite;
                            playSpriteEffect = true;
                        }
                    }
                }

                if (playPositionEffect)
                {
                    Tween.MoveLocalTo(graphic.gameObject, initialPosition, finalPosition, new TweenParam(positionDuration, positionEaseType));
                }
                if (playScaleEffect)
                {
                    Tween.ScaleTo(graphic.gameObject, initialScale, finalScale, new TweenParam(scaleDuration, scaleEaseType));
                }
                if (playColorEffect)
                {
                    Tween.ColorTo(graphic.gameObject, initialColor, finalColor, new TweenParam(colorDuration, colorEaseType));
                }
                if (playSpriteEffect && graphicImage != null)
                {
                    graphicImage.sprite = finalSprite;
                }
            }
        }