This commit is contained in:
JohnCorby 2022-08-26 16:11:29 -07:00
parent a2d34c22bc
commit 236254f8ea
2 changed files with 29 additions and 19 deletions

View File

@ -5,29 +5,30 @@ using UnityEngine;
namespace QSB.StationaryProbeLauncherSync.VariableSync;
// TODO: use base variable sync instead of doing transform, uses less network bandwidth lol
public class StationaryProbeLauncherVariableSync : RotatingElementsVariableSyncer<QSBStationaryProbeLauncher>
{
protected override Transform[] RotatingElements => new Transform[] { WorldObject.AttachedObject.transform };
protected override Transform[] RotatingElements => new[] { WorldObject.AttachedObject.transform };
protected override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
protected override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
var launcher = WorldObject.AttachedObject as StationaryProbeLauncher;
var launcher = (StationaryProbeLauncher)WorldObject.AttachedObject;
writer.Write(launcher._degreesX);
writer.Write(launcher._degreesY);
writer.Write(launcher._audioSource.GetLocalVolume());
}
writer.Write(launcher._degreesX);
writer.Write(launcher._degreesY);
writer.Write(launcher._audioSource.GetLocalVolume());
}
protected override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
protected override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
var launcher = WorldObject.AttachedObject as StationaryProbeLauncher;
var launcher = (StationaryProbeLauncher)WorldObject.AttachedObject;
launcher._degreesX = reader.Read<float>();
launcher._degreesY = reader.Read<float>();
launcher._audioSource.SetLocalVolume(reader.Read<float>());
launcher._degreesX = reader.Read<float>();
launcher._degreesY = reader.Read<float>();
launcher._audioSource.SetLocalVolume(reader.Read<float>());
}
}

View File

@ -61,7 +61,10 @@ public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<S
{
// Whoever is using it needs authority to be able to rotate it
// If this is a client they'll get authority from the host when the message is received otherwise give now
if (QSBCore.IsHost) NetworkBehaviour.netIdentity.SetAuthority(QSBPlayerManager.LocalPlayerId);
if (QSBCore.IsHost)
{
NetworkBehaviour.netIdentity.SetAuthority(QSBPlayerManager.LocalPlayerId);
}
_isInUse = true;
this.SendMessage(new StationaryProbeLauncherMessage(_isInUse));
@ -77,7 +80,10 @@ public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<S
public void OnRemoteUseStateChanged(bool isInUse, uint from)
{
// Whoever is using it needs authority to be able to rotate it
if (QSBCore.IsHost) NetworkBehaviour.netIdentity.SetAuthority(from);
if (QSBCore.IsHost)
{
NetworkBehaviour.netIdentity.SetAuthority(from);
}
_isInUse = isInUse;
@ -88,7 +94,10 @@ public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<S
{
// Stuff can be null when its sending the initial state info
// BUG: uhhh how? this shouldnt be possible since initial state happens AFTER AllObjectsReady
if (!_isInit) return;
if (!_isInit)
{
return;
}
// If somebody is using this we disable the interaction shape
_stationaryProbeLauncher._interactVolume.SetInteractionEnabled(!_isInUse);