Apply "Disable vehicle's rigid body on clients" setting immediately

This commit is contained in:
in0finite 2019-05-26 17:04:47 +02:00
parent d91cd759e3
commit aeb0c8fc1e
3 changed files with 24 additions and 6 deletions

View file

@ -210,21 +210,19 @@ namespace SanAndreasUnity.Behaviours.Vehicles
m_vehicle.Braking = brake;
}
void EnableOrDisableRigidBody()
public void EnableOrDisableRigidBody()
{
if (NetStatus.IsServer || this.IsControlledByLocalPlayer)
{
// enable rigid body
m_vehicle.RigidBody.isKinematic = false;
m_vehicle.RigidBody.detectCollisions = true;
F.EnableRigidBody(m_vehicle.RigidBody);
}
else
{
// disable rigid body
if (VehicleManager.Instance.disableRigidBodyOnClients)
{
m_vehicle.RigidBody.isKinematic = true;
m_vehicle.RigidBody.detectCollisions = false;
F.DisableRigidBody(m_vehicle.RigidBody);
}
}
}

View file

@ -90,7 +90,7 @@ namespace SanAndreasUnity.Settings {
OptionsWindow.BoolInput m_disableVehiclesRigidBodyOnClients = new OptionsWindow.BoolInput ("Disable vehicle's rigid body on clients") {
isAvailable = () => VehicleManager.Instance != null,
getValue = () => VehicleManager.Instance.disableRigidBodyOnClients,
setValue = (value) => { VehicleManager.Instance.disableRigidBodyOnClients = value; },
setValue = (value) => { ApplyRigidBodyState(value); },
persistType = OptionsWindow.InputPersistType.OnStart
};
OptionsWindow.BoolInput m_syncPedTransformWhileInVehicle = new OptionsWindow.BoolInput ("Sync ped transform while in vehicle") {
@ -142,6 +142,13 @@ namespace SanAndreasUnity.Settings {
}
}
static void ApplyRigidBodyState(bool bDisabled)
{
VehicleManager.Instance.disableRigidBodyOnClients = bDisabled;
foreach (var v in Vehicle.AllVehicles)
v.GetComponent<VehicleController>().EnableOrDisableRigidBody();
}
}

View file

@ -273,6 +273,19 @@ namespace SanAndreasUnity.Utilities
}
public static void EnableRigidBody(Rigidbody rb)
{
rb.isKinematic = false;
rb.detectCollisions = true;
}
public static void DisableRigidBody(Rigidbody rb)
{
rb.isKinematic = true;
rb.detectCollisions = false;
}
public static object FromHex(this string hexString, Type type, CultureInfo info)
{
var argTypes = new[] { typeof(string), typeof(NumberStyles), typeof(IFormatProvider) };