/// <summary>
    /// Fade the light intensity over time
    /// </summary>
    /// <param name="m">Material</param>
    /// <param name="mb">MonoBehaviour used for events</param>
    /// <param name="fromVolume">From Volume (0-1)</param>
    /// <param name="toVolume">To Volume (0-1)</param>
    /// <param name="seconds">Seconds</param>
    public static GmDelayPromise FadeIntensity(this Light light, MonoBehaviour mb, float fromIntensity, float toIntensity, float seconds, bool realtime)
    {
        if (seconds == 0)
        {
            light.intensity = toIntensity;
            var done = new GmDelayPromise();
            done.Done();
            return(done);
        }

        float intervalSeconds = 0.1f;
        float step            = 0;
        int   fadeSteps       = (int)Math.Ceiling(seconds / intervalSeconds);

        //Debug.Log("Fade Steps = " + fadeSteps);

        light.intensity = fromIntensity;
        return(mb.Repeat(intervalSeconds, fadeSteps, () =>
        {
            step++;
            float timePercent = Mathf.Clamp(step / fadeSteps, 0, 1);
            //Debug.Log("Fade % = " + timePercent);
            light.intensity = Mathf.Lerp(fromIntensity, toIntensity, timePercent);
        }));
    }
    /// <summary>
    /// Fade the main color from one color to another over time
    /// </summary>
    /// <param name="m">Material</param>
    /// <param name="mb">MonoBehaviour used for events</param>
    /// <param name="fromColor">From Color</param>
    /// <param name="toColor">To Color</param>
    /// <param name="seconds">Seconds</param>
    public static GmDelayPromise Fade(this Material mat, MonoBehaviour mb, Color fromColor, Color toColor, float seconds, bool realtime)
    {
        if (seconds == 0)
        {
            mat.SetColor("_Color", toColor);
            var done = new GmDelayPromise();
            done.Done();
            return(done);
        }

        float intervalSeconds = 0.1f;
        float step            = 0;
        int   fadeSteps       = (int)Math.Ceiling(seconds / intervalSeconds);

        //Debug.Log("Fade Steps = " + fadeSteps);

        mat.SetColor("_Color", fromColor);
        return(mb.Repeat(intervalSeconds, fadeSteps, () =>
        {
            step++;
            float timePercent = Mathf.Clamp(step / fadeSteps, 0, 1);
            //Debug.Log("Fade % = " + timePercent);
            mat.SetColor("_Color", Color.Lerp(fromColor, toColor, timePercent));
        }, realtime));
    }
    /// <summary>
    /// Fade the audio source volume over time
    /// </summary>
    /// <param name="m">Material</param>
    /// <param name="mb">MonoBehaviour used for events</param>
    /// <param name="fromVolume">From Volume (0-1)</param>
    /// <param name="toVolume">To Volume (0-1)</param>
    /// <param name="seconds">Seconds</param>
    public static GmDelayPromise FadePitch(this AudioSource source, MonoBehaviour mb, float fromPitch, float toPitch, float seconds, bool realtime)
    {
        if (seconds == 0)
        {
            source.pitch = toPitch;
            var done = new GmDelayPromise();
            done.Done();
            return(done);
        }

        float intervalSeconds = 0.1f;
        float step            = 0;
        int   fadeSteps       = (int)Math.Ceiling(seconds / intervalSeconds);

        //Debug.Log("Fade Steps = " + fadeSteps);

        source.pitch = fromPitch;
        return(mb.Repeat(intervalSeconds, fadeSteps, () =>
        {
            step++;
            float timePercent = Mathf.Clamp(step / fadeSteps, 0, 1);
            //Debug.Log("Fade % = " + timePercent);
            source.pitch = Mathf.Lerp(fromPitch, toPitch, timePercent);
        }, realtime));
    }
    /// <summary>
    /// Start the cutscene
    /// </summary>
    public override void FirstUpdate()
    {
        //base.FirstUpdate();

        // Don't call base
        GameManager.Instance.ActiveGameScene = this;
        GameManager.Instance.DisableScoreCanvas();
        PlayerScript.Instance.HideKinect(0);

        FadeCameraIn();

        if (GameOverSound != null)
        {
            AudioSource.PlayOneShot(GameOverSound);
        }
        if (BackgroundMusic != null)
        {
            GameManager.Instance.PlayBackgroundMusic(BackgroundMusic);
        }

        this.Text = GetComponentInChildren <TMPro.TextMeshPro>();

        Text.Type(this, 0.1f, true, () =>
        {
            //AudioManager.Instance.PlayTypeCharacter();
        });

        //GameManager.Instance.PauseBackroundMusic(Delay * .9f);
        sceneDelay = this.Delay(Delay, () =>
        {
            FadeToScene(NextScene);
        });
    }
Exemplo n.º 5
0
    public static GmDelayPromise FadeAlpha(this SpriteRenderer sr, MonoBehaviour mb, float fromAlpha, float toAlpha, float seconds, bool realtime)
    {
        if (seconds == 0)
        {
            sr.SetAlpha(toAlpha);
            var done = new GmDelayPromise();
            done.Done();
            return(done);
        }

        float intervalSeconds = 0.1f;
        float step            = 0;
        int   fadeSteps       = (int)Math.Ceiling(seconds / intervalSeconds);

        //Debug.Log("Fade Steps = " + fadeSteps);

        sr.SetAlpha(fromAlpha);
        return(mb.Repeat(intervalSeconds, fadeSteps, () =>
        {
            step++;
            float timePercent = Mathf.Clamp(step / fadeSteps, 0, 1);
            //Debug.Log("Fade % = " + timePercent);
            sr.SetAlpha(Mathf.Lerp(fromAlpha, toAlpha, timePercent));
        }, realtime));
    }
Exemplo n.º 6
0
 public void StartTimer(int Duration, int EventTime)
 {
     TimerValue        = Duration;
     Timer.text        = TimerValue.ToString();
     MidTimerEventTime = EventTime;
     TimerPromise      = this.Delay(1, TimerTick);
 }
Exemplo n.º 7
0
    /// <summary>
    /// Fade the current camera out, switch to another camera and fade it in.  Promise when complete
    /// </summary>
    /// <param name="camera"></param>
    /// <returns></returns>
    public GmDelayPromise FadeToCamera(Camera camera, float fadeSeconds)
    {
        GmDelayPromise fadeComplete = new GmDelayPromise();

        // Already faded out?
        if (CameraMask.color.a == 0)
        {
            FadeCameraIn(fadeSeconds, camera).Then(() =>
            {
                fadeComplete.Done();
            });
        }
        else
        {
            FadeCameraOut(fadeSeconds)
            .Then(() =>
            {
                FadeCameraIn(fadeSeconds, camera).Then(() =>
                {
                    fadeComplete.Done();
                });
            });
        }

        return(fadeComplete);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Play a video clip using the current settings
    /// </summary>
    /// <param name="clip">The video clip to play (if null, then current clip will play)</param>
    public GmDelayPromise PlayClip(VideoClip clip = null, string heading = null)
    {
        // Heading
        if (headingText != null)
        {
            headingText.SetText(heading ?? "");
        }

        videoMaterial.SetColor("_Color", FadeInFrom);
        GameManager.Instance.ShowCamera(videoCamera);

        this.playPromise = new GmDelayPromise();

        // If no clip - play the one already set
        if (clip != null)
        {
            videoPlayer.clip = clip;
        }

        //Debug.Log("Prepare");
        videoPlayer.Prepare();
        isPlaying = true;

        fadingIn       = false;
        fadingOutAudio = false;
        fadingOutVideo = false;

        return(playPromise);
    }
    public static GmDelayPromise Delay(this MonoBehaviour mb, float delaySeconds, Action callback = null, bool realtime = false)
    {
        var promise = new GmDelayPromise {
            monobehaviour = mb
        };

        promise.coroutine = mb.StartCoroutine(WaitThenCallback(mb, delaySeconds, 1, callback, promise, realtime));
        return(promise);
    }
Exemplo n.º 10
0
 private void ShowText()
 {
     if (CurrentTextDisappearDelay != null)
     {
         CurrentTextDisappearDelay.Abort();
     }
     DiffText.gameObject.SetActive(true);
     CurrentTextDisappearDelay = this.Delay(TextScreenTime, () => { DiffText.gameObject.SetActive(false); });
 }
Exemplo n.º 11
0
 /// <summary>
 /// Invite the player
 /// </summary>
 public GmDelayPromise InviteGame()
 {
     Debug.Log("InviteGame");
     Paused = true;
     GameManager.Instance.SetTimeScale(0);
     if (ActiveGameScene)
     {
         ActiveGameScene.OnPause();
     }
     ShowMenu("Invite", 1);
     PauseBackroundMusic();
     PlayerReadyPromise = new GmDelayPromise();
     return(PlayerReadyPromise);
 }
Exemplo n.º 12
0
 void TimerTick()
 {
     TimerValue -= 1;
     Timer.text  = TimerValue.ToString();
     if (TimerValue == MidTimerEventTime)
     {
         TimerEvent();
     }
     if (TimerValue <= PulseTime)
     {
         TimerPulseSound.PlayOneShot(TimerPulseSound.clip);
         // Scale to designed size over one second
         float scale2     = 1.6f;
         float scale      = scale2;
         int   scaleSteps = 4;
         this.Timer.rectTransform.localScale = new Vector3(scale, scale);
         this.Repeat(1 / (scaleSteps + 1), scaleSteps, () =>
         {
             // Aborted
             //if (SecondsRemaining < 0)
             //{
             //    this.Timer.text = "";
             //    return;
             //}
             scale -= (scale2 - 1) / (float)scaleSteps;
             this.Timer.rectTransform.localScale = new Vector3(scale, scale);
         });
     }
     if (TimerValue > 0)
     {
         TimerPromise = this.Delay(1, TimerTick);
     }
     else
     {
         TimerEnded();
         Timer.text = "";
         //Timer.enabled = false;
     }
 }
    public static GmDelayPromise FadeAlpha(this TextMeshPro tmp, float fromAlpha, float toAlpha, float seconds, bool realtime)
    {
        if (seconds == 0)
        {
            tmp.SetAlpha(toAlpha);
            var done = new GmDelayPromise();
            done.Done();
            return done;
        }

        float intervalSeconds = 0.1f;
        float step = 0;
        int fadeSteps = (int)Math.Ceiling(seconds / intervalSeconds);
        //Debug.Log("Fade Steps = " + fadeSteps);

        tmp.SetAlpha(fromAlpha);
        return tmp.Repeat(intervalSeconds, fadeSteps, () =>
        {
            step++;
            float timePercent = Mathf.Clamp(step / fadeSteps, 0, 1);
            //Debug.Log("Fade % = " + timePercent);
            tmp.SetAlpha(Mathf.Lerp(fromAlpha, toAlpha, timePercent));
        }, true);
    }
Exemplo n.º 14
0
    /// <summary>
    /// Start the cutscene
    /// </summary>
    public override void FirstUpdate()
    {
        // Don't call base
        GameManager.Instance.ActiveGameScene = this;
        GameManager.Instance.DisableScoreCanvas();
        PlayerScript.Instance.HideKinect(0);

        // Hide characters
        foreach (var character in Characters)
        {
            character.FadeAlpha(this, 0, 0, 0, true);
        }

        FadeCameraIn();
        if (BackgroundMusic != null)
        {
            GameManager.Instance.PlayBackgroundMusic(BackgroundMusic);
        }

        Text = GetComponentInChildren <TextMeshPro>();

        Text.Type(this, 0.05f, true, () =>
        {
            //AudioManager.Instance.PlayTypeCharacter();
        });
        charDelay = this.Delay(CharacterIntroDelay, () =>
        {
            FadeCharacters(0);
        });
        GameManager.Instance.PauseBackroundMusic(Delay * .9f);
        sceneDelay = this.Delay(Delay, () =>
        {
            GameManager.Instance.EnableScoreCanvas();
            FadeToScene(NextScene);
        });
    }
Exemplo n.º 15
0
    /// <summary>
    /// Start the countdown timer
    /// </summary>
    public void StartCountdown()
    {
        //Debug.Log("Instructions StartCountdown");
        if (CountdownSeconds < 0)
        {
            return;
        }

        GameManager.Instance.PreloadScene(GameSceneName, false);

        this.CountdownText.text = "";
        SecondsRemaining        = CountdownSeconds;

        // Pre-countdown delay
        this.Delay(PreCountdownSeconds, () =>
        {
            //Debug.Log("Pre-Countdown complete");

            // Number of seconds
            TimerPromise = this.Repeat(1f, this.CountdownSeconds + 1, () =>
            {
                //Debug.Log("Countdown seconds remaining: " + SecondsRemaining);

                if (SecondsRemaining < 0)
                {
                    // Aborted
                    StopCountdown();
                    return;
                }
                if (SecondsRemaining == 0)
                {
                    this.CountdownText.text = "Go!";
                    AudioSource.PlayOneShot(CountdownGoSound);

                    // Instructions complete
                    this.Delay(1f, () =>
                    {
                        this.CountdownText.text = "";
                        GameManager.Instance.FadeToScene(GameSceneName, FadeSeconds);
                    });
                }
                else
                {
                    if (Time.timeScale > 0 && !GameManager.Instance.Paused)
                    {
                        this.CountdownText.text = SecondsRemaining.ToString();
                        AudioSource.PlayOneShot(CountdownSecondSound);
                        SecondsRemaining--;
                    }
                    else
                    {
                        this.CountdownText.text = "";
                    }
                }

                // Scale to designed size over one second
                float scale2   = 1.6f;
                float scale    = scale2;
                int scaleSteps = 4;
                this.CountdownText.rectTransform.localScale = new Vector3(scale, scale);
                this.Repeat(1 / (scaleSteps + 1), scaleSteps, () =>
                {
                    // Aborted
                    if (SecondsRemaining < 0)
                    {
                        this.CountdownText.text = "";
                        return;
                    }
                    scale -= (scale2 - 1) / (float)scaleSteps;
                    this.CountdownText.rectTransform.localScale = new Vector3(scale, scale);
                });
            });
        });
    }
 private static IEnumerator WaitThenCallback(MonoBehaviour mb, float seconds, int times, Action callback, GmDelayPromise promise, bool realTime)
 {
     for (var i = 0; i < times || times == int.MaxValue; i++)
     {
         if (realTime)
         {
             yield return(new WaitForSecondsRealtime(seconds));
         }
         else
         {
             yield return(new WaitForSeconds(seconds));
         }
         if (callback != null && mb != null && mb.gameObject != null && mb.isActiveAndEnabled)
         {
             try
             {
                 callback();
             }
             catch (Exception ex)
             {
                 Debug.LogError("Callback Error: " + ex.Message);
             }
         }
     }
     promise.Done();
 }