adding multiplayer

This commit is contained in:
2025-06-30 21:27:55 +02:00
parent 5a813f212c
commit e5616474f1
35 changed files with 712 additions and 525 deletions

View File

@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using R3;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Main;
using RebootKit.Engine.Services.Simulation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Assertions;
@@ -12,7 +12,7 @@ using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.Simulation {
namespace RebootKit.Engine.Simulation {
public interface IWorldContext { }
public class WorldService : IService {
@@ -30,26 +30,28 @@ namespace RebootKit.Engine.Services.Simulation {
struct ActorData {
public Actor Actor;
public readonly bool ManagedByAddressabled;
public readonly bool ManagedByAddressables;
public ActorData(Actor actor, bool managedByAddressabled) {
public ActorData(Actor actor, bool managedByAddressables) {
Actor = actor;
ManagedByAddressabled = managedByAddressabled;
ManagedByAddressables = managedByAddressables;
}
}
readonly List<ActorData> m_Actors = new List<ActorData>();
readonly IDisposable m_UpdateSubscription;
public IWorldContext Context { get; private set; }
public string WorldID {
get {
return string.IsNullOrEmpty(m_Config.name) ? string.Empty : m_Config.name;
}
}
public WorldService() {
m_UpdateSubscription = Observable.EveryUpdate()
.Subscribe(_ => { Tick(Time.deltaTime); });
}
public void Dispose() {
m_UpdateSubscription.Dispose();
Unload();
}
@@ -80,9 +82,21 @@ namespace RebootKit.Engine.Services.Simulation {
}
m_WorldState = WorldState.Loaded;
if (RR.GameInstance is not null) {
RR.GameInstance.OnWorldLoaded();
}
}
public void Unload() {
if (m_WorldState == WorldState.Unloaded) {
return;
}
if (RR.GameInstance is not null) {
RR.GameInstance.OnWorldUnload();
}
KillAllActors();
if (m_SceneInstance.IsValid()) {
@@ -134,7 +148,7 @@ namespace RebootKit.Engine.Services.Simulation {
actor.IsPlaying = false;
actor.OnDespawned();
if (actorData.ManagedByAddressabled) {
if (actorData.ManagedByAddressables) {
Addressables.ReleaseInstance(actor.gameObject);
}
}
@@ -144,7 +158,7 @@ namespace RebootKit.Engine.Services.Simulation {
actorData.Actor.IsPlaying = false;
actorData.Actor.OnDespawned();
if (actorData.ManagedByAddressabled) {
if (actorData.ManagedByAddressables) {
Addressables.ReleaseInstance(actorData.Actor.gameObject);
} else {
UnityEngine.Object.Destroy(actorData.Actor.gameObject);
@@ -154,14 +168,16 @@ namespace RebootKit.Engine.Services.Simulation {
m_Actors.Clear();
}
void Tick(float deltaTime) {
public void Tick(float deltaTime) {
if (m_WorldState != WorldState.Loaded) {
return;
}
foreach (ActorData actorData in m_Actors) {
if (actorData.Actor.IsPlaying) {
actorData.Actor.OnTick(deltaTime);
Actor actor = actorData.Actor;
if (actor.IsPlaying) {
actor.Tick(deltaTime);
}
}
}