Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using DG.Tweening;
- public class LoadLevel : MonoBehaviour
- {
- public static int scene;
- private int section = 1;
- private int level;
- public Text t;
- public Text t2;
- // Use this for initialization
- private bool stage1= false;
- private bool stage2=false;
- private bool stage3= false;
- private bool stage4= false;
- IEnumerator AsynchronousLoad()
- {
- yield return null;
- int div = 1;
- section = (scene / 6)+1;
- level = scene - section * 6;
- if (level < 1) level = 1;
- if (section < 1) section = 1;
- AsyncOperation ao_root = SceneManager.LoadSceneAsync("Root");
- AsyncOperation ao_curr = (scene >= 0) ? SceneManager.LoadSceneAsync("Section_"+ section+"_" + level, LoadSceneMode.Additive) : null;
- AsyncOperation ao_next = (scene < 6) ? SceneManager.LoadSceneAsync("Section_" + section + "_" + (level + 1), LoadSceneMode.Additive) : null;
- AsyncOperation ao_prew = (scene > 1) ? SceneManager.LoadSceneAsync("Section_1" + section + "_" + (level - 1), LoadSceneMode.Additive) : null;
- ao_root.priority = 1;
- ao_root.allowSceneActivation = false;
- if (ao_curr != null)
- {
- div++;
- ao_curr.priority = 2;
- ao_curr.allowSceneActivation = false;
- }
- if (ao_prew != null)
- {
- div++;
- ao_prew.priority = 3;
- ao_prew.allowSceneActivation = false;
- }
- if (ao_next != null)
- {
- div++;
- ao_next.priority = 4;
- ao_next.allowSceneActivation = false;
- }
- t.text += "Мистер Дженнингс пришёл на работу \n";
- while (!ao_root.isDone)
- {
- if (ao_root.progress > 0.1f && stage1 == false) {
- t.text += "Мистер Дженнингс растапливает печи \n";
- stage1 = true;
- }
- if (ao_root.progress == 0.9f)
- {
- t.text += "Мистер Дженнингс сходит с ума \n";
- break;
- }
- yield return new WaitForSeconds(1f);
- }
- if (ao_prew != null)
- {
- while (!ao_prew.isDone)
- {
- if (ao_prew.progress == 0.9f) break;
- yield return new WaitForSeconds(1f);
- }
- }
- t.text += "Мистер Дженнингс cоздаёт своё лучшее произведение \n";
- if (ao_next != null)
- {
- while (!ao_next.isDone)
- {
- if (ao_next.progress == 0.9f) break;
- yield return new WaitForSeconds(1f);
- }
- }
- if (ao_curr != null)
- {
- while (!ao_curr.isDone)
- {
- if (ao_curr.progress == 0.9f) {
- break; }
- yield return new WaitForSeconds(1f);
- }
- }yield return new WaitForSeconds(1f);
- while (true)
- {
- t2.text = "ОНИ ГОТОВЫ, НАЖМИТЕ ЧТОБЫ НАЧАТЬ \n";
- if (Input.anyKey)
- {
- //yield return new WaitForSeconds(1f);
- if (ao_curr != null)
- {
- ao_curr.allowSceneActivation = true;
- }
- ao_root.allowSceneActivation = true;
- if (ao_prew != null)
- {
- ao_prew.allowSceneActivation = true;
- }
- if (ao_next != null)
- {
- ao_next.allowSceneActivation = true;
- }
- //yield return new WaitForSeconds(1f);
- Debug.Log(LoadLevel.scene - 1);
- break;
- }
- yield return null;
- }
- }
- void Start()
- {
- StartCoroutine(AsynchronousLoad());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement