mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
Rafts: begin work
This commit is contained in:
parent
b91041502a
commit
27f67f5365
22
QSB/EchoesOfTheEye/RaftSync/RaftManager.cs
Normal file
22
QSB/EchoesOfTheEye/RaftSync/RaftManager.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.RaftSync;
|
||||
|
||||
public class RaftManager : WorldObjectManager
|
||||
{
|
||||
public override WorldObjectType WorldObjectType => WorldObjectType.SolarSystem;
|
||||
|
||||
public static readonly List<RaftController> Rafts = new();
|
||||
|
||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
||||
{
|
||||
Rafts.Clear();
|
||||
Rafts.AddRange(QSBWorldSync.GetUnityObjects<RaftController>().SortDeterministic());
|
||||
QSBWorldSync.Init<QSBRaft, RaftController>(Rafts);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||
using QSB.Syncs.Unsectored.Rigidbodies;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||
|
||||
public class RaftTransformSync : UnsectoredRigidbodySync
|
||||
{
|
||||
protected override bool UseInterpolation => false;
|
||||
protected override bool OnlyApplyOnDeserialize => true;
|
||||
|
||||
private QSBRaft _qsbRaft;
|
||||
private static readonly List<RaftTransformSync> _instances = new();
|
||||
|
||||
protected override OWRigidbody InitAttachedRigidbody() => _qsbRaft.AttachedObject._raftBody;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
_instances.Add(this);
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
netIdentity.RegisterAuthQueue(true);
|
||||
}
|
||||
|
||||
base.OnStartClient();
|
||||
}
|
||||
|
||||
public override void OnStopClient()
|
||||
{
|
||||
_instances.Remove(this);
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
netIdentity.UnregisterAuthQueue();
|
||||
}
|
||||
|
||||
base.OnStopClient();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
_qsbRaft = RaftManager.Rafts[_instances.IndexOf(this)].GetWorldObject<QSBRaft>();
|
||||
_qsbRaft.TransformSync = this;
|
||||
|
||||
base.Init();
|
||||
SetReferenceTransform(AttachedRigidbody.GetOrigParent());
|
||||
|
||||
AttachedRigidbody.OnUnsuspendOWRigidbody += OnUnsuspend;
|
||||
AttachedRigidbody.OnSuspendOWRigidbody += OnSuspend;
|
||||
netIdentity.UpdateAuthQueue(AttachedRigidbody.IsSuspended() ? AuthQueueAction.Remove : AuthQueueAction.Add);
|
||||
}
|
||||
|
||||
protected override void Uninit()
|
||||
{
|
||||
base.Uninit();
|
||||
|
||||
AttachedRigidbody.OnUnsuspendOWRigidbody -= OnUnsuspend;
|
||||
AttachedRigidbody.OnSuspendOWRigidbody -= OnSuspend;
|
||||
}
|
||||
|
||||
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
||||
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
||||
}
|
39
QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs
Normal file
39
QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Mirror;
|
||||
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||
|
||||
public class QSBRaft : WorldObject<RaftController>
|
||||
{
|
||||
public override bool ShouldDisplayDebug() => false;
|
||||
|
||||
public RaftTransformSync TransformSync;
|
||||
|
||||
public override async UniTask Init(CancellationToken ct)
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
Object.Instantiate(QSBNetworkManager.singleton.RaftPrefab).SpawnWithServerAuthority();
|
||||
}
|
||||
|
||||
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
if (QSBCore.IsHost)
|
||||
{
|
||||
NetworkServer.Destroy(TransformSync.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
// todo SendInitialState
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using QSB.Anglerfish.TransformSync;
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.ClientServerStateSync;
|
||||
using QSB.DeathSync;
|
||||
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||
using QSB.JellyfishSync.TransformSync;
|
||||
using QSB.Messaging;
|
||||
using QSB.OrbSync.Messages;
|
||||
@ -41,6 +42,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
public GameObject AnglerPrefab { get; private set; }
|
||||
public GameObject JellyfishPrefab { get; private set; }
|
||||
public GameObject OccasionalPrefab { get; private set; }
|
||||
public GameObject RaftPrefab { get; private set; }
|
||||
private string PlayerName { get; set; }
|
||||
|
||||
private const int MaxConnections = 128;
|
||||
@ -112,6 +114,9 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
OccasionalPrefab = MakeNewNetworkObject(7, "NetworkOccasional", typeof(OccasionalTransformSync));
|
||||
spawnPrefabs.Add(OccasionalPrefab);
|
||||
|
||||
RaftPrefab = MakeNewNetworkObject(8, "NetworkRaft", typeof(RaftTransformSync));
|
||||
spawnPrefabs.Add(RaftPrefab);
|
||||
|
||||
ConfigureNetworkManager();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user