49 lines
1.1 KiB
C#
Raw Normal View History

2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks;
using Mirror;
2022-01-21 15:13:16 -08:00
using QSB.JellyfishSync.Messages;
using QSB.JellyfishSync.TransformSync;
2022-01-21 15:13:16 -08:00
using QSB.Messaging;
2021-12-01 01:10:38 -08:00
using QSB.WorldSync;
2022-01-28 20:49:07 -08:00
using System.Threading;
2021-12-01 01:10:38 -08:00
using UnityEngine;
2022-03-02 19:46:33 -08:00
namespace QSB.JellyfishSync.WorldObjects;
public class QSBJellyfish : WorldObject<JellyfishController>
2021-12-01 01:10:38 -08:00
{
2022-03-02 19:46:33 -08:00
public override bool ShouldDisplayDebug() => false;
2022-03-02 19:46:33 -08:00
public JellyfishTransformSync TransformSync;
2021-12-01 01:10:38 -08:00
2022-03-02 19:46:33 -08:00
public override async UniTask Init(CancellationToken ct)
{
if (QSBCore.IsHost)
2021-12-01 01:10:38 -08:00
{
2022-03-02 19:46:33 -08:00
NetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.singleton.JellyfishPrefab));
}
2022-03-02 19:46:33 -08:00
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
}
public override void OnRemoval()
{
if (QSBCore.IsHost)
2021-12-01 01:10:38 -08:00
{
2022-03-02 19:46:33 -08:00
NetworkServer.Destroy(TransformSync.gameObject);
2021-12-01 01:10:38 -08:00
}
2022-03-02 19:46:33 -08:00
}
2021-12-01 02:23:12 -08:00
2022-03-02 19:46:33 -08:00
public override void SendInitialState(uint to) =>
this.SendMessage(new JellyfishRisingMessage(AttachedObject._isRising) { To = to });
2022-01-21 15:13:16 -08:00
2022-03-02 19:46:33 -08:00
public void SetIsRising(bool value)
{
if (AttachedObject._isRising == value)
2021-12-01 02:23:12 -08:00
{
2022-03-02 19:46:33 -08:00
return;
}
2022-03-02 19:46:33 -08:00
AttachedObject._isRising = value;
AttachedObject._attractiveFluidVolume.SetVolumeActivation(!value);
2021-12-01 01:10:38 -08:00
}
}