SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections; | |
3 | using System.Collections.Generic; | |
4 | using UnityEngine; | |
5 | using UnityEngine.SceneManagement; | |
6 | using UnityEngine.UI; | |
7 | using DG.Tweening; | |
8 | public class LoadLevel : MonoBehaviour | |
9 | { | |
10 | public static int scene; | |
11 | ||
12 | private int section = 1; | |
13 | private int level; | |
14 | ||
15 | public Text t; | |
16 | public Text t2; | |
17 | // Use this for initialization | |
18 | private bool stage1= false; | |
19 | private bool stage2=false; | |
20 | private bool stage3= false; | |
21 | private bool stage4= false; | |
22 | ||
23 | IEnumerator AsynchronousLoad() | |
24 | { | |
25 | ||
26 | yield return null; | |
27 | ||
28 | int div = 1; | |
29 | ||
30 | section = (scene / 6)+1; | |
31 | level = scene - section * 6; | |
32 | if (level < 1) level = 1; | |
33 | if (section < 1) section = 1; | |
34 | AsyncOperation ao_root = SceneManager.LoadSceneAsync("Root"); | |
35 | ||
36 | AsyncOperation ao_curr = (scene >= 0) ? SceneManager.LoadSceneAsync("Section_"+ section+"_" + level, LoadSceneMode.Additive) : null; | |
37 | AsyncOperation ao_next = (scene < 6) ? SceneManager.LoadSceneAsync("Section_" + section + "_" + (level + 1), LoadSceneMode.Additive) : null; | |
38 | AsyncOperation ao_prew = (scene > 1) ? SceneManager.LoadSceneAsync("Section_1" + section + "_" + (level - 1), LoadSceneMode.Additive) : null; | |
39 | ||
40 | ao_root.priority = 1; | |
41 | ao_root.allowSceneActivation = false; | |
42 | ||
43 | ||
44 | ||
45 | ||
46 | if (ao_curr != null) | |
47 | { | |
48 | div++; | |
49 | ao_curr.priority = 2; | |
50 | ao_curr.allowSceneActivation = false; | |
51 | } | |
52 | ||
53 | ||
54 | if (ao_prew != null) | |
55 | { | |
56 | div++; | |
57 | ao_prew.priority = 3; | |
58 | ao_prew.allowSceneActivation = false; | |
59 | } | |
60 | ||
61 | if (ao_next != null) | |
62 | { | |
63 | div++; | |
64 | ao_next.priority = 4; | |
65 | ao_next.allowSceneActivation = false; | |
66 | ||
67 | } | |
68 | t.text += "Мистер Дженнингс пришёл на работу \n"; | |
69 | while (!ao_root.isDone) | |
70 | { | |
71 | if (ao_root.progress > 0.1f && stage1 == false) { | |
72 | t.text += "Мистер Дженнингс растапливает печи \n"; | |
73 | stage1 = true; | |
74 | } | |
75 | if (ao_root.progress == 0.9f) | |
76 | { | |
77 | ||
78 | t.text += "Мистер Дженнингс сходит с ума \n"; | |
79 | break; | |
80 | } | |
81 | ||
82 | yield return new WaitForSeconds(1f); | |
83 | ||
84 | } | |
85 | ||
86 | if (ao_prew != null) | |
87 | { | |
88 | while (!ao_prew.isDone) | |
89 | { | |
90 | ||
91 | ||
92 | if (ao_prew.progress == 0.9f) break; | |
93 | yield return new WaitForSeconds(1f); | |
94 | ||
95 | } | |
96 | } | |
97 | t.text += "Мистер Дженнингс cоздаёт своё лучшее произведение \n"; | |
98 | if (ao_next != null) | |
99 | { | |
100 | while (!ao_next.isDone) | |
101 | { | |
102 | ||
103 | ||
104 | if (ao_next.progress == 0.9f) break; | |
105 | yield return new WaitForSeconds(1f); | |
106 | ||
107 | } | |
108 | } | |
109 | ||
110 | ||
111 | if (ao_curr != null) | |
112 | { | |
113 | while (!ao_curr.isDone) | |
114 | { | |
115 | ||
116 | ||
117 | if (ao_curr.progress == 0.9f) { | |
118 | ||
119 | break; } | |
120 | yield return new WaitForSeconds(1f); | |
121 | ||
122 | } | |
123 | }yield return new WaitForSeconds(1f); | |
124 | while (true) | |
125 | { | |
126 | t2.text = "ОНИ ГОТОВЫ, НАЖМИТЕ ЧТОБЫ НАЧАТЬ \n"; | |
127 | if (Input.anyKey) | |
128 | { | |
129 | //yield return new WaitForSeconds(1f); | |
130 | if (ao_curr != null) | |
131 | { | |
132 | ao_curr.allowSceneActivation = true; | |
133 | } | |
134 | ao_root.allowSceneActivation = true; | |
135 | ||
136 | ||
137 | ||
138 | if (ao_prew != null) | |
139 | { | |
140 | ||
141 | ao_prew.allowSceneActivation = true; | |
142 | } | |
143 | if (ao_next != null) | |
144 | { | |
145 | ao_next.allowSceneActivation = true; | |
146 | ||
147 | } | |
148 | //yield return new WaitForSeconds(1f); | |
149 | Debug.Log(LoadLevel.scene - 1); | |
150 | break; | |
151 | } | |
152 | ||
153 | yield return null; | |
154 | } | |
155 | } | |
156 | void Start() | |
157 | { | |
158 | ||
159 | StartCoroutine(AsynchronousLoad()); | |
160 | ||
161 | } | |
162 | ||
163 | } |