mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-03-05 07:37:17 +00:00
states can detect when current weapon changes
This commit is contained in:
parent
9f5679de5f
commit
ee25411026
4 changed files with 27 additions and 1 deletions
Assets/Scripts/Behaviours/Ped
|
@ -107,6 +107,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
/// <summary>Is this ped controlled by local player ?</summary>
|
||||
public bool IsControlledByLocalPlayer { get { return this == Ped.Instance; } }
|
||||
|
||||
public string DescriptionForLogging => "(netId = " + this.netId + ")";
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public static int NumStateChangesReceived { get; private set; }
|
||||
|
||||
[SyncVar] internal GameObject m_net_weaponGameObject;
|
||||
[SyncVar(hook=nameof(Net_OnWeaponChanged))] internal GameObject m_net_weaponGameObject;
|
||||
|
||||
|
||||
|
||||
|
@ -187,5 +187,22 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
}
|
||||
|
||||
void Net_OnWeaponChanged(GameObject newWeaponGameObject)
|
||||
{
|
||||
|
||||
if (NetStatus.IsServer)
|
||||
return;
|
||||
|
||||
F.RunExceptionSafe( () => {
|
||||
|
||||
Debug.LogFormat("weapon changed for ped {0} to {1}", this.DescriptionForLogging, newWeaponGameObject);
|
||||
|
||||
if (this.CurrentState != null)
|
||||
this.CurrentState.OnChangedWeaponByServer(newWeaponGameObject != null ? newWeaponGameObject.GetComponent<Weapon>() : null);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,6 +272,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
return null;
|
||||
}
|
||||
|
||||
public virtual void OnChangedWeaponByServer(Weapon weapon)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
/// when the state gets activated. </summary>
|
||||
byte[] GetAdditionalNetworkData();
|
||||
|
||||
void OnChangedWeaponByServer(Weapon weapon);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue