-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathBoltInitSinglePlayer.cs
More file actions
94 lines (80 loc) · 1.84 KB
/
Copy pathBoltInitSinglePlayer.cs
File metadata and controls
94 lines (80 loc) · 1.84 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
using System;
using System.Collections;
using System.Collections.Generic;
using Photon.Bolt;
using Photon.Bolt.Matchmaking;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Bolt.Samples
{
public class BoltInitSinglePlayer : GlobalEventListener
{
enum State
{
SelectMode,
SelectMap,
StartServer,
Started,
}
State state;
string map;
void OnGUI()
{
Rect tex = new Rect(10, 10, 140, 75);
Rect area = new Rect(10, 90, Screen.width - 20, Screen.height - 100);
GUI.Box(tex, Resources.Load("BoltLogo") as Texture2D);
GUILayout.BeginArea(area);
switch (state)
{
case State.SelectMode: State_SelectMode(); break;
case State.SelectMap: State_SelectMap(); break;
case State.StartServer: State_StartSinglePlayer(); break;
}
GUILayout.EndArea();
}
void State_SelectMode()
{
if (ExpandButton("Start Single Player"))
{
state = State.SelectMap;
}
}
void State_SelectMap()
{
GUILayout.BeginVertical();
foreach (string value in BoltScenes.AllScenes)
{
if (SceneManager.GetActiveScene().name != value)
{
if (ExpandButton(value))
{
map = value;
state = State.StartServer;
}
}
}
GUILayout.EndVertical();
}
void State_StartSinglePlayer()
{
BoltLauncher.StartSinglePlayer();
state = State.Started;
}
public override void BoltStartDone()
{
if (BoltNetwork.IsServer)
{
var id = Guid.NewGuid().ToString().Split('-')[0];
var matchName = string.Format("{0} - {1}", id, map);
BoltMatchmaking.CreateSession(
sessionID: matchName,
sceneToLoad: map
);
}
}
bool ExpandButton(string text)
{
return GUILayout.Button(text, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
}
}
}