game version overlay, working on actors sync
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using R3;
|
||||
@@ -18,6 +19,8 @@ using Assert = UnityEngine.Assertions.Assert;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
[assembly: InternalsVisibleTo("RebootKit.Editor")]
|
||||
|
||||
namespace RebootKit.Engine.Main {
|
||||
public static class RR {
|
||||
static readonly Logger s_Logger = new Logger("RR");
|
||||
@@ -61,7 +64,7 @@ namespace RebootKit.Engine.Main {
|
||||
s_Logger.Info("Initializing");
|
||||
s_servicesBag = new DisposableBag();
|
||||
s_disposableBag = new DisposableBag();
|
||||
|
||||
|
||||
s_Logger.Info("Registering core services");
|
||||
Console = CreateService<ConsoleService>();
|
||||
Input = new InputService(EngineConfig.inputConfig);
|
||||
@@ -70,7 +73,9 @@ namespace RebootKit.Engine.Main {
|
||||
|
||||
await InitializeAssetsAsync(cancellationToken);
|
||||
|
||||
// await SteamManager.InitializeAsync(cancellationToken);
|
||||
#if RR_STEAM
|
||||
await SteamManager.InitializeAsync(cancellationToken);
|
||||
#endif
|
||||
}
|
||||
|
||||
// @NOTE: This method is called after the main scene is loaded.
|
||||
@@ -82,6 +87,14 @@ namespace RebootKit.Engine.Main {
|
||||
NetworkManager.Singleton.OnServerStarted += OnServerStarted;
|
||||
NetworkManager.Singleton.OnServerStopped += OnServerStopped;
|
||||
|
||||
#if RR_STEAM
|
||||
if (NetworkManager.Singleton.TryGetComponent(out FacepunchTransport facepunchTransport)) {
|
||||
NetworkManager.Singleton.NetworkConfig.NetworkTransport = facepunchTransport;
|
||||
} else {
|
||||
s_Logger.Error("Steam integration is enabled but FacepunchTransport is not found in NetworkManager.");
|
||||
}
|
||||
#endif
|
||||
|
||||
Observable.EveryUpdate()
|
||||
.Subscribe(_ => Tick())
|
||||
.AddTo(ref s_disposableBag);
|
||||
@@ -116,7 +129,9 @@ namespace RebootKit.Engine.Main {
|
||||
NetworkManager.Singleton.OnServerStopped -= OnServerStopped;
|
||||
}
|
||||
|
||||
// SteamManager.Shutdown();
|
||||
#if RR_STEAM
|
||||
SteamManager.Shutdown();
|
||||
#endif
|
||||
|
||||
s_servicesBag.Dispose();
|
||||
s_disposableBag.Dispose();
|
||||
@@ -195,28 +210,28 @@ namespace RebootKit.Engine.Main {
|
||||
NetworkSystemInstance.SetCurrentWorld(worldID);
|
||||
}
|
||||
|
||||
public static void SpawnActor(AssetReferenceGameObject assetReference,
|
||||
Vector3 position,
|
||||
Quaternion rotation) {
|
||||
public static Actor SpawnActor(AssetReferenceGameObject assetReference,
|
||||
Vector3 position,
|
||||
Quaternion rotation) {
|
||||
if (!IsServer()) {
|
||||
s_Logger.Error("Cannot spawn actor. Not a server instance.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (NetworkSystemInstance is null) {
|
||||
s_Logger.Error("NetworkSystemInstance is not initialized. Cannot spawn actor.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!assetReference.RuntimeKeyIsValid()) {
|
||||
s_Logger.Error("Asset reference is not valid. Cannot spawn actor.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
s_Logger.Info($"Spawning actor from asset reference: {assetReference.RuntimeKey}");
|
||||
NetworkSystemInstance.Actors.SpawnActor(assetReference, position, rotation);
|
||||
return NetworkSystemInstance.Actors.SpawnActor(assetReference, position, rotation);
|
||||
}
|
||||
|
||||
|
||||
public static Actor FindSpawnedActor(ulong actorID) {
|
||||
if (NetworkSystemInstance is null) {
|
||||
s_Logger.Error("NetworkSystemInstance is not initialized. Cannot find actor.");
|
||||
@@ -334,6 +349,8 @@ namespace RebootKit.Engine.Main {
|
||||
}
|
||||
|
||||
public static void ConnectWithSteamID(ulong steamId) {
|
||||
#if RR_STEAM
|
||||
|
||||
if (NetworkManager.Singleton.IsClient) {
|
||||
s_Logger.Error("Already connected to a server");
|
||||
return;
|
||||
@@ -346,6 +363,9 @@ namespace RebootKit.Engine.Main {
|
||||
} else {
|
||||
s_Logger.Error("Network transport is not FacepunchTransport. Cannot connect with Steam ID.");
|
||||
}
|
||||
#else
|
||||
s_Logger.Error("Steam integration is not enabled. Cannot connect with Steam ID.");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Disconnect() { }
|
||||
@@ -395,7 +415,7 @@ namespace RebootKit.Engine.Main {
|
||||
|
||||
GameInstance = Object.Instantiate(EngineConfig.gamePrefab);
|
||||
GameInstance.NetworkObject.Spawn();
|
||||
|
||||
|
||||
NetworkSystemInstance = Object.Instantiate(s_networkSystemPrefab);
|
||||
NetworkSystemInstance.NetworkObject.Spawn();
|
||||
}
|
||||
@@ -407,7 +427,7 @@ namespace RebootKit.Engine.Main {
|
||||
GameInstance.NetworkObject.Despawn();
|
||||
GameInstance = null;
|
||||
}
|
||||
|
||||
|
||||
if (NetworkSystemInstance is not null) {
|
||||
if (NetworkSystemInstance.NetworkObject is not null && NetworkSystemInstance.NetworkObject.IsSpawned) {
|
||||
NetworkSystemInstance.NetworkObject.Despawn();
|
||||
|
||||
Reference in New Issue
Block a user