mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 20:13:02 +00:00
detect when colors are changed on clients
This commit is contained in:
parent
6adfbcd69c
commit
6f98b639c9
1 changed files with 26 additions and 2 deletions
|
@ -14,7 +14,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
bool IsControlledByLocalPlayer => m_vehicle.IsControlledByLocalPlayer;
|
||||
|
||||
[SyncVar] int m_net_id;
|
||||
[SyncVar] string m_net_carColors;
|
||||
[SyncVar(hook = nameof(OnNetColorsChanged))] string m_net_carColors;
|
||||
[SyncVar] float m_net_acceleration;
|
||||
[SyncVar] float m_net_steering;
|
||||
[SyncVar] float m_net_braking;
|
||||
|
@ -56,9 +56,16 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
//m_vehicle = GetComponent<Vehicle>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (m_vehicle != null)
|
||||
m_vehicle.onColorsChanged -= this.OnColorsChanged;
|
||||
}
|
||||
|
||||
internal void OnAfterCreateVehicle()
|
||||
{
|
||||
m_vehicle = this.GetComponent<Vehicle>();
|
||||
m_vehicle = this.GetComponentOrThrow<Vehicle>();
|
||||
m_vehicle.onColorsChanged += this.OnColorsChanged;
|
||||
m_net_id = m_vehicle.Definition.Id;
|
||||
m_net_carColors = SerializeColors(m_vehicle.Colors);
|
||||
}
|
||||
|
@ -138,6 +145,14 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
byte.Parse(splits[3], System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private void OnColorsChanged()
|
||||
{
|
||||
if (!NetStatus.IsServer)
|
||||
return;
|
||||
|
||||
m_net_carColors = SerializeColors(m_vehicle.Colors);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
|
@ -329,5 +344,14 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
}
|
||||
}
|
||||
|
||||
void OnNetColorsChanged(string stringColors)
|
||||
{
|
||||
if (NetStatus.IsServer)
|
||||
return;
|
||||
|
||||
if (m_vehicle != null)
|
||||
F.RunExceptionSafe(() => m_vehicle.SetColors(DeserializeColors(stringColors)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue