quantum-space-buddies/QSB/JellyfishSync/WorldObjects/QSBJellyfish.cs
2022-01-28 20:49:07 -08:00

57 lines
1.2 KiB
C#

using Cysharp.Threading.Tasks;
using Mirror;
using QSB.JellyfishSync.Messages;
using QSB.JellyfishSync.TransformSync;
using QSB.Messaging;
using QSB.WorldSync;
using System.Threading;
using UnityEngine;
namespace QSB.JellyfishSync.WorldObjects
{
public class QSBJellyfish : WorldObject<JellyfishController>
{
public override bool ShouldDisplayDebug() => false;
public JellyfishTransformSync TransformSync;
public override async UniTask Init(CancellationToken cancellationToken)
{
if (QSBCore.IsHost)
{
NetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.singleton.JellyfishPrefab));
}
StartDelayedReady();
QSBCore.UnityEvents.RunWhen(() => TransformSync, FinishDelayedReady);
}
public override void OnRemoval()
{
if (QSBCore.IsHost)
{
NetworkServer.Destroy(TransformSync.gameObject);
}
}
public override void SendInitialState(uint to)
{
if (TransformSync.hasAuthority)
{
this.SendMessage(new JellyfishRisingMessage(AttachedObject._isRising) { To = to });
}
}
public void SetIsRising(bool value)
{
if (AttachedObject._isRising == value)
{
return;
}
AttachedObject._isRising = value;
AttachedObject._attractiveFluidVolume.SetVolumeActivation(!value);
}
}
}