AmazingAlek d7c0c06698
Alek/decoupling (#23)
* refactoring
2020-02-21 23:36:07 +01:00

40 lines
977 B
C#

using UnityEngine;
using UnityEngine.Networking;
namespace QSB.Animation
{
public class AnimationSync : NetworkBehaviour
{
private Animator _anim;
private NetworkAnimator _netAnim;
private void Awake()
{
_anim = gameObject.AddComponent<Animator>();
_netAnim = gameObject.AddComponent<NetworkAnimator>();
_netAnim.animator = _anim;
}
public void Init(Transform body)
{
var bodyAnim = body.GetComponent<Animator>();
var animMirror = body.gameObject.AddComponent<AnimatorMirror>();
if (isLocalPlayer)
{
animMirror.Init(bodyAnim, _anim);
}
else
{
animMirror.Init(_anim, bodyAnim);
}
for (var i = 0; i < _anim.parameterCount; i++)
{
_netAnim.SetParameterAutoSend(i, true);
}
}
}
}