quantum-space-buddies/QSB/Player/PlayerEntanglementWatcher.cs
2021-11-01 20:20:28 +00:00

41 lines
939 B
C#

using OWML.Utils;
using QSB.Events;
using QSB.QuantumSync;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.Player
{
internal class PlayerEntanglementWatcher : MonoBehaviour
{
private QuantumObject _previousCollidingQuantumObject;
private void Update()
{
if (!QSBCore.IsInMultiplayer)
{
return;
}
var controller = Locator.GetPlayerController();
if (controller == null)
{
return;
}
var collidingQuantumObject = controller.GetValue<QuantumObject>("_collidingQuantumObject");
if (_previousCollidingQuantumObject != collidingQuantumObject)
{
var objectIndex = (collidingQuantumObject != null)
? QSBWorldSync.GetIdFromTypeSubset((IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(collidingQuantumObject))
: -1;
QSBEventManager.FireEvent(
EventNames.QSBPlayerEntangle,
objectIndex);
_previousCollidingQuantumObject = collidingQuantumObject;
}
}
}
}