mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
Send input from Update(), with a specified max rate
This commit is contained in:
parent
787603cdb8
commit
c88920e3f8
2 changed files with 30 additions and 15 deletions
|
@ -9,6 +9,9 @@ namespace SanAndreasUnity.Behaviours
|
|||
{
|
||||
public partial class Ped
|
||||
{
|
||||
[Range(1f / 60f, 0.5f)] [SerializeField] float m_inputSendInterval = 1f / 30f;
|
||||
float m_timeSinceSentInput = 0f;
|
||||
|
||||
[SyncVar(hook=nameof(Net_OnIdChanged))] int m_net_pedId = 0;
|
||||
[SyncVar(hook=nameof(Net_OnStateChanged))] string m_net_state = "";
|
||||
//[SyncVar] Weapon m_net_weapon = null;
|
||||
|
@ -37,24 +40,34 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
void Update_Net()
|
||||
{
|
||||
if (!this.isServer)
|
||||
return;
|
||||
|
||||
if (this.PedDef != null && this.PedDef.Id != m_net_pedId)
|
||||
m_net_pedId = this.PedDef.Id;
|
||||
|
||||
string newStateName = this.CurrentState != null ? this.CurrentState.GetType().Name : "";
|
||||
if (newStateName != m_net_state)
|
||||
m_net_state = newStateName;
|
||||
|
||||
//m_net_weapon = this.CurrentWeapon;
|
||||
// update syncvars
|
||||
if (NetStatus.IsServer)
|
||||
{
|
||||
if (this.PedDef != null && this.PedDef.Id != m_net_pedId)
|
||||
m_net_pedId = this.PedDef.Id;
|
||||
|
||||
string newStateName = this.CurrentState != null ? this.CurrentState.GetType().Name : "";
|
||||
if (newStateName != m_net_state)
|
||||
m_net_state = newStateName;
|
||||
}
|
||||
|
||||
// send input to server
|
||||
if (!NetStatus.IsServer && this.IsControlledByLocalPlayer && PedSync.Local != null)
|
||||
{
|
||||
m_timeSinceSentInput += Time.unscaledDeltaTime;
|
||||
if (m_timeSinceSentInput >= m_inputSendInterval)
|
||||
{
|
||||
m_timeSinceSentInput = 0f;
|
||||
PedSync.Local.SendInput();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate_Net()
|
||||
{
|
||||
// send input to server
|
||||
if (!NetStatus.IsServer && this.IsControlledByLocalPlayer && PedSync.Local != null)
|
||||
PedSync.Local.SendInput();
|
||||
|
||||
}
|
||||
|
||||
void Net_OnIdChanged(int newId)
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
- send input to server
|
||||
|
||||
- don't reset ped input on clients
|
||||
|
||||
- input should be sent from Update(), with a specified max rate (30 fps ?)
|
||||
|
||||
- kill player's ped after he disconnects
|
||||
|
||||
- stats window
|
||||
|
||||
- display a message to user when network is stopped
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue