mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-26 15:39:54 +00:00
yes
This commit is contained in:
parent
beccede131
commit
8772a670a5
@ -3,24 +3,24 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public static class AnimControllerPatch
|
||||
{
|
||||
public static RuntimeAnimatorController SuitedAnimController { get; private set; }
|
||||
public static class AnimControllerPatch
|
||||
{
|
||||
public static RuntimeAnimatorController SuitedAnimController { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
QSB.Helper.Events.Subscribe<PlayerAnimController>(OWML.Common.Events.BeforeStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
QSB.Helper.Events.Subscribe<PlayerAnimController>(OWML.Common.Events.BeforeStart);
|
||||
QSB.Helper.Events.Event += OnEvent;
|
||||
}
|
||||
|
||||
private static void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerAnimController playerAnimController &&
|
||||
ev == OWML.Common.Events.BeforeStart &&
|
||||
SuitedAnimController == null)
|
||||
{
|
||||
SuitedAnimController = playerAnimController.GetValue<RuntimeAnimatorController>("_baseAnimController");
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void OnEvent(MonoBehaviour behaviour, OWML.Common.Events ev)
|
||||
{
|
||||
if (behaviour is PlayerAnimController playerAnimController &&
|
||||
ev == OWML.Common.Events.BeforeStart &&
|
||||
SuitedAnimController == null)
|
||||
{
|
||||
SuitedAnimController = playerAnimController.GetValue<RuntimeAnimatorController>("_baseAnimController");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,17 +2,17 @@
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimFloatParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
||||
public class AnimFloatParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
||||
|
||||
private float _velocity;
|
||||
private float _velocity;
|
||||
|
||||
public float Smooth(float smoothTime)
|
||||
{
|
||||
Current = Mathf.SmoothDamp(Current, Target, ref _velocity, smoothTime);
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
public float Smooth(float smoothTime)
|
||||
{
|
||||
Current = Mathf.SmoothDamp(Current, Target, ref _velocity, smoothTime);
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
}
|
@ -8,237 +8,229 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimationSync : PlayerSyncObject
|
||||
{
|
||||
private Animator _anim;
|
||||
private Animator _bodyAnim;
|
||||
private QSBNetworkAnimator _netAnim;
|
||||
public class AnimationSync : PlayerSyncObject
|
||||
{
|
||||
private Animator _anim;
|
||||
private QSBNetworkAnimator _netAnim;
|
||||
|
||||
private RuntimeAnimatorController _suitedAnimController;
|
||||
private AnimatorOverrideController _unsuitedAnimController;
|
||||
private GameObject _suitedGraphics;
|
||||
private GameObject _unsuitedGraphics;
|
||||
private PlayerCharacterController _playerController;
|
||||
private CrouchSync _crouchSync;
|
||||
private RuntimeAnimatorController _suitedAnimController;
|
||||
private AnimatorOverrideController _unsuitedAnimController;
|
||||
private GameObject _suitedGraphics;
|
||||
private GameObject _unsuitedGraphics;
|
||||
private PlayerCharacterController _playerController;
|
||||
private CrouchSync _crouchSync;
|
||||
|
||||
private RuntimeAnimatorController _chertController;
|
||||
private RuntimeAnimatorController _eskerController;
|
||||
private RuntimeAnimatorController _feldsparController;
|
||||
private RuntimeAnimatorController _gabbroController;
|
||||
private RuntimeAnimatorController _riebeckController;
|
||||
private RuntimeAnimatorController _chertController;
|
||||
private RuntimeAnimatorController _eskerController;
|
||||
private RuntimeAnimatorController _feldsparController;
|
||||
private RuntimeAnimatorController _gabbroController;
|
||||
private RuntimeAnimatorController _riebeckController;
|
||||
|
||||
public AnimatorMirror Mirror { get; private set; }
|
||||
public AnimationType CurrentType = AnimationType.PlayerUnsuited;
|
||||
public Animator Animator
|
||||
{
|
||||
get { return _bodyAnim; }
|
||||
}
|
||||
public AnimatorMirror Mirror { get; private set; }
|
||||
public AnimationType CurrentType = AnimationType.PlayerUnsuited;
|
||||
public Animator Animator { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_anim = gameObject.AddComponent<Animator>();
|
||||
_netAnim = gameObject.AddComponent<QSBNetworkAnimator>();
|
||||
_netAnim.enabled = false;
|
||||
_netAnim.animator = _anim;
|
||||
private void Awake()
|
||||
{
|
||||
_anim = gameObject.AddComponent<Animator>();
|
||||
_netAnim = gameObject.AddComponent<QSBNetworkAnimator>();
|
||||
_netAnim.enabled = false;
|
||||
_netAnim.animator = _anim;
|
||||
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => LoadControllers();
|
||||
}
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => LoadControllers();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_netAnim.enabled = false;
|
||||
if (_playerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_playerController.OnJump -= OnJump;
|
||||
_playerController.OnBecomeGrounded -= OnBecomeGrounded;
|
||||
_playerController.OnBecomeUngrounded -= OnBecomeUngrounded;
|
||||
private void OnDestroy()
|
||||
{
|
||||
_netAnim.enabled = false;
|
||||
if (_playerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_playerController.OnJump -= OnJump;
|
||||
_playerController.OnBecomeGrounded -= OnBecomeGrounded;
|
||||
_playerController.OnBecomeUngrounded -= OnBecomeUngrounded;
|
||||
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => LoadControllers();
|
||||
}
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => LoadControllers();
|
||||
}
|
||||
|
||||
private void LoadControllers()
|
||||
{
|
||||
var bundle = QSB.InstrumentAssetBundle;
|
||||
_chertController = bundle.LoadAsset("assets/Chert/Traveller_Chert.controller") as RuntimeAnimatorController;
|
||||
_riebeckController = bundle.LoadAsset("assets/Riebeck/Traveller_Riebeck.controller") as RuntimeAnimatorController;
|
||||
}
|
||||
private void LoadControllers()
|
||||
{
|
||||
var bundle = QSB.InstrumentAssetBundle;
|
||||
_chertController = bundle.LoadAsset("assets/Chert/Traveller_Chert.controller") as RuntimeAnimatorController;
|
||||
_riebeckController = bundle.LoadAsset("assets/Riebeck/Traveller_Riebeck.controller") as RuntimeAnimatorController;
|
||||
}
|
||||
|
||||
private void InitCommon(Transform body)
|
||||
{
|
||||
if (QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
LoadControllers();
|
||||
}
|
||||
_netAnim.enabled = true;
|
||||
Animator = body.GetComponent<Animator>();
|
||||
Mirror = body.gameObject.AddComponent<AnimatorMirror>();
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
Mirror.Init(Animator, _anim);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mirror.Init(_anim, Animator);
|
||||
}
|
||||
|
||||
private void InitCommon(Transform body)
|
||||
{
|
||||
if (QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
LoadControllers();
|
||||
}
|
||||
_netAnim.enabled = true;
|
||||
_bodyAnim = body.GetComponent<Animator>();
|
||||
Mirror = body.gameObject.AddComponent<AnimatorMirror>();
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
Mirror.Init(_bodyAnim, _anim);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mirror.Init(_anim, _bodyAnim);
|
||||
}
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
|
||||
QSBPlayerManager.PlayerSyncObjects.Add(this);
|
||||
for (var i = 0; i < _anim.parameterCount; i++)
|
||||
{
|
||||
_netAnim.SetParameterAutoSend(i, true);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _anim.parameterCount; i++)
|
||||
{
|
||||
_netAnim.SetParameterAutoSend(i, true);
|
||||
}
|
||||
var playerAnimController = body.GetComponent<PlayerAnimController>();
|
||||
_suitedAnimController = AnimControllerPatch.SuitedAnimController;
|
||||
_unsuitedAnimController = playerAnimController.GetValue<AnimatorOverrideController>("_unsuitedAnimOverride");
|
||||
_suitedGraphics = playerAnimController.GetValue<GameObject>("_suitedGroup");
|
||||
_unsuitedGraphics = playerAnimController.GetValue<GameObject>("_unsuitedGroup");
|
||||
}
|
||||
|
||||
var playerAnimController = body.GetComponent<PlayerAnimController>();
|
||||
_suitedAnimController = AnimControllerPatch.SuitedAnimController;
|
||||
_unsuitedAnimController = playerAnimController.GetValue<AnimatorOverrideController>("_unsuitedAnimOverride");
|
||||
_suitedGraphics = playerAnimController.GetValue<GameObject>("_suitedGroup");
|
||||
_unsuitedGraphics = playerAnimController.GetValue<GameObject>("_unsuitedGroup");
|
||||
}
|
||||
public void InitLocal(Transform body)
|
||||
{
|
||||
InitCommon(body);
|
||||
|
||||
public void InitLocal(Transform body)
|
||||
{
|
||||
InitCommon(body);
|
||||
_playerController = body.parent.GetComponent<PlayerCharacterController>();
|
||||
_playerController.OnJump += OnJump;
|
||||
_playerController.OnBecomeGrounded += OnBecomeGrounded;
|
||||
_playerController.OnBecomeUngrounded += OnBecomeUngrounded;
|
||||
|
||||
_playerController = body.parent.GetComponent<PlayerCharacterController>();
|
||||
_playerController.OnJump += OnJump;
|
||||
_playerController.OnBecomeGrounded += OnBecomeGrounded;
|
||||
_playerController.OnBecomeUngrounded += OnBecomeUngrounded;
|
||||
InitCrouchSync();
|
||||
}
|
||||
|
||||
InitCrouchSync();
|
||||
}
|
||||
public void InitRemote(Transform body)
|
||||
{
|
||||
InitCommon(body);
|
||||
|
||||
public void InitRemote(Transform body)
|
||||
{
|
||||
InitCommon(body);
|
||||
var playerAnimController = body.GetComponent<PlayerAnimController>();
|
||||
playerAnimController.enabled = false;
|
||||
|
||||
var playerAnimController = body.GetComponent<PlayerAnimController>();
|
||||
playerAnimController.enabled = false;
|
||||
playerAnimController.SetValue("_suitedGroup", new GameObject());
|
||||
playerAnimController.SetValue("_unsuitedGroup", new GameObject());
|
||||
playerAnimController.SetValue("_baseAnimController", null);
|
||||
playerAnimController.SetValue("_unsuitedAnimOverride", null);
|
||||
playerAnimController.SetValue("_rightArmHidden", false);
|
||||
|
||||
playerAnimController.SetValue("_suitedGroup", new GameObject());
|
||||
playerAnimController.SetValue("_unsuitedGroup", new GameObject());
|
||||
playerAnimController.SetValue("_baseAnimController", null);
|
||||
playerAnimController.SetValue("_unsuitedAnimOverride", null);
|
||||
playerAnimController.SetValue("_rightArmHidden", false);
|
||||
var rightArmObjects = playerAnimController.GetValue<GameObject[]>("_rightArmObjects").ToList();
|
||||
rightArmObjects.ForEach(rightArmObject => rightArmObject.layer = LayerMask.NameToLayer("Default"));
|
||||
|
||||
var rightArmObjects = playerAnimController.GetValue<GameObject[]>("_rightArmObjects").ToList();
|
||||
rightArmObjects.ForEach(rightArmObject => rightArmObject.layer = LayerMask.NameToLayer("Default"));
|
||||
body.Find("player_mesh_noSuit:Traveller_HEA_Player/player_mesh_noSuit:Player_Head").gameObject.layer = 0;
|
||||
body.Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0;
|
||||
|
||||
body.Find("player_mesh_noSuit:Traveller_HEA_Player/player_mesh_noSuit:Player_Head").gameObject.layer = 0;
|
||||
body.Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0;
|
||||
InitCrouchSync();
|
||||
|
||||
InitCrouchSync();
|
||||
var ikSync = body.gameObject.AddComponent<PlayerHeadRotationSync>();
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Player.Camera != null, () => ikSync.Init(Player.Camera.transform));
|
||||
}
|
||||
|
||||
var ikSync = body.gameObject.AddComponent<PlayerHeadRotationSync>();
|
||||
QSB.Helper.Events.Unity.RunWhen(() => Player.Camera != null, () => ikSync.Init(Player.Camera.transform));
|
||||
}
|
||||
private void InitCrouchSync()
|
||||
{
|
||||
_crouchSync = gameObject.AddComponent<CrouchSync>();
|
||||
_crouchSync.Init(this, _playerController, Animator);
|
||||
}
|
||||
|
||||
private void InitCrouchSync()
|
||||
{
|
||||
_crouchSync = gameObject.AddComponent<CrouchSync>();
|
||||
_crouchSync.Init(this, _playerController, _bodyAnim);
|
||||
}
|
||||
private void OnJump() => _netAnim.SetTrigger("Jump");
|
||||
private void OnBecomeGrounded() => _netAnim.SetTrigger("Grounded");
|
||||
private void OnBecomeUngrounded() => _netAnim.SetTrigger("Ungrounded");
|
||||
|
||||
private void OnJump() => _netAnim.SetTrigger("Jump");
|
||||
private void OnBecomeGrounded() => _netAnim.SetTrigger("Grounded");
|
||||
private void OnBecomeUngrounded() => _netAnim.SetTrigger("Ungrounded");
|
||||
public void SendCrouch(float value = 0)
|
||||
=> GlobalMessenger<float>.FireEvent(EventNames.QSBCrouch, value);
|
||||
|
||||
public void SendCrouch(float value = 0)
|
||||
{
|
||||
GlobalMessenger<float>.FireEvent(EventNames.QSBCrouch, value);
|
||||
}
|
||||
public void HandleCrouch(float value)
|
||||
=> _crouchSync.CrouchParam.Target = value;
|
||||
|
||||
public void HandleCrouch(float value)
|
||||
{
|
||||
_crouchSync.CrouchParam.Target = value;
|
||||
}
|
||||
private void SuitUp()
|
||||
{
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerSuited);
|
||||
SetAnimationType(AnimationType.PlayerSuited);
|
||||
}
|
||||
|
||||
private void SuitUp()
|
||||
{
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerSuited);
|
||||
SetAnimationType(AnimationType.PlayerSuited);
|
||||
}
|
||||
private void SuitDown()
|
||||
{
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerUnsuited);
|
||||
SetAnimationType(AnimationType.PlayerUnsuited);
|
||||
}
|
||||
|
||||
private void SuitDown()
|
||||
{
|
||||
GlobalMessenger<uint, AnimationType>.FireEvent(EventNames.QSBChangeAnimType, PlayerId, AnimationType.PlayerUnsuited);
|
||||
SetAnimationType(AnimationType.PlayerUnsuited);
|
||||
}
|
||||
public void SetSuitState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
SuitUp();
|
||||
return;
|
||||
}
|
||||
SuitDown();
|
||||
}
|
||||
|
||||
public void SetSuitState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
SuitUp();
|
||||
return;
|
||||
}
|
||||
SuitDown();
|
||||
}
|
||||
|
||||
public void SetAnimationType(AnimationType type)
|
||||
{
|
||||
if (CurrentType == type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CurrentType = type;
|
||||
if (_unsuitedAnimController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - Unsuited controller is null. ({PlayerId})", MessageType.Error);
|
||||
}
|
||||
if (_suitedAnimController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - Suited controller is null. ({PlayerId})", MessageType.Error);
|
||||
}
|
||||
RuntimeAnimatorController controller = default;
|
||||
switch (type)
|
||||
{
|
||||
case AnimationType.PlayerSuited:
|
||||
controller = _suitedAnimController;
|
||||
_unsuitedGraphics?.SetActive(false);
|
||||
_suitedGraphics?.SetActive(true);
|
||||
break;
|
||||
case AnimationType.PlayerUnsuited:
|
||||
controller = _unsuitedAnimController;
|
||||
_unsuitedGraphics?.SetActive(true);
|
||||
_suitedGraphics?.SetActive(false);
|
||||
break;
|
||||
case AnimationType.Chert:
|
||||
controller = _chertController;
|
||||
break;
|
||||
case AnimationType.Esker:
|
||||
controller = _eskerController;
|
||||
break;
|
||||
case AnimationType.Feldspar:
|
||||
controller = _feldsparController;
|
||||
break;
|
||||
case AnimationType.Gabbro:
|
||||
controller = _gabbroController;
|
||||
break;
|
||||
case AnimationType.Riebeck:
|
||||
controller = _riebeckController;
|
||||
break;
|
||||
}
|
||||
_anim.runtimeAnimatorController = controller;
|
||||
_bodyAnim.runtimeAnimatorController = controller;
|
||||
if (type != AnimationType.PlayerSuited && type != AnimationType.PlayerUnsuited)
|
||||
{
|
||||
_bodyAnim.SetTrigger("Playing");
|
||||
_anim.SetTrigger("Playing");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Avoids "jumping" when exiting instrument and putting on suit
|
||||
_bodyAnim.SetTrigger("Grounded");
|
||||
_anim.SetTrigger("Grounded");
|
||||
}
|
||||
_netAnim.animator = _anim; // Probably not needed.
|
||||
Mirror.RebuildFloatParams();
|
||||
for (var i = 0; i < _anim.parameterCount; i++)
|
||||
{
|
||||
_netAnim.SetParameterAutoSend(i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetAnimationType(AnimationType type)
|
||||
{
|
||||
if (CurrentType == type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CurrentType = type;
|
||||
if (_unsuitedAnimController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - Unsuited controller is null. ({PlayerId})", MessageType.Error);
|
||||
}
|
||||
if (_suitedAnimController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Error - Suited controller is null. ({PlayerId})", MessageType.Error);
|
||||
}
|
||||
RuntimeAnimatorController controller = default;
|
||||
switch (type)
|
||||
{
|
||||
case AnimationType.PlayerSuited:
|
||||
controller = _suitedAnimController;
|
||||
_unsuitedGraphics?.SetActive(false);
|
||||
_suitedGraphics?.SetActive(true);
|
||||
break;
|
||||
case AnimationType.PlayerUnsuited:
|
||||
controller = _unsuitedAnimController;
|
||||
_unsuitedGraphics?.SetActive(true);
|
||||
_suitedGraphics?.SetActive(false);
|
||||
break;
|
||||
case AnimationType.Chert:
|
||||
controller = _chertController;
|
||||
break;
|
||||
case AnimationType.Esker:
|
||||
controller = _eskerController;
|
||||
break;
|
||||
case AnimationType.Feldspar:
|
||||
controller = _feldsparController;
|
||||
break;
|
||||
case AnimationType.Gabbro:
|
||||
controller = _gabbroController;
|
||||
break;
|
||||
case AnimationType.Riebeck:
|
||||
controller = _riebeckController;
|
||||
break;
|
||||
}
|
||||
_anim.runtimeAnimatorController = controller;
|
||||
Animator.runtimeAnimatorController = controller;
|
||||
if (type != AnimationType.PlayerSuited && type != AnimationType.PlayerUnsuited)
|
||||
{
|
||||
Animator.SetTrigger("Playing");
|
||||
_anim.SetTrigger("Playing");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Avoids "jumping" when exiting instrument and putting on suit
|
||||
Animator.SetTrigger("Grounded");
|
||||
_anim.SetTrigger("Grounded");
|
||||
}
|
||||
_netAnim.animator = _anim; // Probably not needed.
|
||||
Mirror.RebuildFloatParams();
|
||||
for (var i = 0; i < _anim.parameterCount; i++)
|
||||
{
|
||||
_netAnim.SetParameterAutoSend(i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public enum AnimationType
|
||||
{
|
||||
Chert,
|
||||
Esker,
|
||||
Feldspar,
|
||||
Gabbro,
|
||||
PlayerSuited,
|
||||
PlayerUnsuited,
|
||||
Riebeck
|
||||
}
|
||||
public enum AnimationType
|
||||
{
|
||||
Chert,
|
||||
Esker,
|
||||
Feldspar,
|
||||
Gabbro,
|
||||
PlayerSuited,
|
||||
PlayerUnsuited,
|
||||
Riebeck
|
||||
}
|
||||
}
|
@ -7,92 +7,90 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
private const float SmoothTime = 0.05f;
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
private const float SmoothTime = 0.05f;
|
||||
|
||||
private Animator _from;
|
||||
private Animator _to;
|
||||
private Animator _from;
|
||||
private Animator _to;
|
||||
|
||||
private readonly Dictionary<string, AnimFloatParam> _floatParams = new Dictionary<string, AnimFloatParam>();
|
||||
private readonly Dictionary<string, AnimFloatParam> _floatParams = new Dictionary<string, AnimFloatParam>();
|
||||
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
_from = from;
|
||||
_to = to;
|
||||
if (_from.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
|
||||
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
|
||||
}
|
||||
else if (_to.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
_from = from;
|
||||
_to = to;
|
||||
if (_from.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
|
||||
_from.runtimeAnimatorController = _to.runtimeAnimatorController;
|
||||
}
|
||||
else if (_to.runtimeAnimatorController == null)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerInfo GetPlayer()
|
||||
{
|
||||
return QSBPlayerManager.GetSyncObjects<AnimationSync>().First(x => x.Mirror == this).Player;
|
||||
}
|
||||
private PlayerInfo GetPlayer()
|
||||
=> QSBPlayerManager.GetSyncObjects<AnimationSync>().First(x => x.Mirror == this).Player;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_to == null || _from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_to.runtimeAnimatorController != _from.runtimeAnimatorController)
|
||||
{
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
SyncParams();
|
||||
SmoothFloats();
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (_to == null || _from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_to.runtimeAnimatorController != _from.runtimeAnimatorController)
|
||||
{
|
||||
_to.runtimeAnimatorController = _from.runtimeAnimatorController;
|
||||
}
|
||||
SyncParams();
|
||||
SmoothFloats();
|
||||
}
|
||||
|
||||
private void SyncParams()
|
||||
{
|
||||
foreach (var fromParam in _from.parameters)
|
||||
{
|
||||
switch (fromParam.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
if (!_floatParams.ContainsKey(fromParam.name))
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Tried to sync anim float that doesn't exist in dict : {fromParam.name}", MessageType.Warning);
|
||||
RebuildFloatParams();
|
||||
break;
|
||||
}
|
||||
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
_to.SetBool(fromParam.name, _from.GetBool(fromParam.name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void SyncParams()
|
||||
{
|
||||
foreach (var fromParam in _from.parameters)
|
||||
{
|
||||
switch (fromParam.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
if (!_floatParams.ContainsKey(fromParam.name))
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Tried to sync anim float that doesn't exist in dict : {fromParam.name}", MessageType.Warning);
|
||||
RebuildFloatParams();
|
||||
break;
|
||||
}
|
||||
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
_to.SetBool(fromParam.name, _from.GetBool(fromParam.name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SmoothFloats()
|
||||
{
|
||||
foreach (var floatParam in _floatParams)
|
||||
{
|
||||
var current = floatParam.Value.Smooth(SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, current);
|
||||
}
|
||||
}
|
||||
private void SmoothFloats()
|
||||
{
|
||||
foreach (var floatParam in _floatParams)
|
||||
{
|
||||
var current = floatParam.Value.Smooth(SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, current);
|
||||
}
|
||||
}
|
||||
|
||||
public void RebuildFloatParams()
|
||||
{
|
||||
_floatParams.Clear();
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RebuildFloatParams()
|
||||
{
|
||||
_floatParams.Clear();
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,69 +4,69 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class CrouchSync : NetworkBehaviour
|
||||
{
|
||||
public AnimFloatParam CrouchParam { get; } = new AnimFloatParam();
|
||||
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 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 float _sendTimer;
|
||||
private float _lastSentJumpChargeFraction;
|
||||
|
||||
private AnimationSync _animationSync;
|
||||
private PlayerCharacterController _playerController;
|
||||
private Animator _bodyAnim;
|
||||
private AnimationSync _animationSync;
|
||||
private PlayerCharacterController _playerController;
|
||||
private Animator _bodyAnim;
|
||||
|
||||
public void Init(AnimationSync animationSync, PlayerCharacterController playerController, Animator bodyAnim)
|
||||
{
|
||||
_animationSync = animationSync;
|
||||
_playerController = playerController;
|
||||
_bodyAnim = 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 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.SendCrouch(jumpChargeFraction);
|
||||
_lastSentJumpChargeFraction = jumpChargeFraction;
|
||||
_sendTimer = 0;
|
||||
}
|
||||
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.SendCrouch(jumpChargeFraction);
|
||||
_lastSentJumpChargeFraction = jumpChargeFraction;
|
||||
_sendTimer = 0;
|
||||
}
|
||||
|
||||
private void SyncRemoteCrouch()
|
||||
{
|
||||
if (_bodyAnim == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CrouchParam.Smooth(CrouchSmoothTime);
|
||||
var jumpChargeFraction = CrouchParam.Current;
|
||||
_bodyAnim.SetLayerWeight(CrouchLayerIndex, jumpChargeFraction);
|
||||
}
|
||||
}
|
||||
private void SyncRemoteCrouch()
|
||||
{
|
||||
if (_bodyAnim == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CrouchParam.Smooth(CrouchSmoothTime);
|
||||
var jumpChargeFraction = CrouchParam.Current;
|
||||
_bodyAnim.SetLayerWeight(CrouchLayerIndex, jumpChargeFraction);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,26 +5,26 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
public class ChangeAnimTypeEvent : QSBEvent<EnumMessage<AnimationType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayInstrument;
|
||||
public class ChangeAnimTypeEvent : QSBEvent<EnumMessage<AnimationType>>
|
||||
{
|
||||
public override EventType Type => EventType.PlayInstrument;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<uint, AnimationType>.AddListener(EventNames.QSBChangeAnimType, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<uint, AnimationType>.AddListener(EventNames.QSBChangeAnimType, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<uint, AnimationType>.RemoveListener(EventNames.QSBChangeAnimType, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<uint, AnimationType>.RemoveListener(EventNames.QSBChangeAnimType, Handler);
|
||||
|
||||
private void Handler(uint player, AnimationType type) => SendEvent(CreateMessage(player, type));
|
||||
private void Handler(uint player, AnimationType type) => SendEvent(CreateMessage(player, type));
|
||||
|
||||
private EnumMessage<AnimationType> CreateMessage(uint player, AnimationType type) => new EnumMessage<AnimationType>
|
||||
{
|
||||
AboutId = player,
|
||||
Value = type
|
||||
};
|
||||
private EnumMessage<AnimationType> CreateMessage(uint player, AnimationType type) => new EnumMessage<AnimationType>
|
||||
{
|
||||
AboutId = player,
|
||||
Value = type
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(EnumMessage<AnimationType> message)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetSyncObject<InstrumentsManager>(message.AboutId).CheckInstrumentProps(message.Value);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(EnumMessage<AnimationType> message)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(message.AboutId).AnimationSync.SetAnimationType(message.Value);
|
||||
QSBPlayerManager.GetSyncObject<InstrumentsManager>(message.AboutId).CheckInstrumentProps(message.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,30 +4,30 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
public class CrouchEvent : QSBEvent<FloatMessage>
|
||||
{
|
||||
public override EventType Type => EventType.AnimTrigger;
|
||||
public class CrouchEvent : QSBEvent<FloatMessage>
|
||||
{
|
||||
public override EventType Type => EventType.AnimTrigger;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<float>.AddListener(EventNames.QSBCrouch, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<float>.AddListener(EventNames.QSBCrouch, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<float>.RemoveListener(EventNames.QSBCrouch, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<float>.RemoveListener(EventNames.QSBCrouch, Handler);
|
||||
|
||||
private void Handler(float value) => SendEvent(CreateMessage(value));
|
||||
private void Handler(float value) => SendEvent(CreateMessage(value));
|
||||
|
||||
private FloatMessage CreateMessage(float value) => new FloatMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = value
|
||||
};
|
||||
private FloatMessage CreateMessage(float value) => new FloatMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Value = value
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(FloatMessage message)
|
||||
{
|
||||
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
|
||||
if (animationSync == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
animationSync.HandleCrouch(message.Value);
|
||||
}
|
||||
}
|
||||
public override void OnReceiveRemote(FloatMessage message)
|
||||
{
|
||||
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
|
||||
if (animationSync == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
animationSync.HandleCrouch(message.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,52 +4,52 @@ using QSB.Player;
|
||||
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.SuitActiveChange;
|
||||
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
|
||||
{
|
||||
public override EventType Type => EventType.SuitActiveChange;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
||||
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
||||
}
|
||||
|
||||
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
||||
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
||||
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
||||
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
||||
|
||||
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = value
|
||||
};
|
||||
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ToggleValue = value
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player?.UpdateState(State.Suit, message.ToggleValue);
|
||||
public override void OnReceiveRemote(ToggleMessage message)
|
||||
{
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player?.UpdateState(State.Suit, message.ToggleValue);
|
||||
|
||||
if (!player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!player.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var animator = player.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.SetAnimationType(type);
|
||||
}
|
||||
var animator = player.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.SetAnimationType(type);
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(ToggleMessage message)
|
||||
{
|
||||
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
|
||||
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.CurrentType = type;
|
||||
}
|
||||
}
|
||||
public override void OnReceiveLocal(ToggleMessage message)
|
||||
{
|
||||
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
|
||||
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
||||
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
||||
animator.CurrentType = type;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,34 +2,34 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
class QSBAnimationMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int stateHash;
|
||||
public float normalizedTime;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
stateHash = (int)reader.ReadPackedUInt32();
|
||||
normalizedTime = reader.ReadSingle();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
stateHash = (int)reader.ReadPackedUInt32();
|
||||
normalizedTime = reader.ReadSingle();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)stateHash);
|
||||
writer.Write(normalizedTime);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)stateHash);
|
||||
writer.Write(normalizedTime);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,28 +2,28 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationParametersMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
class QSBAnimationParametersMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] parameters;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
parameters = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
if (parameters == null)
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBytesAndSize(parameters, parameters.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,21 +2,21 @@
|
||||
|
||||
namespace QSB.Animation.Events
|
||||
{
|
||||
class QSBAnimationTriggerMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int hash;
|
||||
class QSBAnimationTriggerMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public int hash;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
hash = (int)reader.ReadPackedUInt32();
|
||||
}
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
hash = (int)reader.ReadPackedUInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)hash);
|
||||
}
|
||||
}
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WritePackedUInt32((uint)hash);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,10 +11,8 @@ namespace QSB.OrbSync
|
||||
{
|
||||
public static OrbManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
private void Awake()
|
||||
=> Instance = this;
|
||||
|
||||
private void BuildOrbSlots()
|
||||
{
|
||||
|
@ -11,15 +11,9 @@ namespace QSB.Player.Events
|
||||
{
|
||||
public override EventType Type => EventType.PlayerSectorChange;
|
||||
|
||||
public override void SetupListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
public override void SetupListener() => GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
||||
}
|
||||
public override void CloseListener() => GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
||||
|
||||
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
||||
|
||||
|
@ -45,10 +45,8 @@ namespace QSB.Player
|
||||
PlayerList.Clear();
|
||||
}
|
||||
|
||||
public static bool PlayerExists(uint id)
|
||||
{
|
||||
return id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
|
||||
}
|
||||
public static bool PlayerExists(uint id)
|
||||
=> id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
|
||||
|
||||
public static void HandleFullStateMessage(PlayerStateMessage message)
|
||||
{
|
||||
@ -62,15 +60,11 @@ namespace QSB.Player
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject
|
||||
{
|
||||
return PlayerSyncObjects.OfType<T>().Where(x => x != null);
|
||||
}
|
||||
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject
|
||||
=> PlayerSyncObjects.OfType<T>().Where(x => x != null);
|
||||
|
||||
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject
|
||||
{
|
||||
return GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
|
||||
}
|
||||
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject
|
||||
=> GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
|
||||
|
||||
public static bool IsBelongingToLocalPlayer(uint id)
|
||||
{
|
||||
@ -128,8 +122,8 @@ namespace QSB.Player
|
||||
{
|
||||
return default;
|
||||
}
|
||||
int count = 0;
|
||||
int totalCount = PlayerSyncObjects.Count;
|
||||
var count = 0;
|
||||
var totalCount = PlayerSyncObjects.Count;
|
||||
PlayerSyncObjects.RemoveAll(x => x == null);
|
||||
PlayerSyncObjects.RemoveAll(x => x.GetComponent<NetworkIdentity>() == null);
|
||||
if (PlayerSyncObjects.Count != totalCount)
|
||||
|
@ -71,10 +71,8 @@ namespace QSB
|
||||
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
private void OnDestroy()
|
||||
=> QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
|
||||
|
||||
private void OnSceneLoaded(OWScene scene)
|
||||
{
|
||||
|
@ -30,9 +30,7 @@ namespace QSB
|
||||
}
|
||||
}
|
||||
|
||||
private static bool InUniverse(OWScene scene)
|
||||
{
|
||||
return scene == OWScene.SolarSystem || scene == OWScene.EyeOfTheUniverse;
|
||||
}
|
||||
private static bool InUniverse(OWScene scene)
|
||||
=> scene == OWScene.SolarSystem || scene == OWScene.EyeOfTheUniverse;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,9 @@ namespace QSB.SectorSync
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
|
||||
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
=> QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
|
||||
|
||||
public void RebuildSectors()
|
||||
{
|
||||
|
@ -41,9 +41,7 @@ namespace QSB.SectorSync
|
||||
SendSector(transformSync.netId.Value, closestSector);
|
||||
}
|
||||
|
||||
private void SendSector(uint id, QSBSector sector)
|
||||
{
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
|
||||
}
|
||||
private void SendSector(uint id, QSBSector sector)
|
||||
=> GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,7 @@ namespace QSB.TimeSync.Events
|
||||
LoopCount = count
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(ServerTimeMessage message)
|
||||
{
|
||||
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
|
||||
}
|
||||
public override void OnReceiveRemote(ServerTimeMessage message)
|
||||
=> WakeUpSync.Instance.OnClientReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace QSB.TimeSync
|
||||
{
|
||||
public class WakeUpSync : NetworkBehaviour
|
||||
{
|
||||
public static WakeUpSync LocalInstance { get; private set; }
|
||||
public static WakeUpSync Instance { get; private set; }
|
||||
|
||||
private const float TimeThreshold = 0.5f;
|
||||
private const float MaxFastForwardSpeed = 60f;
|
||||
@ -27,10 +27,8 @@ namespace QSB.TimeSync
|
||||
private int _localLoopCount;
|
||||
private int _serverLoopCount;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
=> Instance = this;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@ -78,10 +76,8 @@ namespace QSB.TimeSync
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoopStart()
|
||||
{
|
||||
_localLoopCount++;
|
||||
}
|
||||
private void OnLoopStart()
|
||||
=> _localLoopCount++;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
@ -98,10 +94,8 @@ namespace QSB.TimeSync
|
||||
}
|
||||
}
|
||||
|
||||
private void SendServerTime()
|
||||
{
|
||||
GlobalMessenger<float, int>.FireEvent(EventNames.QSBServerTime, Time.timeSinceLevelLoad, _localLoopCount);
|
||||
}
|
||||
private void SendServerTime()
|
||||
=> GlobalMessenger<float, int>.FireEvent(EventNames.QSBServerTime, Time.timeSinceLevelLoad, _localLoopCount);
|
||||
|
||||
public void OnClientReceiveMessage(ServerTimeMessage message)
|
||||
{
|
||||
|
@ -188,9 +188,7 @@ namespace QSB.Tools
|
||||
return launcherRoot;
|
||||
}
|
||||
|
||||
private static MeshRenderer GetRenderer(GameObject root, string gameObjectName)
|
||||
{
|
||||
return root.GetComponentsInChildren<MeshRenderer>(true).First(x => x.name == gameObjectName);
|
||||
}
|
||||
private static MeshRenderer GetRenderer(GameObject root, string gameObjectName)
|
||||
=> root.GetComponentsInChildren<MeshRenderer>(true).First(x => x.name == gameObjectName);
|
||||
}
|
||||
}
|
@ -10,10 +10,8 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public static PlayerCameraSync LocalInstance { get; private set; }
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
=> LocalInstance = this;
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
|
@ -12,15 +12,11 @@ namespace QSB.TransformSync
|
||||
|
||||
private Transform _disabledSocket;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
=> LocalInstance = this;
|
||||
|
||||
private Transform GetProbe()
|
||||
{
|
||||
return Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
||||
}
|
||||
private Transform GetProbe()
|
||||
=> Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
|
@ -29,15 +29,10 @@ namespace QSB.TransformSync
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
protected virtual void OnDestroy()
|
||||
=> QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
_isInitialized = false;
|
||||
}
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse) => _isInitialized = false;
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
|
@ -25,20 +25,14 @@ namespace QSB.WorldSync
|
||||
WorldObjects.Add(worldObject);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetObjects<T>()
|
||||
{
|
||||
return WorldObjects.OfType<T>();
|
||||
}
|
||||
public static IEnumerable<T> GetObjects<T>()
|
||||
=> WorldObjects.OfType<T>();
|
||||
|
||||
public static T GetObject<T>(int id) where T : WorldObject
|
||||
{
|
||||
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
||||
}
|
||||
public static T GetObject<T>(int id) where T : WorldObject
|
||||
=> GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
||||
|
||||
public static void RemoveObjects<T>() where T : WorldObject
|
||||
{
|
||||
WorldObjects.RemoveAll(x => x.GetType() == typeof(T));
|
||||
}
|
||||
public static void RemoveObjects<T>() where T : WorldObject
|
||||
=> WorldObjects.RemoveAll(x => x.GetType() == typeof(T));
|
||||
|
||||
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user