void Start()
    {
        gameObject.Play(FadeAction.Create(end, isRelative, isRecursive, duration, Ease.FromType(easeType), direction));

        // Self-destroy
        Destroy(this);
    }
Example #2
0
 public void ChangeScene(int newScene, FadeAction fadeOutAction)
 {
     FadeIn();
     this.FadeOutAction = fadeOutAction;
     AsyncOperation scene = Application.LoadLevelAsync(newScene);
     StartCoroutine(LoadSceneCoroutine(scene));
 }
Example #3
0
    public BaseAction GetAction()
    {
        if (actionType == ActionType.Move)
        {
            return(MoveAction.Create(v31, b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Scale)
        {
            return(ScaleAction.Create(v31, b1, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Rotate)
        {
            return(RotateAction.Create(f1, b1, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Fade)
        {
            return(FadeAction.Create(f1, b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Tint)
        {
            return(TintAction.Create(c1.RGB(), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Delay)
        {
            return(DelayAction.Create(duration));
        }

        return(null);
    }
Example #4
0
    protected virtual void Hide(bool fadeOut, Action callback)
    {
        // Disable UI
        SetUIEnabled(false);

        // Hide touch and overlay
        SetShowTouchAndOverlay(false);

        // Delay
        gameObject.Play(DelayAction.Create(0.1f), () => {
            if (fadeOut)
            {
                // Fade-out overlay
                gameObject.Play(FadeAction.FadeOut(fadeDuration));

                // Fade-out background
                background.Play(FadeAction.RecursiveFadeOut(fadeDuration), () => {
                    // Hide
                    gameObject.Hide();

                    // Enable UI
                    SetUIEnabled(true);

                    callback();
                });
            }
            else
            {
                // Enable UI
                SetUIEnabled(true);

                callback();
            }
        });
    }
Example #5
0
    public static void ShowPopup(GameObject popup, Action callback = null)
    {
        // Reset button scale
        popup.ResetButtonScale(true);

        // Show popup
        popup.Show();

        // Fade-in
        popup.Play(FadeAction.FadeTo(popupEndOpacity, popupDuration));

        // Content
        GameObject content = popup.FindInChildren("Popup");

        if (content != null)
        {
            content.transform.localScale = popupStartScale;

            var zoomOut = ScaleAction.ScaleTo(popupEndScale, popupDuration * 0.7f);
            var zoomIn  = ScaleAction.ScaleTo(Vector3.one, popupDuration * 0.3f);
            var action  = SequenceAction.Create(zoomOut, zoomIn);

            content.Play(action, callback);
        }
        else
        {
            if (callback != null)
            {
                callback();
            }
        }
    }
Example #6
0
        public void render(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            spriteBatch.Draw(scene.background.texture, new Rectangle(0, 0, 800, 600), Color.White);

            foreach (KeyValuePair <String, Actor> curActor in scene.actors)
            {
                curActor.Value.Draw(spriteBatch);
            }

            foreach (Actions.Action curAction in curEvent.actions)
            {
                if (curAction.actionType == ActionType.Speak)
                {
                    SpeakAction speak = curAction as SpeakAction;
                    speak.Draw(font, speechTex, spriteBatch);
                }
                else if (curAction.actionType == ActionType.Fade)
                {
                    FadeAction fade = curAction as FadeAction;
                    fade.Draw(spriteBatch, fadeTex);
                }
                //Move modifies actor positions - no draw call needed
            }

            spriteBatch.End();
        }
Example #7
0
 public void FadeInOut(FadeAction fadeInAction, FadeAction fadeOutAction)
 {
     this.FadeInAction = fadeInAction;
     this.FadeOutAction = fadeOutAction;
     this.FadeInAction += FadeOut;
     FadeIn();
 }
Example #8
0
    public override void OnAnimalExit(Animal animal)
    {
        if (_enterCount == 1)
        {
            // Set animal to null
            _animal = null;

            GameManager.Instance.OnAnimalExitFoothold(this);

            _isDouble = false;

            var delay         = DelayAction.Create(0.5f);
            var playExplosion = CallFuncAction.Create(() => {
                // Play sound
                SoundManager.Instance.PlaySound(SoundID.Explose);

                if (explosionPrefab != null)
                {
                    GameObject explosion = explosionPrefab.Create(transform, icon.transform.position);
                    explosion.AddSortingOrder(icon.GetSortingOrder() + 1);
                }
            });
            var fadeOut = FadeAction.FadeOut(0.25f);
            var hide    = HideAction.Create();

            // Hide icon
            icon.Play(SequenceAction.Create(delay, playExplosion, fadeOut, hide));
        }
        else
        {
            base.OnAnimalExit(animal);
        }
    }
 private void updateStay()
 {
     if (timer > stayDuration)
     {
         timer  -= stayDuration;
         handler = updateFadeOut;
         handler();
     }
 }
Example #10
0
    public void OnHammerEnd()
    {
        // Disable swing
        _swingEnabled = false;

        GameManager.Instance.OnFootholdDestroyed(this);

        gameObject.Play(FadeAction.FadeOut(0.5f), () => {
            SelfDestroy();
        });
    }
Example #11
0
    void Sink()
    {
        var delay        = DelayAction.Create(0.5f);
        var disableSwing = CallFuncAction.Create(() => { _swingEnabled = false; });
        var move         = MoveAction.MoveBy(new Vector3(0, -sinkDelta, 0), 0.5f, Ease.SineIn);
        var fadeOut      = FadeAction.RecursiveFadeOut(0.5f);

        gameObject.Play(SequenceAction.Create(delay, disableSwing, ParallelAction.ParallelAll(move, fadeOut)), () => {
            SelfDestroy();
        });
    }
Example #12
0
    IEnumerator Buffering(float bufferingTime, FadeAction fadeActions)
    {
        _active = true;

        float t          = 0;
        var   startValue = _fader.color.a;

        while (t < 1)
        {
            t += Time.deltaTime / 0.25f;
            var color = new Color(0, 0, 0, Mathf.Lerp(startValue, 1, t));
            Debug.Log(color);
            _fader.color = color;
            Debug.Log(color);
            yield return(null);
        }

        if (dots)
        {
            dots.gameObject.SetActive(true);
        }
        for (int i = 0; i < (int)(bufferingTime / 0.1f); i++)
        {
            yield return(new WaitForSeconds(0.1f));

            var eulear = dots.eulerAngles;
            eulear.z        -= 29;
            dots.eulerAngles = eulear;
        }
        if (dots)
        {
            dots.gameObject.SetActive(false);
        }


        if (fadeActions != null)
        {
            fadeActions();
        }


        t          = 0;
        startValue = 1;
        while (t < 1)
        {
            t += Time.deltaTime / 0.25f;
            var color = new Color(0, 0, 0, Mathf.Lerp(startValue, 0, t));
            _fader.color = color;
            yield return(null);
        }

        _active = false;
    }
Example #13
0
    public void Exit()
    {
        image.gameObject.Play(FadeAction.FadeOut(1f));
        text.gameObject.SetActive(false);

        if (bird != null)
        {
            bird.Play(FadeAction.FadeOut(1));
        }

        Invoke("DeactiveCutscene", 1.05f);
    }
Example #14
0
    void Unsink()
    {
        gameObject.SetAlpha(0, true);

        Vector3 position = transform.position;

        position.y -= sinkDelta;

        var delay       = DelayAction.Create(0.05f);
        var setPosition = SetPositionAction.Create(position);
        var move        = MoveAction.MoveBy(new Vector3(0, sinkDelta, 0), 0.5f, Ease.SineOut);
        var fadeIn      = FadeAction.RecursiveFadeIn(0.5f);

        gameObject.Play(SequenceAction.Create(delay, setPosition, ParallelAction.ParallelAll(move, fadeIn)), () => { _swingEnabled = true; });
    }
Example #15
0
    public override void OnAnimalStartUnexit(Animal animal)
    {
        if (_enterCount == 1)
        {
            _isDouble = true;

            icon.StopAction(true);
            icon.Show();

            // Show icon
            icon.Play(FadeAction.FadeIn(0.25f));
        }

        base.OnAnimalStartUnexit(animal);
    }
    private void updateFadeIn()
    {
        float aux;

        if (timer < fadeInDuration)
        {
            colorWithAlpha(timer / fadeInDuration);
        }
        else
        {
            colorWithAlpha(1);
            timer  -= fadeInDuration;
            handler = updateStay;
            handler();
        }
    }
Example #17
0
    IEnumerator ScaleUp(GameObject ObjectToBeScaled, FadeAction ActionToBePerformed)
    {
        //make this the child of TopOfEverything
        ObjectToBeScaled.transform.SetParent(TopOfEverything);

        //detach child from gameobject
        ObjectToBeScaled.transform.DetachChildren();

        while (ObjectToBeScaled.transform.localScale.x < FullCoverScale.x)
        {
            ObjectToBeScaled.transform.localScale = Vector3.Lerp(ObjectToBeScaled.transform.localScale, (2 * FullCoverScale), Time.deltaTime * ScaleSpeed);
            yield return(new WaitForEndOfFrame());
        }

        StartCoroutine(FadeFader(ActionToBePerformed)); //FadeAction.LoadCurrentLevel
    }
Example #18
0
    void Start()
    {
        var fade = FadeAction.Create(end, isRelative, isRecursive, duration, Ease.FromType(easeType), direction);

        if (delay > 0)
        {
            gameObject.Play(SequenceAction.Create(DelayAction.Create(delay), fade));
        }
        else
        {
            gameObject.Play(fade);
        }

        // Self-destroy
        Destroy(this);
    }
Example #19
0
        public override bool SaveFile(string path)
        {
            MenusUibFile uib = new MenusUibFile();

            uib.Entries.Clear();
            foreach (DataGridViewRow dataRow in dgvTable.Rows)
            {
                string     key     = dataRow.Cells[DcKey.Name].Value?.ToString() ?? "";
                string     val     = dataRow.Cells[DcMenu.Name].Value?.ToString() ?? "";
                FadeAction fadein  = _fade.Get(dataRow.Cells[DcFadeIn.Name].Value?.ToString() ?? "");
                FadeAction fadeout = _fade.Get(dataRow.Cells[DcFadeOut.Name].Value?.ToString() ?? "");

                uib.Entries.Add(new UibEntry <MenusUibData>(key, new MenusUibData(val, fadein, fadeout)));
            }
            uib.WriteToFile(path);
            _uib   = uib;
            _dirty = false;
            _path  = path;
            return(true);
        }
Example #20
0
    public static void HidePopup(GameObject popup, Action callback)
    {
        // Content
        GameObject content = popup.FindInChildren("Popup");

        if (content != null)
        {
            // Hide content
            content.transform.localScale = Vector3.zero;
        }

        // Fade-out
        popup.Play(FadeAction.FadeOut(popupDuration), () => {
            // Hide popup
            popup.Hide();

            if (callback != null)
            {
                callback();
            }
        });
    }
Example #21
0
    public virtual void Show(Action callback = null)
    {
        // Hide
        gameObject.SetAlpha(0, true);

        // Hide touch and overlay
        SetShowTouchAndOverlay(false);

        // Disable UI
        SetUIEnabled(false);

        // Show
        gameObject.Show();

        // Overlay
        gameObject.Play(FadeAction.FadeTo(0.8f, this.OverlayDuration), () => {
            // Background
            background.Play(FadeAction.RecursiveFadeIn(fadeDuration), () => {
                OnShowFinished(callback);
            });
        });
    }
Example #22
0
    void UpdateTime()
    {
        // Get current time
        int time = Mathf.CeilToInt(_time);

        if (time != _currentTime)
        {
            if (_currentTime > 0)
            {
                // Frame
                frame.StopAction();
                frame.Show();
                frame.Play(BlinkAction.Create(2, 0.3f, false, false), () => { frame.Hide(); });

                // Play effect
                GameObject effect = numberEffect.gameObject;
                effect.StopAction(true);
                effect.Show();
                effect.transform.localScale = Vector3.one;
                effect.SetColor(_currentTime > 3 ? Color.white : alarmColor, true);

                numberEffect.Number = _currentTime;

                var zoomOut = ScaleAction.ScaleTo(alarmScale, alarmDuration);
                var fadeOut = FadeAction.RecursiveFadeOut(alarmDuration);
                var hide    = HideAction.Create();

                effect.Play(SequenceAction.Create(ParallelAction.ParallelAll(zoomOut, fadeOut), hide));
            }

            // Set current time
            _currentTime = time;

            // Update number
            number.Number = time;
        }
    }
Example #23
0
 public void FadeIn(FadeAction Action)
 {
     this.FadeInAction = Action;
     FadeIn();
 }
Example #24
0
    public BaseAction GetAction()
    {
        if (actionType == ActionType.Move)
        {
            return(MoveAction.Create(v31.VarianceXY(variance), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.HorizontalMove)
        {
            return(HMoveAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.VerticalMove)
        {
            return(VMoveAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Scale)
        {
            return(ScaleAction.Create(v31.VarianceXY(variance), b1, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Rotate)
        {
            return(RotateAction.Create(f1.Variance(variance), b1, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Fade)
        {
            return(FadeAction.Create(f1.Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.Tint)
        {
            return(TintAction.Create(c1.RGB().Variance(variance), b1, b2, duration, Ease.FromType(easeType), direction));
        }

        if (actionType == ActionType.SetPosition)
        {
            return(SetPositionAction.Create(v31, v32, b1, b2));
        }

        if (actionType == ActionType.SetScale)
        {
            return(SetScaleAction.Create(v31, v32, b1));
        }

        if (actionType == ActionType.SetRotation)
        {
            return(SetRotationAction.Create(f1, f2));
        }

        if (actionType == ActionType.SetAlpha)
        {
            return(SetAlphaAction.Create(f1, f2, b1));
        }

        if (actionType == ActionType.SetRGB)
        {
            return(SetRGBAction.Create(c1.RGB(), c2.RGB(), b1));
        }

        if (actionType == ActionType.Delay)
        {
            return(DelayAction.Create(duration, f2));
        }

        if (actionType == ActionType.AnimatorTrigger)
        {
            return(AnimatorTriggerAction.Create(s1));
        }

        if (actionType == ActionType.PlaySound)
        {
            return(PlaySoundAction.Create(soundId, soundType, f1));
        }

        if (actionType == ActionType.CallEvent)
        {
            return(CallEventAction.Create(e1));
        }

        if (actionType == ActionType.PlayParticleSystem)
        {
            return(PlayPSAction.Create(b1));
        }

        return(null);
    }
Example #25
0
 private void Fade(FadeAction mode)
 {
     this.FadeMode = mode;
     timer1.Start();
 }
Example #26
0
    void Start()
    {
        // Set scale
        transform.localScale = scale;

        gameObject.Play(ParallelAction.ParallelAll(ScaleAction.ScaleTo(scale * Random.Range(minScale, maxScale), scaleDuration), FadeAction.FadeOut(fadeDuration)), () => {
            GameObject.Destroy(gameObject);
        });
    }
Example #27
0
 public MenusUibData(string menu, FadeAction fadeIn, FadeAction fadeOut)
 {
     Menu    = menu;
     FadeIn  = fadeIn;
     FadeOut = fadeOut;
 }
 private void Awake()
 {
     _fadeAction    = GetComponent <FadeAction>();
     _chatBoxAction = GetComponent <ChatAction>();
     _shakeAction   = GetComponent <ShakeAction>();
 }
Example #29
0
 public void StartBuffering(float bufferingTime = 2, FadeAction fadeActions = null)
 {
     StartCoroutine(Buffering(bufferingTime, fadeActions));
 }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        if (running)
        {
            Action action = actionsList[actionIndex];
            actionTime += Time.unscaledDeltaTime;

            if (action.type == ActionType.Fade)
            {
                FadeAction faction = (FadeAction)action;

                if (!faction.started)
                {
                    faction.SetupColor(GetColor());
                }

                if (actionTime >= action.time)
                {
                    faction.started = false;
                    SetColor(faction.targetColor);
                    nextAction();
                    return;
                }

                SetColor(Color.Lerp(faction.originalColor, faction.targetColor, actionTime / action.time));
            }
            else if (action.type == ActionType.Func)
            {
                ((FuncAction)action).function();
                nextAction();
            }
            else if (action.type == ActionType.Delay && actionTime >= action.time)
            {
                nextAction();
            }
            else if (action.type == ActionType.ImageFill)
            {
                ImageFillAction iaction = (ImageFillAction)action;

                if (!iaction.started)
                {
                    iaction.SetupFill(GetFillAmount());
                }

                if (actionTime >= action.time)
                {
                    iaction.started = false;
                    SetFillAmount(iaction.targetFill);
                    nextAction();
                    return;
                }

                SetFillAmount(Mathf.Lerp(iaction.originalFill, iaction.targetFill, actionTime / action.time));
            }
            else if (action.type == ActionType.Scale)
            {
                ScaleAction saction = (ScaleAction)action;

                if (!saction.started)
                {
                    saction.SetupScale(transform.localScale);
                }

                if (actionTime >= action.time)
                {
                    saction.started      = false;
                    transform.localScale = saction.targetScale;
                    nextAction();
                    return;
                }

                transform.localScale = Vector3.Lerp(saction.originalScale, saction.targetScale, actionTime / action.time);
            }
            else if (action.type == ActionType.Size)
            {
                SizeAction saction = (SizeAction)action;

                if (!saction.started)
                {
                    saction.SetupSize(GetSize());
                }

                if (actionTime >= action.time)
                {
                    saction.started = false;
                    SetSize(saction.targetSize);
                    nextAction();
                    return;
                }

                Vector2 size = Vector2.Lerp(saction.originalSize, saction.targetSize, actionTime / action.time);
                SetSize(size);

                if (sizeUpdatebc && bc2d != null)
                {
                    bc2d.size   = size;
                    bc2d.offset = new Vector2(size.x * pivot.x, size.y * pivot.y);
                }
            }
        }
    }
Example #31
0
    void OnStart()
    {
        if (!FB.IsLoggedIn)
        {
            // Check to show login FB
            if (UserData.Instance.ShowLoginFBTimes < 3 &&
                !Manager.Instance.isShowLoginFB &&
                UserData.Instance.Level >= 10)
            {
                UserData.Instance.ShowLoginFBTimes++;
                Manager.Instance.isShowLoginFB = true;
                Manager.Instance.ShowConfirm("Connect Facebook", "Please connect with facebook to save your progress and see your friends",
                                             (isOK) =>
                {
                    if (isOK)
                    {
                        Debug.Log("Connect FB, choosse OK ...");
                        ConnectFacebook();

                        UserData.Instance.ShowLoginFBTimes = 3;
                    }
                    else
                    {
                        Debug.Log("Cancel, no connect FB ...");
                    }
                });
            }
        }

        if (!Manager.Instance.isShowNewVersion && UserData.Instance.Level >= 4)
        {
            SCross.Instance.ShowMessage("cyrus_bean_jump", "1.6.0", (result, message) => {
            });
            Manager.Instance.isShowNewVersion = true;
        }


        if (UserData.Instance.Level > 15)
        {
            SCross.Instance.GetImage("cyrus_bean_jump", (result, message) => {
                if (result)
                {
                    SCross.Instance.ShowPopupScross();
                }
            });
        }

        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        // Update Facebook
        FBManager.Instance.OnUpdate();

        // Play BGM
        SoundManager.Instance.PlayMusic(SoundID.MainMenu);

        // Sunlight
        if (sunlight != null)
        {
            // Get top
            float top = Camera.main.orthographicSize;

            // Get right
            float right = Camera.main.GetOrthographicWidth();

            sunlight.transform.position      = new Vector3(right - Random.Range(0.0f, 0.1f), top + 2.0f, 0);
            sunlight.transform.localRotation = Quaternion.Euler(0, 0, Random.Range(240.0f, 250.0f));

            int count = sunlight.transform.childCount;

            for (int i = 0; i < count; i++)
            {
                sunlight.transform.GetChild(i).localScale = new Vector3(Random.Range(9.0f, 10.0f), Random.Range(0.85f, 1.0f), 1.0f);
            }

            float startOpacity = Random.value * 0.1f;
            sunlight.SetAlpha(startOpacity, true);

            var rotate  = RotateAction.RotateBy(Random.Range(-20.0f, -25.0f), 18.0f, Ease.Linear, LerpDirection.PingPongForever);
            var fadeIn  = FadeAction.RecursiveFadeTo(Random.Range(0.6f, 0.7f), 18.0f);
            var delay1  = DelayAction.Create(6.0f);
            var fadeOut = FadeAction.RecursiveFadeTo(startOpacity, 18.0f);
            var delay2  = DelayAction.Create(6.0f);
            var fade    = SequenceAction.Create(fadeIn, delay1, fadeOut, delay2);
            var action  = ParallelAction.ParallelAll(rotate, RepeatAction.RepeatForever(fade, false));

            sunlight.Play(action);
        }

        // Get ignore raycast
        _ignoreRaycast = GameObject.FindObjectOfType <IgnoreRaycast>();

        if (!UserData.Instance.PlayedCutscene1)
        {
            UserData.Instance.PlayedCutscene1 = true;
            cutscene1.SetActive(true);
        }

        // Update Connect button
        UpdateConnectFacebook(true);

        googleAnalytics.LogScreen("Main Menu");

        _requestUpdater.Play(UpdateRequests);

        Manager.Instance.SetUpdateSendRequests(true);
    }
Example #32
0
    public IEnumerator FadeFader(FadeAction Action)
    {
        Color FaderInitialColor;
        Color FaderFinalColor;

        ScreenFader.gameObject.SetActive(true);
        ScreenFader.transform.SetAsLastSibling();
        FaderInitialColor = ClearColor;
        FaderFinalColor   = WhiteColor;

        ScreenFader.color = FaderInitialColor;

        while (ColorIsNotSimilar(ScreenFader.color, FaderFinalColor))
        {
            ScreenFader.color = Color.Lerp(ScreenFader.color, FaderFinalColor, FadeSpeed);
            yield return(new WaitForEndOfFrame());
        }

        switch (Action)
        {
        case FadeAction.CreateMainMenu:
            CreateMainMenu();
            break;

        case FadeAction.LoadCurrentLevel:
            if (InstantiatedMainMenu)
            {
                Destroy(InstantiatedMainMenu);
            }
            DestroyEverythingInOnTop();
            Manager.StartGame();

            break;

        case FadeAction.LoadListOfLevels:
            DestroyEverythingInOnTop();
            InstantiatedMainMenu.GetComponent <MainMenu>().ShowRelevantModePage();
            break;

        case FadeAction.LoadNextLevel:
            StartCoroutine(EnsureFaderState(0.1f, false));
            Manager.GetGameMode().LevelEnded();
            break;

        case FadeAction.RestartLevel:
            SetFailedScreenState(false);
            Manager.RestartProceedings();
            break;

        case FadeAction.BackToMenu:
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            break;
        }

        FaderInitialColor = WhiteColor;
        FaderFinalColor   = ClearColor;

        ScreenFader.color = FaderInitialColor;

        //This is not completing
        while (ColorIsNotSimilar(ScreenFader.color, FaderFinalColor))
        {
            ScreenFader.color = Color.Lerp(ScreenFader.color, FaderFinalColor, FadeSpeed);
            yield return(new WaitForEndOfFrame());
        }

        ScreenFader.gameObject.SetActive(false);
    }
Example #33
0
 private void Fade(FadeAction mode)
 {
     this.FadeMode = mode;
     timer1.Start();
 }
Example #34
0
 private void StartFadeOutAction()
 {
     if(this.FadeOutAction != null)
     {
         this.FadeOutAction();
         FadeOutAction = null;
     }
 }
    public void Fade(float value, float duration, bool doQueue = false, TweenCallback completeCallback = null)   // value: 0-1. 0 fade in, 1 fade to black
    {
        if (screenFade == null)
        {
            return;
        }

        if (duration <= 0)
        {
            Color c = screenFade.color;
            c.a = value;
            screenFade.color = c;

            if (completeCallback != null)
            {
                completeCallback();
            }
        }
        else
        {
            if (fadeTween != null)
            {
                fadeTween.Kill(true);
            }

            fadeTween = screenFade.DOFade(value, duration).SetEase(Ease.InCubic)
                        .OnStart(() =>
            {
                FadeAction handler = StartedFade;
                if (handler != null)
                {
                    handler(screenFade.color.a);
                }
            })
                        .OnUpdate(() =>
            {
                FadeAction handler = UpdatedFade;
                if (handler != null)
                {
                    handler(screenFade.color.a);
                }
            })
                        .OnComplete(() =>
            {
                if (completeCallback != null)
                {
                    completeCallback();
                }
                FadeAction handler = EndedFade;
                if (handler != null)
                {
                    handler(screenFade.color.a);
                }
            });
        }

        // XXX: Code was for queuing fade actions. Issue with not being able to
        //      resolve race conditions
        #region Oldcode

        /*
         * if( screenFade == null ) { return; }
         *
         * if( doQueue && fadeTween != null ) {
         *  TweenCallback callback = fadeTween.onComplete;
         *  fadeTween.OnComplete(() => {
         *      if( callback != null ) { callback(); }
         *      Fade(value, duration, false, completeCallback);
         *  });
         * } else {
         *  if( fadeTween != null ) { fadeTween.Kill(true); }
         *
         *  if( duration <= 0 ) {
         *      Color c = screenFade.color;
         *      c.a = value;
         *      screenFade.color = c;
         *
         *      if( completeCallback != null ) { completeCallback(); }
         *  } else {
         *      fadeTween = screenFade.DOFade(value, duration).SetEase(Ease.InCubic)
         *          .OnStart(() => {
         *              FadeAction handler = StartedFade;
         *              if( handler != null ) {
         *                  handler(screenFade.color.a);
         *              }
         *          })
         *          .OnUpdate(() => {
         *              FadeAction handler = UpdatedFade;
         *              if( handler != null ) {
         *                  handler(screenFade.color.a);
         *              }
         *          })
         *          .OnComplete(() => {
         *              if( completeCallback != null ) { completeCallback(); }
         *              FadeAction handler = EndedFade;
         *              if( handler != null ) {
         *                  handler(screenFade.color.a);
         *              }
         *          });
         *  }
         * }
         */
        #endregion
    }
Example #36
0
 public void FadeOut(FadeAction Action)
 {
     this.FadeOutAction = Action;
     FadeOut();
 }