remove need for CrouchSync

This commit is contained in:
Mister_Nebula 2022-08-14 12:05:55 +01:00
parent 6c690da7e9
commit 84f2a6f999
4 changed files with 11 additions and 73 deletions

View File

@ -17,8 +17,6 @@ public class AnimationSync : PlayerSyncObject
private AnimatorOverrideController _unsuitedAnimController;
private GameObject _suitedGraphics;
private GameObject _unsuitedGraphics;
private PlayerCharacterController _playerController;
private CrouchSync _crouchSync;
public AnimatorMirror Mirror { get; private set; }
public bool InSuitedUpState { get; set; }
@ -74,10 +72,6 @@ public class AnimationSync : PlayerSyncObject
public void InitLocal(Transform body)
{
InitCommon(body);
_playerController = body.parent.GetComponent<PlayerCharacterController>();
InitCrouchSync();
InitAccelerationSync();
}
@ -85,7 +79,6 @@ public class AnimationSync : PlayerSyncObject
{
InitCommon(body);
SetSuitState(QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse);
InitCrouchSync();
InitAccelerationSync();
ThrusterManager.CreateRemotePlayerVFX(Player);
@ -100,12 +93,6 @@ public class AnimationSync : PlayerSyncObject
Player.JetpackAcceleration.Init(thrusterModel);
}
private void InitCrouchSync()
{
_crouchSync = this.GetRequiredComponent<CrouchSync>();
_crouchSync.Init(_playerController, VisibleAnimator);
}
public void SetSuitState(bool suitedUp)
{
if (!Player.IsReady)

View File

@ -61,6 +61,7 @@ public class AnimatorMirror : MonoBehaviour
}
SyncParams();
SyncLayerWeights();
SmoothFloats();
}
@ -96,6 +97,15 @@ public class AnimatorMirror : MonoBehaviour
}
}
private void SyncLayerWeights()
{
for (var i = 0; i < _from.layerCount; i++)
{
var weight = _from.GetLayerWeight(i);
_to.SetLayerWeight(i, weight);
}
}
private void SmoothFloats()
{
foreach (var floatParam in _floatParams)

View File

@ -1,59 +0,0 @@
using Mirror;
using QSB.Utility.VariableSync;
using UnityEngine;
namespace QSB.Animation.Player;
public class CrouchSync : NetworkBehaviour
{
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam();
private const float CrouchSmoothTime = 0.05f;
public const int CrouchLayerIndex = 1;
private PlayerCharacterController _playerController;
private Animator _bodyAnim;
public FloatVariableSyncer CrouchVariableSyncer;
public void Init(PlayerCharacterController playerController, Animator bodyAnim)
{
_playerController = playerController;
_bodyAnim = bodyAnim;
}
public void Update()
{
if (isLocalPlayer)
{
SyncLocalCrouch();
return;
}
SyncRemoteCrouch();
}
private void SyncLocalCrouch()
{
if (_playerController == null)
{
return;
}
var jumpChargeFraction = _playerController.GetJumpCrouchFraction();
CrouchVariableSyncer.Value = jumpChargeFraction;
}
private void SyncRemoteCrouch()
{
if (_bodyAnim == null)
{
return;
}
CrouchParam.Target = CrouchVariableSyncer.Value;
CrouchParam.Smooth(CrouchSmoothTime);
var jumpChargeFraction = CrouchParam.Current;
_bodyAnim.SetLayerWeight(CrouchLayerIndex, jumpChargeFraction);
}
}

View File

@ -54,7 +54,7 @@ internal class PlayerAnimationPatches : QSBPatch
__instance._animator.SetFloat("RunSpeedY", movementVector.z / 3f);
__instance._animator.SetFloat("TurnSpeed", __instance._playerController.GetTurning());
__instance._animator.SetBool("Grounded", isGrounded || isAttached || PlayerState.IsRecentlyDetached());
__instance._animator.SetLayerWeight(CrouchSync.CrouchLayerIndex, __instance._playerController.GetJumpCrouchFraction());
__instance._animator.SetLayerWeight(1, __instance._playerController.GetJumpCrouchFraction());
__instance._animator.SetFloat("FreefallSpeed", freefallMagnitude / 15f * (timeInFreefall / 3f));
__instance._animator.SetBool("InZeroG", isInZeroG || isFlying);
__instance._animator.SetBool("UsingJetpack", isInZeroG && PlayerState.IsWearingSuit());