forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenuManager.cs
More file actions
121 lines (93 loc) · 3.04 KB
/
MainMenuManager.cs
File metadata and controls
121 lines (93 loc) · 3.04 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
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
113
114
115
116
117
118
119
120
121
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/// <summary>
/// Main Menu Manager only accepts types of MenuReference
/// </summary>
public class MainMenuManager : MenuManager<MenuReference>
{
public static List<MainMenuManager> Managers = new List<MainMenuManager>();
public List<string> GetAllMenuScenes()
{
var allSceneReferences = new List<string>();
foreach (var keypair in m_SceneMenuReferencesByDisplayName)
{
allSceneReferences.AddRange(keypair.Value.GetReferencedScenes());
}
return allSceneReferences;
}
protected override void OnAwake()
{
Managers.Add(this);
}
protected override void OnDestroyInvoked()
{
Managers.Remove(this);
}
}
/// <summary>
/// Used for to construct a menu that accepts a specific type of ISceneReference
/// </summary>
/// <typeparam name="T"></typeparam>
public class MenuManager<T> : MonoBehaviour where T : ISceneReference
{
[SerializeField]
protected List<T> m_SceneMenus;
[SerializeField]
protected Dropdown m_SceneMenusDropDownList;
[HideInInspector]
[SerializeField]
protected Dropdown.OptionDataList m_OptionsList = new Dropdown.OptionDataList();
[Tooltip("Horizontal window resolution size")]
public int HorizontalResolution = 1024;
[Tooltip("Vertical window resolution size")]
public int VerticalResolution = 768;
protected Dictionary<string, T> m_SceneMenuReferencesByDisplayName = new Dictionary<string, T>();
protected virtual void OnAwake()
{
}
private void Awake()
{
Screen.SetResolution(HorizontalResolution, VerticalResolution, false);
OnAwake();
}
protected virtual void OnBuildMenuList()
{
m_OptionsList.options.Clear();
foreach (var menuReference in m_SceneMenus)
{
if (!m_SceneMenuReferencesByDisplayName.ContainsKey(menuReference.GetReferencedScenes()[0]))
{
m_SceneMenuReferencesByDisplayName.Add(menuReference.GetDisplayName(), menuReference);
var optionData = new Dropdown.OptionData();
optionData.text = menuReference.GetDisplayName();
m_OptionsList.options.Add(optionData);
}
}
}
private void Start()
{
OnBuildMenuList();
m_SceneMenusDropDownList.options = m_OptionsList.options;
}
protected virtual void OnSelectMenuScene()
{
string selectedMenuScene = m_SceneMenusDropDownList.options[m_SceneMenusDropDownList.value].text;
if (m_SceneMenuReferencesByDisplayName.ContainsKey(selectedMenuScene))
{
SceneManager.LoadScene(m_SceneMenuReferencesByDisplayName[selectedMenuScene].GetReferencedScenes()[0], LoadSceneMode.Single);
}
}
public void SelectMenuScene()
{
OnSelectMenuScene();
}
protected virtual void OnDestroyInvoked()
{
}
private void OnDestroy()
{
OnDestroyInvoked();
}
}