forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontendBootstrap.cs
More file actions
50 lines (46 loc) · 1.59 KB
/
Copy pathFrontendBootstrap.cs
File metadata and controls
50 lines (46 loc) · 1.59 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
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Samples.HelloNetcode
{
public class FrontendBootstrap : MonoBehaviour
{
void Start()
{
#if UNITY_SERVER
string defaultSceneName = "Asteroids";
#else
string defaultSceneName = "Frontend";
#endif
// Commandline always overrides defaults if it exists
string commandScene = CommandLineUtils.GetCommandLineValueFromKey("scene");
if (string.IsNullOrWhiteSpace(commandScene))
{
SceneManager.LoadScene(defaultSceneName);
return;
}
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
{
var scenePath = SceneUtility.GetScenePathByBuildIndex(i);
var scene = Path.GetFileNameWithoutExtension(scenePath);
if (commandScene == scene)
{
SceneManager.LoadScene(commandScene);
return;
}
}
Debug.LogError($"${commandScene} not found. Scenes present in the build\n: {string.Join(',', GetAllScenesInBuild())}");
Application.Quit(-1);
}
private IEnumerable<string> GetAllScenesInBuild()
{
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; ++i)
{
var scenePath = SceneUtility.GetScenePathByBuildIndex(i);
yield return Path.GetFileNameWithoutExtension(scenePath);
}
}
}
}