quantum-space-buddies/QSB/EchoesOfTheEye/EclipseCodeControllers/Messages/InitialStateMessage.cs

50 lines
1.5 KiB
C#
Raw Normal View History

2022-03-12 11:47:44 +00:00
using Mirror;
using QSB.EchoesOfTheEye.EclipseCodeControllers.WorldObjects;
using QSB.Messaging;
using System.Linq;
namespace QSB.EchoesOfTheEye.EclipseCodeControllers.Messages;
2023-07-28 18:30:57 +00:00
public class InitialStateMessage : QSBWorldObjectMessage<QSBEclipseCodeController>
2022-03-12 11:47:44 +00:00
{
private int _selectedDial;
private int[] _dialSelectedSymbols;
public InitialStateMessage(EclipseCodeController4 eclipseCodeController)
2022-03-12 11:47:44 +00:00
{
_selectedDial = eclipseCodeController._selectedDial;
_dialSelectedSymbols = eclipseCodeController._dials.Select(x => x.GetSymbolSelected()).ToArray();
2022-03-12 11:47:44 +00:00
}
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(_selectedDial);
writer.Write(_dialSelectedSymbols);
}
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
_selectedDial = reader.Read<int>();
_dialSelectedSymbols = reader.Read<int[]>();
}
public override void OnReceiveRemote()
{
WorldObject.AttachedObject._selectedDial = _selectedDial;
WorldObject.AttachedObject._currentSelectorPosY = WorldObject.AttachedObject._dials[_selectedDial].transform.localPosition.y;
for (var i = 0; i < WorldObject.AttachedObject._selectors.Length; i++)
{
WorldObject.AttachedObject._selectors[i].SetLocalPositionY(WorldObject.AttachedObject._currentSelectorPosY);
}
for (var i = 0; i < WorldObject.AttachedObject._dials.Length; i++)
{
var dial = WorldObject.AttachedObject._dials[i];
dial._symbolSelected = _dialSelectedSymbols[i];
dial.InstantRotate();
}
}
}