2021-12-24 01:07:29 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 21:49:47 +00:00
|
|
|
|
using QSB.Player.Messages;
|
2021-12-14 06:49:18 +00:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
2022-02-01 22:24:21 +00:00
|
|
|
|
using QSB.Utility;
|
2021-02-24 10:45:25 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-02-21 21:27:54 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Player;
|
|
|
|
|
|
2023-07-28 18:30:57 +00:00
|
|
|
|
public class PlayerEntanglementWatcher : MonoBehaviour, IAddComponentOnStart
|
2021-02-21 21:27:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private QuantumObject _previousCollidingQuantumObject;
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!QSBCore.IsInMultiplayer)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-12-12 10:49:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (!QSBWorldSync.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var controller = Locator.GetPlayerController();
|
|
|
|
|
if (controller == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var collidingQuantumObject = controller._collidingQuantumObject;
|
|
|
|
|
if (_previousCollidingQuantumObject != collidingQuantumObject)
|
|
|
|
|
{
|
|
|
|
|
var objectId = collidingQuantumObject != null
|
|
|
|
|
? collidingQuantumObject.GetWorldObject<IQSBQuantumObject>().ObjectId
|
|
|
|
|
: -1;
|
2021-02-21 21:27:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
new PlayerEntangledMessage(objectId).Send();
|
|
|
|
|
_previousCollidingQuantumObject = collidingQuantumObject;
|
2021-02-21 21:27:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|