forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneSwitcher.cs
More file actions
61 lines (48 loc) · 1.27 KB
/
Copy pathSceneSwitcher.cs
File metadata and controls
61 lines (48 loc) · 1.27 KB
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
using Unity.Entities;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneSwitcher : MonoBehaviour
{
public float SceneSwitchInterval = 5.0f;
public float TimeUntilNextSwitch = 0.0f;
public int CurrentSceneIndex = 0;
// Use this for initialization
void Start ()
{
DontDestroyOnLoad(this);
LoadNextScene();
}
private void LoadNextScene()
{
var sceneCount = SceneManager.sceneCountInBuildSettings;
var nextIndex = CurrentSceneIndex + 1;
if (nextIndex >= sceneCount)
{
Quit();
return;
}
TimeUntilNextSwitch = SceneSwitchInterval;
CurrentSceneIndex = nextIndex;
var entityManager = World.Active.GetExistingManager<EntityManager>();
var entities = entityManager.GetAllEntities();
entityManager.DestroyEntity(entities);
entities.Dispose();
SceneManager.LoadScene(nextIndex);
}
private void Quit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
// Update is called once per frame
void Update ()
{
TimeUntilNextSwitch -= Time.deltaTime;
if (TimeUntilNextSwitch > 0.0f)
return;
LoadNextScene();
}
}