mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 06:35:45 +00:00
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
|
using Cysharp.Threading.Tasks;
|
|||
|
using Mirror;
|
|||
|
using QSB.AuthoritySync;
|
|||
|
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
|||
|
using QSB.Utility.LinkedWorldObject;
|
|||
|
using QSB.WorldSync;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Threading;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace QSB.EchoesOfTheEye;
|
|||
|
|
|||
|
internal abstract class QSBRotatingElements<T, U> : LinkedWorldObject<T, U>
|
|||
|
where T : MonoBehaviour
|
|||
|
where U : NetworkBehaviour
|
|||
|
{
|
|||
|
public override void SendInitialState(uint to) { }
|
|||
|
|
|||
|
protected abstract IEnumerable<SingleLightSensor> LightSensors { get; }
|
|||
|
private QSBLightSensor[] _qsbLightSensors;
|
|||
|
|
|||
|
public override async UniTask Init(CancellationToken ct)
|
|||
|
{
|
|||
|
await base.Init(ct);
|
|||
|
|
|||
|
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
|
|||
|
_qsbLightSensors = LightSensors.Select(x => x.GetWorldObject<QSBLightSensor>()).ToArray();
|
|||
|
|
|||
|
foreach (var lightSensor in _qsbLightSensors)
|
|||
|
{
|
|||
|
lightSensor.OnDetectLocalLight += OnDetectLocalLight;
|
|||
|
lightSensor.OnDetectLocalDarkness += OnDetectLocalDarkness;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void OnRemoval()
|
|||
|
{
|
|||
|
base.OnRemoval();
|
|||
|
|
|||
|
foreach (var lightSensor in _qsbLightSensors)
|
|||
|
{
|
|||
|
lightSensor.OnDetectLocalLight -= OnDetectLocalLight;
|
|||
|
lightSensor.OnDetectLocalDarkness -= OnDetectLocalDarkness;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDetectLocalLight() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
|||
|
private void OnDetectLocalDarkness() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
|||
|
}
|