mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-23 12:33:02 +00:00
client detects when roll direction changes, and plays anim again
This commit is contained in:
parent
2e7289d1b4
commit
95120b46d3
2 changed files with 61 additions and 6 deletions
|
@ -32,6 +32,10 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public static int NumStateChangesReceived { get; private set; }
|
||||
|
||||
public class SyncDictionaryStringUint : Mirror.SyncDictionary<string, uint> { }
|
||||
|
||||
public SyncDictionaryStringUint syncDictionaryStringUint = new SyncDictionaryStringUint();
|
||||
|
||||
[SyncVar] Vector3 m_net_movementInput;
|
||||
[SyncVar] Vector3 m_net_heading;
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
private bool m_rollLeft = false;
|
||||
private AnimationState m_animState;
|
||||
|
||||
const string kRollDirSyncName = "rollDir";
|
||||
|
||||
|
||||
|
||||
public bool CanRoll()
|
||||
|
@ -33,15 +35,24 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
return true;
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// subscribe to dictionary event
|
||||
if (m_isClientOnly)
|
||||
m_ped.syncDictionaryStringUint.Callback += this.OnDictChanged;
|
||||
|
||||
}
|
||||
|
||||
public override void OnBecameActive ()
|
||||
{
|
||||
base.OnBecameActive();
|
||||
m_animState = m_model.PlayAnim( this.movementAnim );
|
||||
// clients have wrap mode set to 'Loop', because state can be switched very fast between roll and crouchaim, and
|
||||
// server will not update current state syncvar, so client will not start the state again,
|
||||
// and roll state will remain
|
||||
m_animState.wrapMode = m_isServer ? WrapMode.Once : WrapMode.Loop;
|
||||
m_model.VelocityAxis = 0; // movement will be done along x axis
|
||||
|
||||
this.PlayAnim();
|
||||
|
||||
if (m_isServer)
|
||||
m_ped.syncDictionaryStringUint[kRollDirSyncName] = m_rollLeft ? (uint) 1 : (uint) 0;
|
||||
}
|
||||
|
||||
public override byte[] GetAdditionalNetworkData()
|
||||
|
@ -63,6 +74,35 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
m_ped.SwitchState(this.GetType());
|
||||
}
|
||||
|
||||
void OnDictChanged(Ped.SyncDictionaryStringUint.Operation op, string key, uint value)
|
||||
{
|
||||
// switch (op)
|
||||
// {
|
||||
// case Ped.SyncDictionaryStringUint.Operation.OP_ADD:
|
||||
// case Ped.SyncDictionaryStringUint.Operation.OP_DIRTY:
|
||||
// case Ped.SyncDictionaryStringUint.Operation.OP_SET:
|
||||
// break;
|
||||
// }
|
||||
|
||||
Debug.LogFormat("OnDictChanged() - op: {0}, key: {1}, value: {2}", op, key, value);
|
||||
|
||||
if (key != kRollDirSyncName)
|
||||
return;
|
||||
|
||||
F.RunExceptionSafe( () => {
|
||||
if (m_ped.syncDictionaryStringUint.ContainsKey(key))
|
||||
{
|
||||
// roll direction possibly changed
|
||||
bool oldLeft = m_rollLeft;
|
||||
m_rollLeft = m_ped.syncDictionaryStringUint[key] == 1;
|
||||
Debug.LogFormat("roll dir changed - old left: {0}, new left: {1}", oldLeft, m_rollLeft);
|
||||
if (oldLeft != m_rollLeft)
|
||||
this.PlayAnim();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override void SwitchToMovementState ()
|
||||
{
|
||||
|
@ -104,6 +144,17 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
m_ped.Movement = originalMovementInput;
|
||||
}
|
||||
|
||||
void PlayAnim()
|
||||
{
|
||||
m_animState = m_model.PlayAnim( this.movementAnim );
|
||||
// clients have wrap mode set to 'Loop', because state can be switched very fast between roll and crouchaim, and
|
||||
// server will not update current state syncvar, so client will not start the state again,
|
||||
// and roll state will remain
|
||||
m_animState.wrapMode = m_isServer ? WrapMode.Once : WrapMode.Loop;
|
||||
m_model.VelocityAxis = 0; // movement will be done along x axis
|
||||
|
||||
}
|
||||
|
||||
protected override void UpdateAnims ()
|
||||
{
|
||||
// correct local x position of root frame
|
||||
|
|
Loading…
Reference in a new issue