예제 #1
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);
    }
    /// <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 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>
    /// 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));
    }
예제 #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));
    }
 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();
 }
예제 #7
0
    /// <summary>
    /// Resume the paused game
    /// </summary>
    public void ResumeGame()
    {
        Debug.Log("ResumeGame");
        // todo - could fade out
        Paused = false;
        HideMenu();
        Time.timeScale = 0;
        ResumeBackroundMusic();
        if (ActiveGameScene)
        {
            ActiveGameScene.OnResume();
        }
        this.Delay(0.25f, () =>
        {
            float timeScale = 0;
            this.Repeat(0.2f, 10, () =>
            {
                timeScale     += .1f;
                Time.timeScale = timeScale;
            }, true);
        }, true);

        if (PlayerReadyPromise != null)
        {
            PlayerReadyPromise.Done();
        }
    }
예제 #8
0
 private void ClipComplete()
 {
     //Debug.Log("Video End");
     isPlaying = false;
     videoMaterial.SetColor("_Color", visibleColor.WithAlpha(0));
     headingText.SetAlpha(0);
     fadingOutAudio = false;
     fadingOutVideo = false;
     videoPlayer.Stop();
     playPromise.Done();
     //videoCamera.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);
    }