private IEnumerator Fade(FadeDirection fadeDirection, FadeDirection fadeDirection1 = FadeDirection.In) { float alpha = (fadeDirection == FadeDirection.Out)? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out)? 0 : 1; if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } fadeOutUIImage.enabled = false; } else { fadeOutUIImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } } if (fadeDirection1 == FadeDirection.Out) { fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, 1); yield return(new WaitForSeconds(1f)); co = StartCoroutine(Fade(FadeDirection.Out)); yield return(null); } }
private IEnumerator Fade(FadeDirection fadeDirection, GameObject gameObject) { float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; var image = gameObject.GetComponent <Image>(); if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection, image); yield return(null); } image.enabled = false; } else { image.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection, image); yield return(null); } } }
private IEnumerator FadeAudio(FadeDirection direction, System.Action onComplete) { const int numFadeSteps = 100; float stepAmount = 1f / numFadeSteps; float easeSpeed = audioFadeDuration / numFadeSteps; float easeStart = minVolume; float easeGoal = maxVolume; if (direction == FadeDirection.Down) { easeStart = maxVolume; easeGoal = minVolume; } for (float pct = 0; pct <= 1f; pct += stepAmount) { float volumeLevel; if (direction == FadeDirection.Down) { volumeLevel = Mathfx.Sinerp(easeStart, easeGoal, pct); } else { volumeLevel = Mathfx.Coserp(easeStart, easeGoal, pct); } source.volume = volumeLevel; yield return(new WaitForSeconds(easeSpeed)); } onComplete(); }
/// <summary> /// UI & Scene Effects /// </summary> private void SetColorImage(ref float alpha, FadeDirection fadeDirection) { fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, alpha); fadeOutLoadingImage.color = new Color(fadeOutLoadingImage.color.r, fadeOutLoadingImage.color.g, fadeOutLoadingImage.color.b, alpha); alpha += Time.deltaTime * (1.0f / fadeSpeed) * ((fadeDirection == FadeDirection.Out) ? -1 : 1); }
/// <summary> /// Starts the fading using <see cref="Start"/> and toggled the fade direction afterwards /// </summary> /// <param name="monoBehaviour"></param> /// <param name="fadeDirection"></param> /// <param name="duration"></param> public void StartToggle(MonoBehaviour monoBehaviour, ref FadeDirection fadeDirection, float duration) { Start(monoBehaviour, fadeDirection, duration); // toggle fade direction fadeDirection = fadeDirection == FadeDirection.In ? FadeDirection.Out : FadeDirection.In; }
// FADE TRANSITION FUNCTIONS public IEnumerator Fade(FadeDirection fadeDirection) { fadeOutUIImage.gameObject.SetActive(true); float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } fadeOutUIImage.enabled = false; } else { fadeOutUIImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } } }
private ScreenEffects() { _fadeDirection = FadeDirection.None; _fadeTexture = new Texture2D(Engine.Device, 1, 1); _fadeTexture.SetData<Color>(new Color[] { Color.Black }); }
public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection) { yield return(Fade(fadeDirection)); SceneManager.LoadScene(zonaDestino); Debug.Log(zonaDestino); }
public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection, int sceneToLoad, float opacity) { yield return(Fade(fadeDirection, opacity)); SceneManager.LoadScene(sceneToLoad); this.gameObject.SetActive(false); }
private bool TryMoveNext() { targetTextElement.text = string.Empty; if (timelineEnumerator.MoveNext()) { currentElement = timelineEnumerator.Current; if (currentElement == null) { currentTimeline = null; return(false); } else { doneWithCurrentElement = false; fadeInDone = false; fadeOutDone = false; fadeDirection = FadeDirection.None; elementDisplayedAt = float.NaN; return(true); } } else { return(false); } }
private IEnumerator Fade(FadeDirection fadeDirection) { float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } FadeOutUIImage.enabled = false; } else { FadeOutUIImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } } }
private IEnumerator Fade(FadeDirection fadeDirection) { float alpha = (fadeDirection == FadeDirection.Out) ? 0 : 1; float scale = 0; float scaleEndValue = 50; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 1 : 0; if (fadeDirection == FadeDirection.Out) { //transparent >> flash >> white screen while (scale < scaleEndValue) { scale = Mathf.Lerp(scale, scaleEndValue, 0.01f); if (scale >= 0.8 * scaleEndValue) { scale = scaleEndValue; } flash.localScale = new Vector3(scale, scale, scale); yield return(null); } fadeOutUIImage.enabled = false; } else { fadeOutUIImage.enabled = true; while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } } }
public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection, string sceneToLoad) { Cursor.visible = true; yield return(Fade(fadeDirection)); SceneManager.LoadScene(sceneToLoad); }
public IEnumerator Fade(FadeDirection fadeDirection) { PlayerMover mover = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerMover>(); mover.freeze = true; if (fadeDirection == FadeDirection.In) { for (float i = 0; i <= fadeSpeed; i += Time.deltaTime) { // set color with i as alpha fadeOutUIImage.color = new Color(0, 0, 0, i); StartCoroutine(this.Fade(FadeDirection.Out)); yield return(null); } } else { for (float i = fadeSpeed; i >= 0; i -= Time.deltaTime) { // set color with i as alpha fadeOutUIImage.color = new Color(0, 0, 0, i); mover.freeze = false; yield return(null); } } }
public void BeginFadeEffect(float targetTransparency, float duration) { if ((byte)targetTransparency == Colour.A) { return; } _fadeDirection = FadeDirection.FadeIn; if (targetTransparency < (float)Colour.A) { _fadeDirection = FadeDirection.FadeOut; } _fadeTransparency = Colour.A; float totalFadeChange = targetTransparency - (float)Colour.A; if (totalFadeChange < 0) { totalFadeChange *= -1; } _fadeChangePerSecond = totalFadeChange / (duration / 1000.0f); _targetTransparency = targetTransparency; IsFading = true; }
/* FADE */ IEnumerator Fade(FadeDirection dir, float duration, float minFadeValue, float maxFadeValue) { var _color = _getColor(); if (dir == FadeDirection.In) { for (float i = 1; i >= 0; i -= Time.deltaTime / duration) { var newColor = new Color(_color.r, _color.g, _color.b, Mathf.Lerp(minFadeValue, maxFadeValue, i)); _setColor(newColor); yield return(null); } _setColor(new Color(_color.r, _color.g, _color.b, 0f)); } else { for (float i = 0; i <= 1; i += Time.deltaTime / duration) { var newColor = new Color(_color.r, _color.g, _color.b, Mathf.Lerp(minFadeValue, maxFadeValue, i)); _setColor(newColor); yield return(null); } _setColor(new Color(_color.r, _color.g, _color.b, 1f)); } }
void Update() { if (Input.anyKeyDown) { if (Input.GetKeyDown(toggleKeyCode)) { if (currentFadeCoroutine != null) { StopCoroutine(currentFadeCoroutine); } // start fading if (fadeDirection == FadeDirection.In) { currentFadeCoroutine = StartCoroutine(Fade(minimumValue, maximumValue)); } else if (fadeDirection == FadeDirection.Out) { currentFadeCoroutine = StartCoroutine(Fade(maximumValue, minimumValue)); } // toggle fade direction fadeDirection = fadeDirection == FadeDirection.In ? FadeDirection.Out : FadeDirection.In; } } }
private async Task Fade(FadeDirection direction, CancellationToken cancellationToken) { var deltaDuration = fadeDuration * (direction == FadeDirection.In ? 1f - fadePosition : fadePosition); var endTime = Time.realtimeSinceStartup + deltaDuration; while (Time.realtimeSinceStartup < endTime) { await Task.Yield(); if (!Application.isPlaying) { return; } cancellationToken.ThrowIfCancellationRequested(); var timeRemaining = endTime - Time.realtimeSinceStartup; fadePosition = timeRemaining / fadeDuration; if (direction == FadeDirection.In) { fadePosition = 1f - fadePosition; } blockerCanvasGroup.alpha = Mathf.Lerp(unblockedAlpha, blockedAlpha, fadePosition); } fadePosition = Mathf.Clamp01(fadePosition); }
public IEnumerator FadeRoutine(FadeDirection fadeDirection) { float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; Debug.Log(fadeEndValue); if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } FadeImage.enabled = false; } else { FadeImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } FadeImage.color = new Color(FadeImage.color.r, FadeImage.color.g, FadeImage.color.b, alpha); } }
private ScreenEffects() { _fadeDirection = FadeDirection.None; _fadeTexture = new Texture2D(GameEngine.Device, 1, 1); _fadeTexture.SetData <Color>(new Color[] { Color.Black }); }
private IEnumerator Fade(FadeDirection fadeDirection) { float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } fadeOutUIImage.enabled = false; OnSceneLoadComplete?.Invoke(); } else { OnSceneLoadStarted?.Invoke(); fadeOutUIImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, fadeDirection); yield return(null); } } }
private IEnumerator FadeAndLoad(FadeDirection dir, int lvl) { float alpha = (FadeDirection.Out == dir) ? 1 : 0; float fadeEndValue = (dir == FadeDirection.Out)? 0 : 1; if (dir == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(ref alpha, dir); yield return(null); } fadeOutImage.enabled = false; } else { fadeOutImage.enabled = true; while (alpha <= fadeEndValue) { SetColorImage(ref alpha, dir); yield return(null); } } SceneManager.LoadScene(lvl); }
private IEnumerator Fade(float globalDuration, FadeDirection fadeDirection) { float timeElapsed = 0; while (timeElapsed < globalDuration) { float percentage = timeElapsed / globalDuration; if (fadeDirection == FadeDirection.Out) { percentage = 1.0f - percentage; } percentage = Mathf.Clamp(percentage, 0f, 1f); timeElapsed += Time.deltaTime; ApplyFade(percentage); yield return(null); } // set end value explicitly, otherwise it might not be the specified one because of the time increments if (fadeDirection == FadeDirection.Out) { ApplyFade(0f); } else { ApplyFade(1f); } }
// Update is called once per frame void Update() { if (fadeDirection == FadeDirection.FadeOut) { fadePlaneMaterial.color = new Color(fadePlaneMaterial.color.r, fadePlaneMaterial.color.g, fadePlaneMaterial.color.b, fadeAlphaValue); if (fadeAlphaValue >= 1f) { fadeDirection = FadeDirection.FadeIn; } fadeAlphaValue += Time.deltaTime / FadeSpeed; } else if (fadeDirection == FadeDirection.FadeIn) { fadePlaneMaterial.color = new Color(fadePlaneMaterial.color.r, fadePlaneMaterial.color.g, fadePlaneMaterial.color.b, fadeAlphaValue); if (fadeAlphaValue <= 0f) { FadePlane.SetActive(false); fadeDirection = FadeDirection.None; } fadeAlphaValue -= Time.deltaTime / FadeSpeed; } //if (InformationTimeShowed > 0) { // InformationTimeShowed -= Time.deltaTime; //} else { // InformationsHUD.enabled = false; // InformationsCanvas.enabled = false; //} }
public IEnumerator Fade(FadeDirection fadeDirection, float fadeSpeed, Action <bool> done) { fadeCanvas.gameObject.transform.Find("FadeBackground").gameObject.SetActive(true); Image fadeBackground = fadeCanvas.gameObject.transform.Find("FadeBackground").gameObject.GetComponentInChildren <Image>(); float alpha = (fadeDirection == FadeDirection.Out) ? 1 : 0; float fadeEndValue = (fadeDirection == FadeDirection.Out) ? 0 : 1; fadeBackground.enabled = true; if (fadeDirection == FadeDirection.Out) { while (alpha >= fadeEndValue) { SetColorImage(fadeBackground, ref alpha, fadeDirection, fadeSpeed); yield return(null); } SetColorImage(fadeBackground, ref alpha, fadeDirection, fadeSpeed); fadeBackground.enabled = false; done(true); } else { while (alpha <= fadeEndValue) { SetColorImage(fadeBackground, ref alpha, fadeDirection, fadeSpeed); yield return(null); } SetColorImage(fadeBackground, ref alpha, fadeDirection, fadeSpeed); done(true); } }
/// <summary> /// 判断是否能关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _FormClosing(object sender, FormClosingEventArgs e) { if (_opacity >= _endopacity && FadeOutEnabled) { e.Cancel = true; _direction = FadeDirection.FadeOut; _timer.Enabled = true; _timer.Start(); } }
public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection, string sceneToLoad) { yield return(Fade(fadeDirection)); Debug.Log("Fading and loading " + sceneToLoad); SceneManager.LoadScene(sceneToLoad); }
/// <summary> /// Generic method to handle all opacity transitions. /// </summary> public static void Fade(GameObject gameObject, FadeDirection fadeDirection, float opacity, float duration, Easing easing, bool destroy, string cubicBezier) { Transform[] objectAndChildren = gameObject.GetComponentsInChildren <Transform> (); // If there are child objects, loop through them for (int i = 0; i < objectAndChildren.Length; i++) { // TODO: Provide a check to see whether the child component already has this code. // I was hitting issues before where child objects were not fading in because they had their own // components calling the same coroutine // Check to see if there's a renderer before trying to tween if (objectAndChildren [i].gameObject.GetComponent <Renderer> () != null) { if (CrayonRunner.Instance == null) { Debug.LogWarning(CrayonMessages.PrefabMissing); } else { CrayonRunner.Instance.Run(CrayonTweenCoroutines.FadeCoroutine(objectAndChildren [i].gameObject, fadeDirection, opacity, duration, easing, destroy, cubicBezier)); } } else { Debug.LogWarningFormat("{0} will not tween because it does not contain a Renderer component.", objectAndChildren [i].gameObject.name); } } }
public IEnumerator FadeAndLoadScene(FadeDirection fadeDirection, string sceneToLoad) { fadeOutUIImage.color = new Color(fadeOutUIImage.color.r, fadeOutUIImage.color.g, fadeOutUIImage.color.b, 0f); fadeOutUIImage.enabled = true; yield return(Fade(fadeDirection)); SceneManager.LoadScene(sceneToLoad); }
private void CompleteFade() { _fadeDirection = FadeDirection.None; if (FadeCompleted != null) { FadeCompleted(this, null); } }
private void Fade(FadeDirection fadeDirection) { if (co != null) { StopCoroutine(co); } co = StartCoroutine(FadeText(fadeDirection)); }
public MainMenuScreen(FadeDirection fadeIn) { this.TransitionOnTime = TimeSpan.FromSeconds(0.5f); this.TransitionOffTime = TimeSpan.FromSeconds(0.5f); this.FadeType = FadeType.FadeAlpha; this.FadeIn = fadeIn; this.FadeOut = FadeDirection.Right; HighscoreHelper.ResubmitHighscoreIfNeeded(); }
private IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam) { if (code >= 0) { var num = Marshal.ReadInt32(lParam); if (wParam == (IntPtr) 256) { if (num.ToString(CultureInfo.CurrentCulture) == "164") _altPressed = true; if (num.ToString(CultureInfo.CurrentCulture) == "162") _ctrlPressed = true; if (num.ToString(CultureInfo.CurrentCulture) == "160") _shiftPressed = true; } else if (wParam == (IntPtr) 257) { if (num.ToString(CultureInfo.CurrentCulture) == "164") _altPressed = false; if (num.ToString(CultureInfo.CurrentCulture) == "162") _ctrlPressed = false; if (num.ToString(CultureInfo.CurrentCulture) == "160") _shiftPressed = false; } var fadeDirection = _fadeDirection; _fadeDirection = !_shiftPressed || !_ctrlPressed || !_altPressed ? FadeDirection.FadeOut : FadeDirection.FadeIn; if (fadeDirection != _fadeDirection) { // Let all reachable ("kontexted") items to refresh themselves _kontexts.ForEach(k => k.Items.ForEach(ki => ki.RefreshState())); // Fade the window in Show(); _fadeTimer.Start(); if (_fadeDirection == FadeDirection.FadeIn) MoveToForeground(); } } return CallNextHookEx(_hhook, code, (int) wParam, lParam); }
private void CaptureOrCancelButtonClick(object sender, EventArgs e) { // If we are capturing, stop. If we're not, start. If capturing the From key, this is the cancel button. if (disabled || mapped) return; if (capturingFromKey) { // Cancel capturingFromKey = false; StopCapture(); Close(); return; } if (capturingToKey) { // Cancelling capture - return display to lists. capturingToKey = false; direction = FadeDirection.FromMappedToUnmapped; StopCapture(); } else { // OK, start capturing the To key. // New capture each time: SetMapToBlankMapping(); StartCapture(); capturingToKey = true; direction = FadeDirection.FromUnmappedToMapped; } SetupForm(); Transition(); }
private void MapSelected() { if (disabled) // Nono - Can't map while disabled. Shouldn't be here anyway! return; if (mapped) { // Unmap. MappingsManager.DeleteMapping(map); SetMapToBlankMapping(); Close(); return; } if (capturingToKey) { // Ah, but have we caught a "to" key yet? if (!map.IsValid()) return; capturingToKey = false; StopCapture(); MappingsManager.AddMapping(map); Close(); return; } if (selectingFromKeyFromLists) { Key selectedKey = GetKeyFromListboxValue(); // Have we been sent a dud?? if (selectedKey.Scancode == 0) { // Something went wrong. map = new KeyMapping(); } else { SetMapToBlankMapping(selectedKey.Scancode, selectedKey.Extended); // Need to move panel back to where it was and set the image in the picturebox KeyListsPanel.Location = savedPanelLocation; FromKeyPictureBox.SetImage(ButtonImages.GetButtonImage(map.From.Scancode, map.From.Extended)); selectingFromKeyFromLists = false; keyThreshold = 1; SetListOptionsComboIndex(); SetupForm(); return; } } if (capturingFromKey == false) { // Not mapped, not capturing From or To keys, so this is mapping from list. // Need to call method to create map from name. if (CreateMappingFromListboxValue()) { MappingsManager.AddMapping(map); Close(); } return; } else { // Setting the From key. Map has already been created from keypress capturingFromKey = false; StopCapture(); direction = FadeDirection.FromBlankToUnmapped; SetupForm(); Transition(); } }
private void Fade(AudioSource audioSource, FadeDirection fadeDirection, float fadeSpeed) { var isFading = fadeDirection == FadeDirection.In ? (audioSource.volume < 1.0f) : (audioSource.volume > 0.0f); if (isFading) { var speed = fadeDirection == FadeDirection.In ? fadeSpeed : -FadeSpeed; audioSource.volume = audioSource.volume + speed * Time.deltaTime; } }
public FadeScreen(FadeDirection direction) { if (direction == FadeDirection.None) throw new ArgumentNullException("direction"); m_direction = direction; }
/// <summary> /// Helper draws a translucent black fullscreen sprite, used for fading /// screens in and out, and for darkening the background behind popups. /// </summary> public void FadeScreen() { _alpha = 0; _fadeDirection = FadeDirection.FadeOut; }
public EffectsBuilder Fade(FadeDirection direction) { return Add(EffectsList.Fade, direction.ToString().ToLower()); }
public void UnFadeScreen() { _alpha = 255; _fadeDirection = FadeDirection.FadeIn; }