2022-02-25 08:21:21 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using Mirror;
|
2022-02-26 08:02:14 +00:00
|
|
|
|
using QSB.AuthoritySync;
|
|
|
|
|
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
2022-02-25 08:21:21 +00:00
|
|
|
|
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
|
|
|
|
using QSB.WorldSync;
|
2022-02-26 08:02:14 +00:00
|
|
|
|
using System.Linq;
|
2022-02-25 08:21:21 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBRaft : WorldObject<RaftController>
|
2022-02-25 08:21:21 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override bool ShouldDisplayDebug() => false;
|
2022-02-25 08:21:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public RaftTransformSync TransformSync;
|
2022-02-25 08:21:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private QSBLightSensor[] _lightSensors;
|
2022-02-26 08:26:31 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2022-02-25 08:21:21 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
NetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.singleton.RaftPrefab));
|
|
|
|
|
}
|
2022-02-25 08:21:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
|
2022-02-26 08:02:14 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
|
|
|
|
|
_lightSensors = AttachedObject._lightSensors.Select(x => x.GetWorldObject<QSBLightSensor>()).ToArray();
|
2022-02-26 08:26:31 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
foreach (var lightSensor in _lightSensors)
|
|
|
|
|
{
|
|
|
|
|
lightSensor.OnDetectLocalLight += OnDetectLocalLight;
|
2022-02-26 08:02:14 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-02-25 08:21:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnRemoval()
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.IsHost)
|
2022-02-25 08:21:21 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
NetworkServer.Destroy(TransformSync.gameObject);
|
2022-02-25 08:21:21 +00:00
|
|
|
|
}
|
2022-02-26 08:02:14 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
foreach (var lightSensor in _lightSensors)
|
2022-02-26 08:02:14 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
lightSensor.OnDetectLocalLight -= OnDetectLocalLight;
|
2022-02-26 08:02:14 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-02-26 08:02:14 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void OnDetectLocalLight()
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject.IsPlayerRiding())
|
2022-02-26 08:02:14 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
TransformSync.netIdentity.UpdateAuthQueue(AuthQueueAction.Force);
|
2022-02-26 08:02:14 +00:00
|
|
|
|
}
|
2022-02-25 08:21:21 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
|
|
|
|
// todo?? SendInitialState
|
|
|
|
|
}
|
2022-02-26 08:02:14 +00:00
|
|
|
|
}
|