-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathGameOptions.cs
More file actions
51 lines (43 loc) · 1.62 KB
/
GameOptions.cs
File metadata and controls
51 lines (43 loc) · 1.62 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
using System;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
using UnityEngine.UI;
namespace Samples.Asteroids.Host.UI
{
public class GameOptions : MonoBehaviour
{
GameObject m_OptionsPanel;
InputField m_AsteroidCountTextBox;
EntityQuery m_ServerSettingsQuery;
void Start()
{
m_OptionsPanel = gameObject.transform.Find("Panel").gameObject;
m_OptionsPanel.SetActive(false);
m_AsteroidCountTextBox = m_OptionsPanel.transform.Find("Count").GetComponent<InputField>();
}
void Update()
{
// Can only set options on the host/server
if (ClientServerBootstrap.ServerWorld == null)
return;
if ( Input.GetKeyDown("o") )
{
m_OptionsPanel.SetActive(!m_OptionsPanel.activeSelf);
if (m_OptionsPanel.activeSelf)
{
if (m_ServerSettingsQuery==default)
m_ServerSettingsQuery = ClientServerBootstrap.ServerWorld.EntityManager.CreateEntityQuery(typeof(ServerSettings));
if (m_ServerSettingsQuery.IsEmpty)
return;
var numAsteroids = m_ServerSettingsQuery.GetSingleton<ServerSettings>().levelData.numAsteroids;
m_AsteroidCountTextBox.text = $"{numAsteroids}";
}
}
}
public void SetAsteroidCount()
{
m_ServerSettingsQuery.GetSingletonRW<ServerSettings>().ValueRW.levelData.numAsteroids = Int32.Parse( m_AsteroidCountTextBox.text );
}
}
}