-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMainMenu.cs
More file actions
130 lines (112 loc) · 3.87 KB
/
MainMenu.cs
File metadata and controls
130 lines (112 loc) · 3.87 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
122
123
124
125
126
127
128
129
130
// Copyright (c) Meta Platforms, Inc. and affiliates.
// Use of the material below is subject to the terms of the MIT License
// https://github.com/oculus-samples/Unity-Decommissioned/tree/main/Assets/Decommissioned/LICENSE
using System.Collections;
using Meta.Decommissioned.UI;
using Meta.Multiplayer.Avatar;
using Meta.Multiplayer.Core;
using Meta.Utilities;
using Meta.XR.Samples;
using NaughtyAttributes;
using Oculus.Interaction;
using TMPro;
using UnityEngine;
namespace Meta.Decommissioned
{
[MetaCodeSample("Decommissioned")]
public class MainMenu : MonoBehaviour
{
[SerializeField] private PokeInteractable m_createLobbyButton;
[SerializeField] private PokeInteractable m_joinLobbyButton;
[SerializeField] private TextMeshProUGUI m_infoText;
[SerializeField] private LeaveMenu m_leaveMenu;
[SerializeField] private Transform m_spawnPoint;
private void Start()
{
var camTransform = PlayerCamera.Instance.transform;
camTransform.SetPositionAndRotation(m_spawnPoint.position, m_spawnPoint.rotation);
DisableButtons();
_ = StartCoroutine(WaitForAvatarLoadToEnableMenu());
Application.Instance.UpdateGroupPresence();
}
private IEnumerator WaitForAvatarLoadToEnableMenu()
{
yield return new WaitUntil(() => FindFirstObjectByType<AvatarEntity>() != null);
var avatarEntity = FindFirstObjectByType<AvatarEntity>();
yield return new WaitUntil(() => Application.Instance.IsAvatarEntityReady(avatarEntity));
EnableButtons();
}
[Button]
public void CreateNewGame()
{
m_leaveMenu.gameObject.SetActive(false);
if (!Application.Instance.ConnectToMatch(true))
{
EnableButtons();
_ = StartCoroutine(ResetInfoTextAfterFrame());
}
}
[Button]
public void JoinGame()
{
m_leaveMenu.gameObject.SetActive(false);
if (!Application.Instance.ConnectToMatch(false))
{
EnableButtons();
_ = StartCoroutine(ResetInfoTextAfterFrame());
}
}
[Button]
public void QuitGame() => UnityEngine.Application.Quit();
public void QuitGameConfirmation()
{
if (m_leaveMenu)
{
m_leaveMenu.ShowMenu();
return;
}
QuitGame();
}
/// <summary>
/// Enables the 'Create Lobby' and 'Join Lobby' buttons.
/// </summary>
public void EnableButtons()
{
m_createLobbyButton.enabled = true;
m_joinLobbyButton.enabled = true;
}
/// <summary>
/// Disables the 'Create Lobby' and 'Join Lobby' buttons.
/// </summary>
public void DisableButtons()
{
m_createLobbyButton.enabled = false;
m_joinLobbyButton.enabled = false;
}
private IEnumerator ResetInfoTextAfterFrame()
{
yield return new WaitForEndOfFrame();
SetInfoText("");
}
/// <summary>
/// Sets the info text located on the main menu control panel.
/// </summary>
/// <param name="newText">The new text to set the info panel to display.</param>
public void SetInfoText(string newText)
{
if (!m_infoText)
{
Debug.LogWarning("m_infoText was not set up in the MainMenu canvas!");
return;
}
if (newText.IsNullOrEmpty())
{
m_infoText.text = "";
m_infoText.gameObject.SetActive(false);
return;
}
m_infoText.gameObject.SetActive(true);
m_infoText.text = newText;
}
}
}