mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 16:27:19 +00:00
send color of detached part
This commit is contained in:
parent
d5a51d595e
commit
f926bb7c24
2 changed files with 18 additions and 4 deletions
|
@ -49,8 +49,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
{
|
||||
m_vehicle = this.GetComponent<Vehicle>();
|
||||
m_net_id = m_vehicle.Definition.Id;
|
||||
if (m_vehicle.Colors != null)
|
||||
m_net_carColors = string.Join(";", m_vehicle.Colors);
|
||||
m_net_carColors = SerializeColors(m_vehicle.Colors);
|
||||
}
|
||||
|
||||
public override void OnStartClient()
|
||||
|
@ -61,7 +60,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
{
|
||||
F.RunExceptionSafe( () => {
|
||||
// load vehicle on clients
|
||||
int[] colors = string.IsNullOrEmpty(m_net_carColors) ? null : m_net_carColors.Split(';').Select(s => int.Parse(s)).ToArray();
|
||||
int[] colors = DeserializeColors(m_net_carColors);
|
||||
m_vehicle = Vehicle.Create(this.gameObject, m_net_id, colors, this.transform.position, this.transform.rotation);
|
||||
|
||||
// update rigid body status
|
||||
|
@ -82,6 +81,16 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
this.EnableOrDisableRigidBody();
|
||||
}
|
||||
|
||||
public static string SerializeColors(int[] colors)
|
||||
{
|
||||
return colors != null ? string.Join(";", colors) : null;
|
||||
}
|
||||
|
||||
public static int[] DeserializeColors(string colors)
|
||||
{
|
||||
return string.IsNullOrEmpty(colors) ? null : colors.Split(';').Select(s => int.Parse(s)).ToArray();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace SanAndreasUnity.Net
|
|||
|
||||
[SyncVar] uint m_net_vehicleNetId;
|
||||
[SyncVar] int m_net_vehicleModelId;
|
||||
[SyncVar] string m_net_vehicleColors;
|
||||
[SyncVar] string m_net_frameName;
|
||||
[SyncVar] float m_net_mass;
|
||||
|
||||
|
@ -47,6 +48,7 @@ namespace SanAndreasUnity.Net
|
|||
vehicleInfo.numReferences--;
|
||||
if (vehicleInfo.numReferences <= 0)
|
||||
{
|
||||
// TODO: check if it is null
|
||||
Object.Destroy(vehicleInfo.frames.gameObject);
|
||||
s_dummyObjectsPerVehicle.Remove(m_net_vehicleNetId);
|
||||
}
|
||||
|
@ -54,12 +56,13 @@ namespace SanAndreasUnity.Net
|
|||
}
|
||||
}
|
||||
|
||||
public void InitializeOnServer(uint vehicleNetId, int vehicleModelId, string frameName, float mass, Rigidbody rigidbody)
|
||||
public void InitializeOnServer(uint vehicleNetId, int vehicleModelId, int[] vehicleColors, string frameName, float mass, Rigidbody rigidbody)
|
||||
{
|
||||
NetStatus.ThrowIfNotOnServer();
|
||||
|
||||
m_net_vehicleNetId = vehicleNetId;
|
||||
m_net_vehicleModelId = vehicleModelId;
|
||||
m_net_vehicleColors = VehicleController.SerializeColors(vehicleColors);
|
||||
m_net_frameName = frameName;
|
||||
m_net_mass = mass;
|
||||
|
||||
|
@ -87,6 +90,8 @@ namespace SanAndreasUnity.Net
|
|||
|
||||
VehicleDef def = Item.GetDefinitionOrThrow<VehicleDef>(m_net_vehicleModelId);
|
||||
|
||||
int[] colors = VehicleController.DeserializeColors(m_net_vehicleColors);
|
||||
|
||||
var geometryParts = Vehicle.LoadGeometryParts(def);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue