Beispiel #1
0
    /// <summary>
    /// Awake function of GameManager. Checks if another instance of this GameObject exists and
    /// if not, initializes all required atributes and values of the GameManager, creating a new
    /// one.
    ///
    /// If the GameManager already exists, destroy this gameObject.
    /// </summary>
    private void Awake()
    {
        // If GameManager is not created and initialized...
        if (_instance == null)
        {
            // Set this GameManager as instance
            _instance = this;

            // Set this gameObject to not Destroy when changing between scenes
            DontDestroyOnLoad(gameObject);

            _gc = LoadingFiles.ReadGameConfig();

            // Store canvas' scaling reference resolution
            _scalingReferenceResolution = _cnv.GetComponent <CanvasScaler>().referenceResolution;

            // Initialize Scaling with cam values and scalingreference values
            _scalator = new Scaling(new Vector2(Screen.width, Screen.height), _scalingReferenceResolution, (int)_cam.orthographicSize);

            // Search all panels for later calculation
            ReloadPanels();

            // Load all AssetBundles
            _lab = new LoadAssetBundle();

            // Depending on OS system, load from a different path and using different techniques
#if !UNITY_EDITOR && UNITY_ANDROID
            _lab.LoadBundlesAndroid(Application.streamingAssetsPath + "/AssetBundles/");
#else
            _lab.LoadBundlesWindows(Application.streamingAssetsPath + "/AssetBundles/");
#endif

            // Initialize random value
            _rnd = new Random();

            // Load gameInfo previously generated, data driven information
            _gi = LoadingFiles.ReadGameInfo();

            // Set all values of this information
            SetGameInfo();

            // Get Player information and store it
            _currentPlayerData = LoadingFiles.ReadPlayerData(_maxDifficulty);

            // Set the time waiting for challenge info
            SetTimeForChallenge();
        }
        else if (_instance != this)
        {
            Destroy(gameObject);
        }
    }
Beispiel #2
0
    private void Awake()
    {
        // Si no se ha inicializado el GameManager en ningún momento, lo crea e inicializa
        if (instance == null)
        {
            instance = this;

            DontDestroyOnLoad(gameObject);

            // Nos aseguramos que el canvas tenga la resolución de referencia correcta
            scalingReferenceResolution = cnv.GetComponent <CanvasScaler>().referenceResolution;

            // Aquí iría la inicialización de los datos del jugador
            scalator = new Scaling(new Vector2(Screen.width, Screen.height), scalingReferenceResolution, (int)cam.orthographicSize);

            // Buscamos los paneles para luego realizar los cálculos
            ReloadPanels();

            lab = new LoadAssetBundle();

#if !UNITY_EDITOR && UNITY_ANDROID
            lab.LoadBundlesAndroid(Application.streamingAssetsPath + "/AssetBundles/");
#else
            lab.LoadBundlesWindows(Application.streamingAssetsPath + "/AssetBundles/");
#endif

            rnd = new Random();

            _gi = LoadingFiles.ReadGameInfo();

            SetGameInfo();

            // GetPlayer information
            currentPlayerData = LoadingFiles.ReadPlayerData(_maxDifficulty);
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Checks if the app has the focus and reloads all the info about the
    /// player and the times in case it's needed.
    /// </summary>
    /// <param name="focus"></param>
    private void OnApplicationFocus(bool focus)
    {
        isPaused = !focus;

        if (focus)
        {
            // Get Player information and store it
            GetInstance()._currentPlayerData = LoadingFiles.ReadPlayerData(GetInstance()._maxDifficulty);

            // Set the time waiting for challenge info
            SetTimeForChallenge();
        }
        else
        {
            // Update _currentPlayerData
            if (GetInstance()._challengeWaiting)
            {
                GetInstance()._currentPlayerData._dateForNextChallenge = (int)(ConvertDateToSecond() + GetInstance()._timeChallengeWait);
            }
            // Save player information
            LoadingFiles.SavePlayerData(GetInstance()._currentPlayerData);
        }
    }