sync offset

This commit is contained in:
in0finite 2019-07-13 18:29:14 +02:00
parent eade6fc3d8
commit 75ab5d5d9b
2 changed files with 22 additions and 4 deletions

View file

@ -38,6 +38,12 @@ namespace SanAndreasUnity.Behaviours.Peds.States
}
protected void ReadNetworkData(byte[] data)
{
var reader = new Mirror.NetworkReader(data);
this.ReadNetworkData(reader);
}
protected virtual void ReadNetworkData(Mirror.NetworkReader reader)
{
// first reset params
this.CurrentVehicle = null;
@ -46,8 +52,6 @@ namespace SanAndreasUnity.Behaviours.Peds.States
// extract vehicle and seat from data
var reader = new Mirror.NetworkReader(data);
int magicNumber = reader.ReadInt32();
m_currentVehicleNetId = reader.ReadUInt32();
this.CurrentVehicleSeatAlignment = (Vehicle.SeatAlignment) reader.ReadSByte();
@ -57,7 +61,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
this.CurrentVehicle = vehicleGo != null ? vehicleGo.GetComponent<Vehicle>() : null;
if (magicNumber != 123456789)
Debug.LogErrorFormat("magicNumber {0}, m_currentVehicleNetId {1}, data size {2} - this should not happen", magicNumber, m_currentVehicleNetId, data.Length);
Debug.LogErrorFormat("magicNumber {0}, m_currentVehicleNetId {1}, data size {2} - this should not happen", magicNumber, m_currentVehicleNetId, reader.Length);
}

View file

@ -28,6 +28,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States
base.OnBecameInactive();
}
protected override void GetAdditionalNetworkData(Mirror.NetworkWriter writer)
{
base.GetAdditionalNetworkData(writer);
writer.Write(m_vehicleParentOffset);
}
protected override void ReadNetworkData(Mirror.NetworkReader reader)
{
base.ReadNetworkData(reader);
m_vehicleParentOffset = reader.ReadVector3();
}
protected override void OnVehicleAssigned()
{
this.EnterVehicleInternal();
@ -50,7 +62,9 @@ namespace SanAndreasUnity.Behaviours.Peds.States
{
Vehicle vehicle = this.CurrentVehicle;
Vehicle.Seat seat = this.CurrentVehicleSeat;
m_vehicleParentOffset = m_model.VehicleParentOffset;
if (m_isServer)
m_vehicleParentOffset = m_model.VehicleParentOffset;
BaseVehicleState.PreparePedForVehicle(m_ped, vehicle, seat);