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 CrouchSync _crouchSync;
private RuntimeAnimatorController RiebeckController;
private RuntimeAnimatorController ChertController;
private RuntimeAnimatorController GabbroController;
private RuntimeAnimatorController FeldsparController;
private void Awake()
{
_anim = gameObject.AddComponent<Animator>();
_netAnim = gameObject.AddComponent<NetworkAnimator>();
_netAnim.enabled = false;
_netAnim.animator = _anim;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
@ -41,6 +48,20 @@ namespace QSB.Animation
_playerController.OnBecomeUngrounded -= OnBecomeUngrounded;
GlobalMessenger.RemoveListener(EventNames.SuitUp, OnSuitUp);
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)
@ -173,5 +194,26 @@ namespace QSB.Animation
}
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;
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))

View File

@ -1,4 +1,5 @@
using QSB.EventsCore;
using QSB.Animation;
using QSB.EventsCore;
using QSB.Instruments.QSBCamera;
using QSB.Player;
using UnityEngine;
@ -8,28 +9,11 @@ namespace QSB.Instruments
public class InstrumentsManager : MonoBehaviour
{
public static InstrumentsManager Instance;
private RuntimeAnimatorController RiebeckController;
private RuntimeAnimatorController ChertController;
private RuntimeAnimatorController GabbroController;
private RuntimeAnimatorController FeldsparController;
private void Awake()
{
Instance = this;
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()
@ -40,9 +24,7 @@ namespace QSB.Instruments
{
CameraManager.Instance.SwitchTo3rdPerson();
SwitchToInstrument(InstrumentType.RIEBECK);
var animator = Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2").GetComponent<Animator>();
animator.runtimeAnimatorController = ChertController;
animator.SetTrigger("Playing");
QSBPlayerManager.GetSyncObject<AnimationSync>(QSBPlayerManager.LocalPlayerId).SetAnimationType(AnimationType.Chert);
}
else
{

View File

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