adding multiplayer
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
using RebootKit.Engine.Foundation;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKit.Engine.Services.Simulation {
|
||||
namespace RebootKit.Engine.Simulation {
|
||||
public abstract class Actor : MonoBehaviour {
|
||||
[field: SerializeField]
|
||||
public SerializableGuid ActorGuid { get; private set; } = SerializableGuid.New();
|
||||
|
||||
bool m_IsPlaying = false;
|
||||
public bool IsPlaying {
|
||||
get {
|
||||
@@ -39,7 +36,13 @@ namespace RebootKit.Engine.Services.Simulation {
|
||||
public virtual void OnEndPlay() {
|
||||
}
|
||||
|
||||
public virtual void OnTick(float deltaTime) {
|
||||
public virtual void Tick(float deltaTime) {
|
||||
}
|
||||
|
||||
public virtual void SerializeNetworkState(ref DataStreamWriter writer) {
|
||||
}
|
||||
|
||||
public virtual void DeserializeNetworkState(ref DataStreamReader reader) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootKit.Engine.Services.Simulation {
|
||||
|
||||
Reference in New Issue
Block a user