-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathUnifiedBootstrap.cs
More file actions
95 lines (82 loc) · 3.32 KB
/
Copy pathUnifiedBootstrap.cs
File metadata and controls
95 lines (82 loc) · 3.32 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
#if UNIFIED_NETCODE
using System;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
namespace Unity.Netcode
{
/// <summary>
/// TODO-UNIFIED: Needs furthery review and proper error messaging using the new logging context.
/// Handles the bootstrap process for both client and server in unified mode. This is used to create the world and set it on the
/// NetworkManager during initialization.
/// </summary>
internal class UnifiedBootstrap : ClientServerBootstrap
{
public static UnifiedBootstrap Instance { get; private set; }
public static Action OnInitialized;
public static ushort Port = 7979;
public static NetworkManager CurrentNetworkManagerForInitialization;
public static World LastCreatedWorld { get; private set; }
private static int s_WorldCounter = 0;
public override bool Initialize(string defaultWorldName)
{
var networkManager = CurrentNetworkManagerForInitialization;
if (networkManager == NetworkManager.Singleton)
{
Instance = this;
}
AutoConnectPort = Port;
if (base.Initialize(defaultWorldName))
{
Debug.LogError($"[{nameof(UnifiedBootstrap)}] Auto-bootstrap is enabled!!! This will break the POC!");
return true;
}
if (networkManager != null)
{
Debug.Log($"Starting a world for {(networkManager.IsServer ? "Host" : "Client")}");
s_WorldCounter++;
LastCreatedWorld = networkManager.IsServer ? CreateSingleWorldHost($"HostSingleWorld-{s_WorldCounter}")
: CreateClientWorld($"ClientWorld-{s_WorldCounter}");
if (LastCreatedWorld == null)
{
s_WorldCounter--;
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World is null!");
return false;
}
if (!LastCreatedWorld.IsCreated)
{
s_WorldCounter--;
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World was not created!");
return false;
}
if (networkManager.LogLevel <= LogLevel.Developer)
{
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Created world: {LastCreatedWorld.Name} / {LastCreatedWorld.SequenceNumber}");
}
networkManager.NetcodeWorld = (NetcodeWorld)LastCreatedWorld;
#if UNIFIED_NGO_REGISTERS_PREFABS
if (networkManager.NetworkConfig.Prefabs.HasPendingGhostPrefabs)
{
if (networkManager.LogLevel <= LogLevel.Developer)
{
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Registering hybrid prefabs...");
}
networkManager.NetworkConfig.Prefabs.RegisterGhostPrefabs(networkManager);
}
#endif
}
else
{
LastCreatedWorld = CreateLocalWorld("LocalWorld");
}
OnInitialized?.Invoke();
return true;
}
~UnifiedBootstrap()
{
LastCreatedWorld = null;
Instance = null;
}
}
}
#endif