forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneNavigation.cs
More file actions
68 lines (53 loc) · 1.77 KB
/
Copy pathSceneNavigation.cs
File metadata and controls
68 lines (53 loc) · 1.77 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
62
63
64
65
66
67
68
using System;
using Unity.Entities;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SceneNavigation : MonoBehaviour
{
#pragma warning disable 649
[SerializeField]
Button m_MenuButton;
[SerializeField]
Button m_PreviousButton;
[SerializeField]
Text m_Title;
[SerializeField]
Button m_NextButton;
[SerializeField]
Button m_ReloadButton;
[SerializeField]
EventSystem m_EventSystem;
internal LoaderScene Loader;
#pragma warning restore 649
void Start()
{
DontDestroyOnLoad(m_EventSystem);
DontDestroyOnLoad(gameObject);
m_MenuButton.onClick.AddListener(() =>
{
var entityManager = BasePhysicsDemo.DefaultWorld.EntityManager;
entityManager.DestroyEntity(
entityManager.CreateEntityQuery(new EntityQueryDesc
{
None = new ComponentType[] { typeof(CharacterControllerInput) }
})
);
SceneManager.LoadScene(0, LoadSceneMode.Single);
Destroy(gameObject);
Destroy(m_EventSystem.gameObject);
});
m_PreviousButton.onClick.AddListener(() => { Loader.LoadLevel(-1); });
m_NextButton.onClick.AddListener(() => { Loader.LoadLevel(1); });
m_ReloadButton.onClick.AddListener(() => { Loader.LoadLevel(0); });
OnSceneLoaded(SceneManager.GetActiveScene(), default);
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
m_Title.text = scene.name;
EventSystem.current.SetSelectedGameObject(m_NextButton.gameObject);
}
void OnDestroy() => SceneManager.sceneLoaded -= OnSceneLoaded;
}