Exemplo n.º 1
0
    public void Pulse(float duration, Vector2 moveAmount, Vector2 scaleAmount)
    {
        if (spriteRenderer.enabled == false || spriteRenderer.sprite == null)
        {
            return;
        }

        // create new ghost
        GameObject newObj = null;
        {
            newObj = new GameObject(gameObject.name);
            newObj.transform.position = transform.position.plusZ(-0.00001f);
            newObj.transform.rotation = transform.rotation;
            var newSprite = newObj.AddComponent <SpriteRenderer>();
            newSprite.sprite = spriteRenderer.sprite;
            newSprite.color  = spriteRenderer.color;

            newObj.transform.parent     = transform.parent;
            newObj.transform.localScale = transform.localScale;
        }
        // start tweening ghost
        {
            Tween.MoveBy(newObj, new Vector3(moveAmount.x, moveAmount.y, 0), duration, Interpolate.EaseType.EaseOutCirc);
            Tween.ScaleBy(newObj, new Vector3(scaleAmount.x, scaleAmount.y, 0), duration, Interpolate.EaseType.EaseOutCirc);
            Tween.ColorTo(newObj, spriteRenderer.color.withAlpha(0), duration, Interpolate.EaseType.Linear);
        }
        // register new ghost to keep track of when to destroy it
        {
            ghostObjects.Add(newObj);
            ghostDurations.Add(duration);
        }
    }
Exemplo n.º 2
0
 public void NewRound()
 {
     UpdateRPG();
     UpdateTest();
     // set new creature
     if (currentCreature == null || creaturePatternDone)
     {
         currentCreature         = AssetManager.Inst.Creatures.Next(currentCreature);
         currentCreaturePhase    = 0;
         currentCreatureDialogue = 0;
         CreatureNameText.text   = currentCreature.Name;
         CreatureResponseBox.SetActive(false);
         CreatureResponseText.text = "";
         CreatureDebug.text        = currentCreature.name;
         currentCreature.IntroSound.Play();
         currentCreatureObj = Instantiate(currentCreature.Prefab, CreaturePosition, Quaternion.identity);
         currentCreatureObj.transform.localScale = CreatureScaleInit;
         Tween.ScaleTo(currentCreatureObj, CreatureScaleFinal, 0.5f, Interpolate.EaseType.EaseOutQuad);
         var sprite = currentCreatureObj.GetComponentInChildren <SpriteRenderer>();
         sprite.color = sprite.color.withAlpha(0);
         Tween.ColorTo(sprite.gameObject, sprite.color.withAlpha(1), 0.4f, Interpolate.EaseType.EaseOutSine);
     }
     // set new question
     questionOrder.Shuffle();
     currentQuestion    = AssetManager.Inst.Questions.Next(currentQuestion);
     QuestionText.text  = currentQuestion.Question.LineWrap(QuestionLineLength);
     Answer1Text.text   = currentQuestion.GetAnswer(questionOrder[0]).Text.LineWrap(AnswerLineLength);
     Answer2Text.text   = currentQuestion.GetAnswer(questionOrder[1]).Text.LineWrap(AnswerLineLength);
     Answer3Text.text   = currentQuestion.GetAnswer(questionOrder[2]).Text.LineWrap(AnswerLineLength);
     Answer4Text.text   = currentQuestion.GetAnswer(questionOrder[3]).Text.LineWrap(AnswerLineLength);
     NumberText.text    = "Question " + (questionsAnswered + 1) + "/" + QuestionsBeforeWin;
     QuestionDebug.text = currentQuestion.name;
 }
Exemplo n.º 3
0
    void Start()
    {
        var r = GetComponent <Image>();

        r.enabled = true;
        r.color   = ColorStart;
        Tween.ColorTo(gameObject, ColorEnd, Duration, Interpolate.EaseType.Linear);
        Destroy(gameObject, Duration * 1.05f);
    }
            public override void ShowEffect(bool showEffect)
            {
                for (int i = 0; i < _ApplyTo.Length; ++i)
                {
                    ColorEffectData colorEffectData = _ApplyTo[i];

                    if (colorEffectData._Widget != null)
                    {
                        Graphic graphic = colorEffectData._Widget as Graphic;
                        if (graphic != null)
                        {
                            Color toColor = showEffect ? colorEffectData._Color : mOriginalValues[i];
                            Tween.ColorTo(graphic.gameObject, graphic.color, toColor, new TweenParam(colorEffectData._Time, colorEffectData._ColorEffect));
                        }
                    }
                }
            }
Exemplo n.º 5
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;
                }
            }
        }