<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class SceneShifter : MonoBehaviour
{
    private const string QuitString = "QUITGAME";

    private const float DefaultShiftDuration = 1f, DefaultFadeDuration = .5f;
    private const float MinBlackScreenTime = .5f;

#pragma warning disable 0649   //Serialized Fields
    [SerializeField]
    private bool useRealTime = true;
    [SerializeField]
    private Image blocker;
#pragma warning restore 0649

    private string goalScene;
    private float shiftDuration;
    private float fadeDuration;
    private bool leavingScene;
    private float shiftStartTime;
    private float sceneLoadedTime;

    private AsyncOperation operation;
	
	void Update()
	{
        if (leavingScene)
        {
            float timeLeft = shiftStartTime + shiftDuration - getCurrentTime();
            if (timeLeft < fadeDuration)
            {
                setBlockerAlpha(Mathf.Lerp(1f, 0f, timeLeft / fadeDuration));

                if (timeLeft < -MinBlackScreenTime)
                {
                    if (!goalScene.Equals(QuitString))
                    {
                        SceneManager.LoadScene(goalScene);
                        operation.allowSceneActivation = true;
                        sceneLoadedTime = -1f;
                        leavingScene = false;
                    }
                    else
                    {
                        Application.Quit();
                    }
                }
            }
        }
        else
        {
            if (sceneLoadedTime < 0f)
            {
                sceneLoadedTime = getCurrentTime();
                operation = null;
            }


            float timeSinceLoaded = getCurrentTime() - sceneLoadedTime;
            float alpha = Mathf.Lerp(1f, 0f, timeSinceLoaded / fadeDuration);
            setBlockerAlpha(alpha);
            if (alpha <= 0f)
            {
                PauseManager.disablePause = false;
                gameObject.SetActive(false);
            }
        }
	}

    public void startShift(string goalScene, float shiftDuration = DefaultShiftDuration, float fadeDuration = DefaultFadeDuration)
    {
        if (operation != null)
            return;

        PauseManager.disablePause = true;
        gameObject.SetActive(true);
        this.shiftDuration = shiftDuration;
        this.fadeDuration = fadeDuration;
        this.goalScene = goalScene;
        leavingScene = true;
        shiftStartTime = getCurrentTime();
        setBlockerAlpha(0f);

        if (!goalScene.Equals(QuitString))
        {
            operation = SceneManager.LoadSceneAsync(goalScene);
            operation.allowSceneActivation = false;
        }
    }

    public void shiftToQuitGame(float shiftDuration = DefaultShiftDuration, float fadeDuration = DefaultFadeDuration)
    {
        startShift(QuitString, shiftDuration, fadeDuration);
    }

    public float getShiftDuration()
    {
        return shiftDuration;
    }

    public void setShiftDuration(float shiftDuration)
    {
        this.shiftDuration = shiftDuration;
    }

    public float getFadeDuration()
    {
        return fadeDuration;
    }

    public void setFadeDuration(float fadeDuration)
    {
        this.fadeDuration = fadeDuration;
    }

    float getCurrentTime()
    {
        return useRealTime ? Time.realtimeSinceStartup : Time.time;
    }

    void setBlockerAlpha(float alpha)
    {
        blocker.color = new Color(0f, 0f, 0f, alpha);
    }

    float getblockerAlpha()
    {
        return blocker.color.a;
    }
}
<commit_msg>Use game time for SceneShifter when timeScale > 0<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class SceneShifter : MonoBehaviour
{
    private const string QuitString = "QUITGAME";

    private const float DefaultShiftDuration = 1f, DefaultFadeDuration = .5f;
    private const float MinBlackScreenTime = .5f;

#pragma warning disable 0649   //Serialized Fields
    [SerializeField]
    private Image blocker;
#pragma warning restore 0649

    private string goalScene;
    private float shiftDuration;
    private float fadeDuration;
    private bool leavingScene;
    private float shiftStartGameTime, shiftStartRealTime;
    private float sceneLoadedGameTime, sceneLoadedRealTime;

    private AsyncOperation operation;
	
	void Update()
	{
        if (leavingScene)
        {
            float timeLeft = getShiftStartTime() + shiftDuration - getCurrentTime();
            if (timeLeft < fadeDuration)
            {
                setBlockerAlpha(Mathf.Lerp(1f, 0f, timeLeft / fadeDuration));

                if (timeLeft < -MinBlackScreenTime)
                {
                    if (!goalScene.Equals(QuitString))
                    {
                        SceneManager.LoadScene(goalScene);
                        operation.allowSceneActivation = true;
                        sceneLoadedGameTime = sceneLoadedRealTime = -1f;
                        leavingScene = false;
                    }
                    else
                    {
                        Application.Quit();
                    }
                }
            }
        }
        else
        {
            if (sceneLoadedGameTime < 0f)
            {
                sceneLoadedGameTime = Time.time;
                sceneLoadedRealTime = Time.realtimeSinceStartup;
                operation = null;
            }


            float timeSinceLoaded = getCurrentTime() - getSceneLoadedTime();
            float alpha = Mathf.Lerp(1f, 0f, timeSinceLoaded / fadeDuration);
            setBlockerAlpha(alpha);
            if (alpha <= 0f)
            {
                PauseManager.disablePause = false;
                gameObject.SetActive(false);
            }
        }
	}

    public void startShift(string goalScene, float shiftDuration = DefaultShiftDuration, float fadeDuration = DefaultFadeDuration)
    {
        if (operation != null)
            return;

        PauseManager.disablePause = true;
        gameObject.SetActive(true);
        this.shiftDuration = shiftDuration;
        this.fadeDuration = fadeDuration;
        this.goalScene = goalScene;
        leavingScene = true;
        shiftStartGameTime = Time.time;
        shiftStartRealTime = Time.realtimeSinceStartup;
        setBlockerAlpha(0f);

        if (!goalScene.Equals(QuitString))
        {
            operation = SceneManager.LoadSceneAsync(goalScene);
            operation.allowSceneActivation = false;
        }
    }

    public void shiftToQuitGame(float shiftDuration = DefaultShiftDuration, float fadeDuration = DefaultFadeDuration)
    {
        startShift(QuitString, shiftDuration, fadeDuration);
    }

    public float getShiftDuration()
    {
        return shiftDuration;
    }

    public void setShiftDuration(float shiftDuration)
    {
        this.shiftDuration = shiftDuration;
    }

    public float getFadeDuration()
    {
        return fadeDuration;
    }

    public void setFadeDuration(float fadeDuration)
    {
        this.fadeDuration = fadeDuration;
    }

    float getCurrentTime()
    {
        return Time.timeScale > 0f ? Time.time : Time.realtimeSinceStartup;
    }

    float getShiftStartTime()
    {
        return Time.timeScale > 0f ? shiftStartGameTime : shiftStartRealTime;
    }
    
    float getSceneLoadedTime()
    {
        return Time.timeScale > 0f ? sceneLoadedGameTime : sceneLoadedRealTime;
    }

    void setBlockerAlpha(float alpha)
    {
        blocker.color = new Color(0f, 0f, 0f, alpha);
    }

    float getblockerAlpha()
    {
        return blocker.color.a;
    }
}

{'fraction_non_alphanumeric': 0.0720790047454149, 'fraction_numerical': 0.0061562139284340135, 'mean_word_length': 1.9010416666666667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5269773', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1970, 'n_words': 448}