move animation logic to animationsync

This commit is contained in:
Mister_Nebula 2020-11-07 21:20:30 +00:00
parent d0996b4011
commit e7a8c64af5
5 changed files with 57 additions and 21 deletions

View File

@ -21,12 +21,19 @@ namespace QSB.Animation
private PlayerCharacterController _playerController; private PlayerCharacterController _playerController;
private CrouchSync _crouchSync; private CrouchSync _crouchSync;
private RuntimeAnimatorController RiebeckController;
private RuntimeAnimatorController ChertController;
private RuntimeAnimatorController GabbroController;
private RuntimeAnimatorController FeldsparController;
private void Awake() private void Awake()
{ {
_anim = gameObject.AddComponent<Animator>(); _anim = gameObject.AddComponent<Animator>();
_netAnim = gameObject.AddComponent<NetworkAnimator>(); _netAnim = gameObject.AddComponent<NetworkAnimator>();
_netAnim.enabled = false; _netAnim.enabled = false;
_netAnim.animator = _anim; _netAnim.animator = _anim;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
} }
private void OnDestroy() private void OnDestroy()
@ -41,6 +48,20 @@ namespace QSB.Animation
_playerController.OnBecomeUngrounded -= OnBecomeUngrounded; _playerController.OnBecomeUngrounded -= OnBecomeUngrounded;
GlobalMessenger.RemoveListener(EventNames.SuitUp, OnSuitUp); GlobalMessenger.RemoveListener(EventNames.SuitUp, OnSuitUp);
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, OnSuitDown); GlobalMessenger.RemoveListener(EventNames.RemoveSuit, OnSuitDown);
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(OWScene scene, bool inUniverse)
{
var reibeckRoot = GameObject.Find("Traveller_HEA_Riebeck_ANIM_Talking");
RiebeckController = reibeckRoot.GetComponent<Animator>().runtimeAnimatorController;
var chertRoot = GameObject.Find("Traveller_HEA_Chert_ANIM_Chatter_Chipper");
ChertController = chertRoot.GetComponent<Animator>().runtimeAnimatorController;
var gabbroRoot = GameObject.Find("Traveller_HEA_Gabbro_ANIM_IdleFlute");
GabbroController = gabbroRoot.GetComponent<Animator>().runtimeAnimatorController;
var feldsparRoot = GameObject.Find("Traveller_HEA_Feldspar_ANIM_Talking");
FeldsparController = feldsparRoot.GetComponent<Animator>().runtimeAnimatorController;
} }
private void InitCommon(Transform body) private void InitCommon(Transform body)
@ -173,5 +194,26 @@ namespace QSB.Animation
} }
SuitDown(); SuitDown();
} }
public void SetAnimationType(AnimationType type)
{
switch (type)
{
case AnimationType.PlayerSuited:
_bodyAnim.runtimeAnimatorController = _suitedAnimController;
_anim.runtimeAnimatorController = _suitedAnimController;
break;
case AnimationType.PlayerUnsuited:
_bodyAnim.runtimeAnimatorController = _unsuitedAnimController;
_anim.runtimeAnimatorController = _unsuitedAnimController;
break;
case AnimationType.Chert:
_bodyAnim.runtimeAnimatorController = ChertController;
_bodyAnim.SetTrigger("Playing");
_anim.runtimeAnimatorController = ChertController;
_anim.SetTrigger("Playing");
break;
}
}
} }
} }

View File

@ -0,0 +1,9 @@
namespace QSB.Animation
{
public enum AnimationType
{
PlayerSuited,
PlayerUnsuited,
Chert
}
}

View File

@ -21,10 +21,12 @@ namespace QSB.Animation
_to = to; _to = to;
if (_from.runtimeAnimatorController == null) if (_from.runtimeAnimatorController == null)
{ {
DebugLog.DebugWrite($"Warning - \"From\" ({from.name}) controller is null.", MessageType.Warning);
_from.runtimeAnimatorController = _to.runtimeAnimatorController; _from.runtimeAnimatorController = _to.runtimeAnimatorController;
} }
else if (_to.runtimeAnimatorController == null) else if (_to.runtimeAnimatorController == null)
{ {
DebugLog.DebugWrite($"Warning - \"To\" ({to.name}) controller is null.", MessageType.Warning);
_to.runtimeAnimatorController = _from.runtimeAnimatorController; _to.runtimeAnimatorController = _from.runtimeAnimatorController;
} }
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float)) foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))

View File

@ -1,4 +1,5 @@
using QSB.EventsCore; using QSB.Animation;
using QSB.EventsCore;
using QSB.Instruments.QSBCamera; using QSB.Instruments.QSBCamera;
using QSB.Player; using QSB.Player;
using UnityEngine; using UnityEngine;
@ -8,28 +9,11 @@ namespace QSB.Instruments
public class InstrumentsManager : MonoBehaviour public class InstrumentsManager : MonoBehaviour
{ {
public static InstrumentsManager Instance; public static InstrumentsManager Instance;
private RuntimeAnimatorController RiebeckController;
private RuntimeAnimatorController ChertController;
private RuntimeAnimatorController GabbroController;
private RuntimeAnimatorController FeldsparController;
private void Awake() private void Awake()
{ {
Instance = this; Instance = this;
gameObject.AddComponent<CameraManager>(); gameObject.AddComponent<CameraManager>();
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(OWScene scene, bool inUniverse)
{
var reibeckRoot = GameObject.Find("Traveller_HEA_Riebeck_ANIM_Talking");
RiebeckController = reibeckRoot.GetComponent<Animator>().runtimeAnimatorController;
var chertRoot = GameObject.Find("Traveller_HEA_Chert_ANIM_Chatter_Chipper");
ChertController = chertRoot.GetComponent<Animator>().runtimeAnimatorController;
var gabbroRoot = GameObject.Find("Traveller_HEA_Gabbro_ANIM_IdleFlute");
GabbroController = gabbroRoot.GetComponent<Animator>().runtimeAnimatorController;
var feldsparRoot = GameObject.Find("Traveller_HEA_Feldspar_ANIM_Talking");
FeldsparController = feldsparRoot.GetComponent<Animator>().runtimeAnimatorController;
} }
private void Update() private void Update()
@ -40,9 +24,7 @@ namespace QSB.Instruments
{ {
CameraManager.Instance.SwitchTo3rdPerson(); CameraManager.Instance.SwitchTo3rdPerson();
SwitchToInstrument(InstrumentType.RIEBECK); SwitchToInstrument(InstrumentType.RIEBECK);
var animator = Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2").GetComponent<Animator>(); QSBPlayerManager.GetSyncObject<AnimationSync>(QSBPlayerManager.LocalPlayerId).SetAnimationType(AnimationType.Chert);
animator.runtimeAnimatorController = ChertController;
animator.SetTrigger("Playing");
} }
else else
{ {

View File

@ -123,6 +123,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Animation\AnimationSync.cs" /> <Compile Include="Animation\AnimationSync.cs" />
<Compile Include="Animation\AnimationType.cs" />
<Compile Include="Animation\Events\AnimTriggerEvent.cs" /> <Compile Include="Animation\Events\AnimTriggerEvent.cs" />
<Compile Include="Animation\AnimatorMirror.cs" /> <Compile Include="Animation\AnimatorMirror.cs" />
<Compile Include="Animation\AnimControllerPatch.cs" /> <Compile Include="Animation\AnimControllerPatch.cs" />