quantum-space-buddies/QSB/Player/PlayerEntanglementWatcher.cs

39 lines
912 B
C#
Raw Normal View History

2021-02-21 21:27:54 +00:00
using OWML.Utils;
using QSB.Events;
using QSB.QuantumSync;
2021-02-24 10:45:25 +00:00
using QSB.WorldSync;
2021-02-21 21:27:54 +00:00
using UnityEngine;
namespace QSB.Player
{
internal class PlayerEntanglementWatcher : MonoBehaviour
{
private QuantumObject _previousCollidingQuantumObject;
private void Update()
{
2021-03-09 19:45:00 +00:00
if (!QSBCore.IsInMultiplayer)
{
return;
}
2021-02-21 21:27:54 +00:00
var controller = Locator.GetPlayerController();
if (controller == null)
{
return;
}
var collidingQuantumObject = controller.GetValue<QuantumObject>("_collidingQuantumObject");
if (_previousCollidingQuantumObject != collidingQuantumObject)
{
var objectIndex = (collidingQuantumObject != null)
2021-02-24 10:45:25 +00:00
? QSBWorldSync.GetIdFromTypeSubset(QuantumManager.GetObject(collidingQuantumObject))
2021-02-21 21:27:54 +00:00
: -1;
QSBEventManager.FireEvent(
EventNames.QSBPlayerEntangle,
objectIndex);
_previousCollidingQuantumObject = collidingQuantumObject;
}
}
}
}