Advertisement
Guest User

Untitled

a guest
Jun 29th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. // Hybrid ecs
  2.  
  3. public class AnimationControlComponent : MonoBehaviour
  4. {
  5.     public bool disable_movement = false;
  6.     public bool disable_rotation = false;
  7.     public Animator assignedAnimator;
  8. }
  9.  
  10. [UpdateAfter(typeof(PlayerInputSystem))]
  11. public class AnimationControlSystem : ComponentSystem
  12. {
  13.     public struct State
  14.     {
  15.         public AnimationControlComponent animationControl;
  16.         public CritterMovementComponent critterMovement;
  17.     }
  18.  
  19.     protected override void OnUpdate()
  20.     {
  21.         var entities = GetEntities<State>();
  22.  
  23.         foreach (var entity in entities)
  24.         {
  25.             var xzImpulse = entity.critterMovement.directionToGo;
  26.             xzImpulse.y = 0;
  27.             entity.animationControl.assignedAnimator.SetFloat("movementSpeed", Vector3.Magnitude(xzImpulse));
  28.             entity.animationControl.disable_movement = entity.animationControl.assignedAnimator.GetBool("disable_movement");
  29.             entity.animationControl.disable_rotation = entity.animationControl.assignedAnimator.GetBool("disable_rotation");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement