2021-12-23 17:07:29 -08:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 13:49:47 -08:00
|
|
|
|
using QSB.Player.Messages;
|
2021-12-13 22:49:18 -08:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
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-06-18 22:38:32 +01:00
|
|
|
|
|
2021-12-12 10:49:21 +00:00
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 21:27:54 +00:00
|
|
|
|
var controller = Locator.GetPlayerController();
|
|
|
|
|
if (controller == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-12-12 10:49:21 +00:00
|
|
|
|
var collidingQuantumObject = controller._collidingQuantumObject;
|
2021-02-21 21:27:54 +00:00
|
|
|
|
if (_previousCollidingQuantumObject != collidingQuantumObject)
|
|
|
|
|
{
|
2021-12-22 20:45:25 -08:00
|
|
|
|
var objectId = collidingQuantumObject != null
|
2021-12-25 22:37:20 -08:00
|
|
|
|
? collidingQuantumObject.GetWorldObject<IQSBQuantumObject>().ObjectId
|
2021-02-21 21:27:54 +00:00
|
|
|
|
: -1;
|
|
|
|
|
|
2021-12-22 20:45:25 -08:00
|
|
|
|
new PlayerEntangledMessage(objectId).Send();
|
2021-02-21 21:27:54 +00:00
|
|
|
|
_previousCollidingQuantumObject = collidingQuantumObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|