Skip to main content
edited body
Source Link
Emil
  • 145
  • 8
using Assets.Components;
using Unity.Entities;
using UnityEngine;

namespace Assets.BehaviorSystems
{
    public partial class InputComponentUpdatesAnimator : SystemBase
    {
        protected override void OnUpdate()
        {
            this.Entities
                .WithAll<Animator, InputComponent>()
                .ForEach(
                    (Animator animator, in InputComponent input) =>
                    {
                        animator.SetBool("IsJumping", input.IsJumping);
                        animator.SetBool("IsRunning", input.IsRunning);
                        animator.SetBool("IsCrouching", input.IsCrouching);
                        animator.SetFloat("DeltaLook.x", input.DeltaLook.x);
                        animator.SetFloat("DeltaLook.y", input.DeltaLook.y);
                        animator.SetFloat("DeltaMove.x", input.DeltaMove.x);
                        animator.SetFloat("DeltaMove.y", input.DeltaMove.xy);
                        animator.SetFloat("DeltaRotate", (float)input.DeltaRotate);
                    }
                )
                .WithoutBurst()
                .Run();
        }
    }
}

using Assets.Components;
using Unity.Entities;
using UnityEngine;

namespace Assets.BehaviorSystems
{
    public partial class InputComponentUpdatesAnimator : SystemBase
    {
        protected override void OnUpdate()
        {
            this.Entities
                .WithAll<Animator, InputComponent>()
                .ForEach(
                    (Animator animator, in InputComponent input) =>
                    {
                        animator.SetBool("IsJumping", input.IsJumping);
                        animator.SetBool("IsRunning", input.IsRunning);
                        animator.SetBool("IsCrouching", input.IsCrouching);
                        animator.SetFloat("DeltaLook.x", input.DeltaLook.x);
                        animator.SetFloat("DeltaLook.y", input.DeltaLook.y);
                        animator.SetFloat("DeltaMove.x", input.DeltaMove.x);
                        animator.SetFloat("DeltaMove.y", input.DeltaMove.x);
                        animator.SetFloat("DeltaRotate", (float)input.DeltaRotate);
                    }
                )
                .WithoutBurst()
                .Run();
        }
    }
}

using Assets.Components;
using Unity.Entities;
using UnityEngine;

namespace Assets.BehaviorSystems
{
    public partial class InputComponentUpdatesAnimator : SystemBase
    {
        protected override void OnUpdate()
        {
            this.Entities
                .WithAll<Animator, InputComponent>()
                .ForEach(
                    (Animator animator, in InputComponent input) =>
                    {
                        animator.SetBool("IsJumping", input.IsJumping);
                        animator.SetBool("IsRunning", input.IsRunning);
                        animator.SetBool("IsCrouching", input.IsCrouching);
                        animator.SetFloat("DeltaLook.x", input.DeltaLook.x);
                        animator.SetFloat("DeltaLook.y", input.DeltaLook.y);
                        animator.SetFloat("DeltaMove.x", input.DeltaMove.x);
                        animator.SetFloat("DeltaMove.y", input.DeltaMove.y);
                        animator.SetFloat("DeltaRotate", (float)input.DeltaRotate);
                    }
                )
                .WithoutBurst()
                .Run();
        }
    }
}

Source Link
Emil
  • 145
  • 8

I managed to get it working after selecting "Convert And Inject Game Object" enter image description here

using System;
using Unity.Entities;
using UnityEngine;

namespace Assets.Components
{
    [GenerateAuthoringComponent]
    [Serializable]
    public struct InputComponent : IComponentData
    {
        public bool IsJumping;
        public bool IsRunning;
        public bool IsCrouching;
        public Vector2 DeltaLook;
        public Vector2 DeltaMove;
        public double DeltaRotate;
    }
}

using Assets.Components;
using Unity.Entities;
using UnityEngine;
using UnityEngine.InputSystem;

namespace Assets.BehaviorSystems
{
    public partial class InputActionsUpdatesInputComponent : SystemBase
    {
        InputActions inputActions;

        protected override void OnCreate()
        {
            base.OnCreate();

            inputActions = new InputActions();
            inputActions.Enable();
        }

        protected override void OnUpdate()
        {
            InputSystem.Update();

            InputComponent input = new InputComponent
            {
                IsJumping = inputActions.MainCharacter.Jump.IsPressed(),
                IsRunning = inputActions.MainCharacter.Run.IsPressed(),
                IsCrouching = inputActions.MainCharacter.Crouch.IsPressed(),
                DeltaLook = inputActions.MainCharacter.Look.ReadValue<Vector2>(),
                DeltaRotate = inputActions.MainCharacter.Rotate.ReadValue<float>(),
                DeltaMove = inputActions.MainCharacter.Move.ReadValue<Vector2>()
            };

            this.Entities
                .WithAll<InputComponent>()
                .ForEach(
                    (ref InputComponent entity) =>
                    {
                        entity.IsJumping = input.IsJumping;
                        entity.IsRunning = input.IsRunning;
                        entity.IsCrouching = input.IsCrouching;
                        entity.DeltaLook = input.DeltaLook;
                        entity.DeltaRotate = input.DeltaRotate;
                        entity.DeltaMove = input.DeltaMove;
                    }
                )
                .Run();
        }
    }
}

using Assets.Components;
using Unity.Entities;
using UnityEngine;

namespace Assets.BehaviorSystems
{
    public partial class InputComponentUpdatesAnimator : SystemBase
    {
        protected override void OnUpdate()
        {
            this.Entities
                .WithAll<Animator, InputComponent>()
                .ForEach(
                    (Animator animator, in InputComponent input) =>
                    {
                        animator.SetBool("IsJumping", input.IsJumping);
                        animator.SetBool("IsRunning", input.IsRunning);
                        animator.SetBool("IsCrouching", input.IsCrouching);
                        animator.SetFloat("DeltaLook.x", input.DeltaLook.x);
                        animator.SetFloat("DeltaLook.y", input.DeltaLook.y);
                        animator.SetFloat("DeltaMove.x", input.DeltaMove.x);
                        animator.SetFloat("DeltaMove.y", input.DeltaMove.x);
                        animator.SetFloat("DeltaRotate", (float)input.DeltaRotate);
                    }
                )
                .WithoutBurst()
                .Run();
        }
    }
}