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
103 lines (82 loc) · 2.68 KB
/
MainMenuManager.cs
File metadata and controls
103 lines (82 loc) · 2.68 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
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
/// <summary>
/// Main Menu Manager only accepts types of MenuReference
/// </summary>
public class MainMenuManager : MenuManager<MenuReference>
{
#if UNITY_EDITOR
[InitializeOnEnterPlayMode]
public static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
{
Initialize();
}
#endif
}
/// <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 static void Initialize()
{
Application.runInBackground = true;
Application.targetFrameRate = 60;
}
private void Awake()
{
Initialize();
Screen.SetResolution(HorizontalResolution, VerticalResolution, false);
}
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
{
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();
}
}