mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
44 lines
938 B
C#
44 lines
938 B
C#
using QSB.Messaging;
|
|
using QSB.Player.Messages;
|
|
using QSB.QuantumSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
using UnityEngine;
|
|
|
|
namespace QSB.Player
|
|
{
|
|
internal class PlayerEntanglementWatcher : MonoBehaviour
|
|
{
|
|
private QuantumObject _previousCollidingQuantumObject;
|
|
|
|
private void Update()
|
|
{
|
|
if (!QSBCore.IsInMultiplayer)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var controller = Locator.GetPlayerController();
|
|
if (controller == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var collidingQuantumObject = controller._collidingQuantumObject;
|
|
if (_previousCollidingQuantumObject != collidingQuantumObject)
|
|
{
|
|
var objectId = collidingQuantumObject != null
|
|
? QSBWorldSync.GetWorldFromUnity<IQSBQuantumObject>(collidingQuantumObject).ObjectId
|
|
: -1;
|
|
|
|
new PlayerEntangledMessage(objectId).Send();
|
|
_previousCollidingQuantumObject = collidingQuantumObject;
|
|
}
|
|
}
|
|
}
|
|
}
|