Skip to content

Commit bf4f27c

Browse files
update
Placing the UnifiedBootstrap into its own file.
1 parent e66c22e commit bf4f27c

3 files changed

Lines changed: 96 additions & 89 deletions

File tree

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#if UNIFIED_NETCODE
2-
using System;
3-
using Unity.Entities;
42
using Unity.NetCode;
5-
using UnityEngine;
63

74
namespace Unity.Netcode
85
{
9-
106
#if UNIFIED_NETCODE
117
/// <summary>
128
/// TODO-UNIFIED: Needs further peer review and exploring alternate ways of handling this.
@@ -55,90 +51,5 @@ public void SetNetworkObjectId(ulong networkObjectId)
5551
}
5652
}
5753
#endif
58-
59-
/// <summary>
60-
/// TODO-UNIFIED: Would need to be reviewed for alternate ways of handling this.
61-
/// Creates the hosted world and provides a means to configuring
62-
/// the 2nd port for unified netcode connection.
63-
/// </summary>
64-
internal class UnifiedBootStrap : ClientServerBootstrap
65-
{
66-
public static UnifiedBootStrap Instance { get; private set; }
67-
public static Action OnInitialized;
68-
public static ushort Port = 7979;
69-
public static NetworkManager CurrentNetworkManagerForInitialization;
70-
71-
public static World LastCreatedWorld { get; private set; }
72-
73-
private static int s_WorldCounter = 0;
74-
75-
public override bool Initialize(string defaultWorldName)
76-
{
77-
var networkManager = CurrentNetworkManagerForInitialization;
78-
if (networkManager == NetworkManager.Singleton)
79-
{
80-
Instance = this;
81-
}
82-
83-
AutoConnectPort = Port;
84-
if (base.Initialize(defaultWorldName))
85-
{
86-
Debug.LogError($"[{nameof(UnifiedBootStrap)}] Auto-bootstrap is enabled!!! This will break the POC!");
87-
return true;
88-
}
89-
90-
if (networkManager != null)
91-
{
92-
Debug.Log($"Starting a world for {(networkManager.IsServer ? "Host" : "Client")}");
93-
s_WorldCounter++;
94-
LastCreatedWorld = networkManager.IsServer ? CreateSingleWorldHost($"HostSingleWorld-{s_WorldCounter}")
95-
: CreateClientWorld($"ClientWorld-{s_WorldCounter}");
96-
97-
if (LastCreatedWorld == null)
98-
{
99-
s_WorldCounter--;
100-
Debug.LogError($"[{nameof(UnifiedBootStrap)}] World is null!");
101-
return false;
102-
}
103-
104-
if (!LastCreatedWorld.IsCreated)
105-
{
106-
s_WorldCounter--;
107-
Debug.LogError($"[{nameof(UnifiedBootStrap)}] World was not created!");
108-
return false;
109-
}
110-
111-
//if (networkManager.LogLevel <= LogLevel.Developer)
112-
{
113-
NetworkLog.LogInfo($"[{nameof(UnifiedBootStrap)}] Created world: {LastCreatedWorld.Name} / {LastCreatedWorld.SequenceNumber}");
114-
}
115-
116-
networkManager.NetcodeWorld = (NetcodeWorld)LastCreatedWorld;
117-
if (networkManager.NetworkConfig.Prefabs.HasPendingGhostPrefabs)
118-
{
119-
if (networkManager.LogLevel <= LogLevel.Developer)
120-
{
121-
NetworkLog.LogInfo($"[{nameof(UnifiedBootStrap)}] Registering hybrid prefabs...");
122-
}
123-
124-
networkManager.NetworkConfig.Prefabs.RegisterGhostPrefabs(networkManager);
125-
}
126-
}
127-
else
128-
{
129-
LastCreatedWorld = CreateLocalWorld("LocalWorld");
130-
}
131-
132-
OnInitialized?.Invoke();
133-
134-
return true;
135-
}
136-
137-
~UnifiedBootStrap()
138-
{
139-
LastCreatedWorld = null;
140-
Instance = null;
141-
}
142-
}
14354
}
14455
#endif
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#if UNIFIED_NETCODE
2+
using System;
3+
using Unity.Entities;
4+
using Unity.NetCode;
5+
using UnityEngine;
6+
7+
namespace Unity.Netcode
8+
{
9+
/// <summary>
10+
/// TODO-UNIFIED: Would need to be reviewed for alternate ways of handling this.
11+
/// Creates the hosted world and provides a means to configuring
12+
/// the 2nd port for unified netcode connection.
13+
/// </summary>
14+
internal class UnifiedBootstrap : ClientServerBootstrap
15+
{
16+
public static UnifiedBootstrap Instance { get; private set; }
17+
public static Action OnInitialized;
18+
public static ushort Port = 7979;
19+
public static NetworkManager CurrentNetworkManagerForInitialization;
20+
21+
public static World LastCreatedWorld { get; private set; }
22+
23+
private static int s_WorldCounter = 0;
24+
25+
public override bool Initialize(string defaultWorldName)
26+
{
27+
var networkManager = CurrentNetworkManagerForInitialization;
28+
if (networkManager == NetworkManager.Singleton)
29+
{
30+
Instance = this;
31+
}
32+
33+
AutoConnectPort = Port;
34+
if (base.Initialize(defaultWorldName))
35+
{
36+
Debug.LogError($"[{nameof(UnifiedBootstrap)}] Auto-bootstrap is enabled!!! This will break the POC!");
37+
return true;
38+
}
39+
40+
if (networkManager != null)
41+
{
42+
Debug.Log($"Starting a world for {(networkManager.IsServer ? "Host" : "Client")}");
43+
s_WorldCounter++;
44+
LastCreatedWorld = networkManager.IsServer ? CreateSingleWorldHost($"HostSingleWorld-{s_WorldCounter}")
45+
: CreateClientWorld($"ClientWorld-{s_WorldCounter}");
46+
47+
if (LastCreatedWorld == null)
48+
{
49+
s_WorldCounter--;
50+
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World is null!");
51+
return false;
52+
}
53+
54+
if (!LastCreatedWorld.IsCreated)
55+
{
56+
s_WorldCounter--;
57+
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World was not created!");
58+
return false;
59+
}
60+
61+
//if (networkManager.LogLevel <= LogLevel.Developer)
62+
{
63+
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Created world: {LastCreatedWorld.Name} / {LastCreatedWorld.SequenceNumber}");
64+
}
65+
66+
networkManager.NetcodeWorld = (NetcodeWorld)LastCreatedWorld;
67+
if (networkManager.NetworkConfig.Prefabs.HasPendingGhostPrefabs)
68+
{
69+
if (networkManager.LogLevel <= LogLevel.Developer)
70+
{
71+
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Registering hybrid prefabs...");
72+
}
73+
74+
networkManager.NetworkConfig.Prefabs.RegisterGhostPrefabs(networkManager);
75+
}
76+
}
77+
else
78+
{
79+
LastCreatedWorld = CreateLocalWorld("LocalWorld");
80+
}
81+
82+
OnInitialized?.Invoke();
83+
84+
return true;
85+
}
86+
87+
~UnifiedBootstrap()
88+
{
89+
LastCreatedWorld = null;
90+
Instance = null;
91+
}
92+
}
93+
}
94+
#endif

com.unity.netcode.gameobjects/Runtime/Components/Helpers/UnifiedBootstrap.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)