2
0
Fork 0
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:
in0finite 2019-07-06 22:38:46 +02:00
parent 9f5679de5f
commit ee25411026
4 changed files with 27 additions and 1 deletions

View file

@ -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 + ")";

View file

@ -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);
});
}
}
}

View file

@ -272,6 +272,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States
return null;
}
public virtual void OnChangedWeaponByServer(Weapon weapon)
{
}
}
}

View file

@ -27,6 +27,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
/// when the state gets activated. </summary>
byte[] GetAdditionalNetworkData();
void OnChangedWeaponByServer(Weapon weapon);
}
}