-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultiSceneController.cs
113 lines (85 loc) · 3.13 KB
/
MultiSceneController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Serialization;
using UnityEngine.UI;
using Gameplay;
public class MultiSceneController : MonoBehaviour
{
[Serializable]
public struct ScenePathList
{
public string groupName;
public int activeSceneIndex;
public string[] scenePaths;
}
public bool benchmarkMode;
public ScenePathList mainScenePath;
public ScenePathList[] editorScenePaths;
public GameObject[] deactivateAfterLoad;
public string centerSpawnPointName;
public Slider progressSlider;
public Text progressText;
public ShaderVariantCollection[] shaderVariantCollections = new ShaderVariantCollection[0];
IEnumerator Start()
{
AxelF.Zone.dontProbeZones = true;
PlayerInput.ignore = true;
foreach(var go in deactivateAfterLoad)
go.SetActive(true);
if(!Application.isEditor) {
yield return null;
var originalBackgroundLoadingPriority = Application.backgroundLoadingPriority;
Application.backgroundLoadingPriority = ThreadPriority.High;
for(int i = 1; i < mainScenePath.scenePaths.Length; ++i) {
yield return StartCoroutine(LoadScene(i));
}
Application.backgroundLoadingPriority = originalBackgroundLoadingPriority;
yield return null;
progressText.text = "PREWARMING SHADERS";
progressSlider.value = 0.9f;
#if !UNITY_EDITOR
#if !UNITY_STANDALONE_OSX
// There are some prewarming issues that can cause crashes with certain drivers, so try to avoid those here.
if(SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.Vulkan && SystemInfo.graphicsDeviceType != UnityEngine.Rendering.GraphicsDeviceType.Direct3D12)
foreach(var svc in shaderVariantCollections)
svc.WarmUp();
#endif
#endif
yield return null;
progressText.text = "STARTING";
progressSlider.value = 1;
}
GameController gameController;
do gameController = GameController.FindGameController();
while (!gameController);
if(!string.IsNullOrEmpty(centerSpawnPointName)) {
yield return null;
}
gameController.SpawnPlayer(nextFrame: false);
foreach (var go in deactivateAfterLoad)
go.SetActive(false);
AxelF.Zone.dontProbeZones = false;
while (!gameController.debugContext)
yield return null;
if (benchmarkMode)
((DebugControls) gameController.debugContext).EnableBenchmarkMode();
((DebugControls) gameController.debugContext).AssumeControl();
}
IEnumerator LoadScene(int index)
{
var asyncOp = SceneManager.LoadSceneAsync(index, LoadSceneMode.Additive);
if (asyncOp != null)
{
progressText.text = "LOADING '" + mainScenePath.scenePaths[index] + "'";
while (!asyncOp.isDone)
{
progressSlider.value = (((index - 1) + asyncOp.progress) / (mainScenePath.scenePaths.Length - 1)) * 0.8f;
yield return null;
}
if(index == mainScenePath.activeSceneIndex)
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(index));
}
}
}