-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from Raicuparta/dev
master <- dev (0.5.0)
- Loading branch information
Showing
65 changed files
with
961 additions
and
597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using QSB.Events; | ||
using QSB.Messaging; | ||
|
||
namespace QSB.Animation | ||
{ | ||
public class AnimTriggerEvent : QSBEvent<AnimTriggerMessage> | ||
{ | ||
public override EventType Type => EventType.AnimTrigger; | ||
|
||
public override void SetupListener() | ||
{ | ||
GlobalMessenger<short, float>.AddListener(EventNames.QSBAnimTrigger, Handler); | ||
} | ||
|
||
public override void CloseListener() | ||
{ | ||
GlobalMessenger<short, float>.RemoveListener(EventNames.QSBAnimTrigger, Handler); | ||
} | ||
|
||
private void Handler(short triggerId, float value) => SendEvent(CreateMessage(triggerId, value)); | ||
|
||
private AnimTriggerMessage CreateMessage(short triggerId, float value) => new AnimTriggerMessage | ||
{ | ||
AboutId = LocalPlayerId, | ||
TriggerId = triggerId, | ||
Value = value | ||
}; | ||
|
||
public override void OnReceiveRemote(AnimTriggerMessage message) | ||
{ | ||
var animationSync = PlayerRegistry.GetSyncObject<AnimationSync>(message.AboutId); | ||
if (animationSync == null) | ||
{ | ||
return; | ||
} | ||
animationSync.HandleTrigger((AnimTrigger)message.TriggerId, message.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
|
||
namespace QSB.Animation | ||
{ | ||
public class CrouchSync : NetworkBehaviour | ||
{ | ||
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam(); | ||
|
||
private const float CrouchSendInterval = 0.1f; | ||
private const float CrouchChargeThreshold = 0.01f; | ||
private const float CrouchSmoothTime = 0.05f; | ||
private const int CrouchLayerIndex = 1; | ||
|
||
private float _sendTimer; | ||
private float _lastSentJumpChargeFraction; | ||
|
||
private AnimationSync _animationSync; | ||
private PlayerCharacterController _playerController; | ||
private Animator _bodyAnim; | ||
|
||
public void Init(AnimationSync animationSync, PlayerCharacterController playerController, Animator bodyAnim) | ||
{ | ||
_animationSync = animationSync; | ||
_playerController = playerController; | ||
_bodyAnim = bodyAnim; | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (isLocalPlayer) | ||
{ | ||
SyncLocalCrouch(); | ||
return; | ||
} | ||
SyncRemoteCrouch(); | ||
} | ||
|
||
private void SyncLocalCrouch() | ||
{ | ||
if (_playerController == null) | ||
{ | ||
return; | ||
} | ||
_sendTimer += Time.unscaledDeltaTime; | ||
if (_sendTimer < CrouchSendInterval) | ||
{ | ||
return; | ||
} | ||
var jumpChargeFraction = _playerController.GetJumpChargeFraction(); | ||
if (Math.Abs(jumpChargeFraction - _lastSentJumpChargeFraction) < CrouchChargeThreshold) | ||
{ | ||
return; | ||
} | ||
_animationSync.SendTrigger(AnimTrigger.Crouch, jumpChargeFraction); | ||
_lastSentJumpChargeFraction = jumpChargeFraction; | ||
_sendTimer = 0; | ||
} | ||
|
||
private void SyncRemoteCrouch() | ||
{ | ||
if (_bodyAnim == null) | ||
{ | ||
return; | ||
} | ||
CrouchParam.Smooth(CrouchSmoothTime); | ||
var jumpChargeFraction = CrouchParam.Current; | ||
_bodyAnim.SetLayerWeight(CrouchLayerIndex, jumpChargeFraction); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.