mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
update
This commit is contained in:
@@ -15,5 +15,6 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
public class CanRotate : IEntityComponent { public ICompositeCondition Value; }
|
||||
|
||||
public class JumpForce : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
public class CanJump : IEntityComponent { public ICompositeCondition Value; }
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -9,18 +10,30 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
private ReactiveVariable<Vector3> _moveDirection;
|
||||
private ReactiveVariable<float> _moveSpeed;
|
||||
private CharacterController _controller;
|
||||
|
||||
private ReactiveVariable<bool> _isMoving;
|
||||
|
||||
private ICompositeCondition _canMove;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveDirection = entity.MoveDirection;
|
||||
_moveSpeed = entity.MoveSpeed;
|
||||
_controller = entity.CharacterController;
|
||||
|
||||
_isMoving = entity.IsMoving;
|
||||
_canMove = entity.CanMove;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_canMove.Evaluate() == false)
|
||||
return;
|
||||
|
||||
Vector3 velocity = _moveDirection.Value.normalized * _moveSpeed.Value;
|
||||
|
||||
_isMoving.Value = velocity.magnitude > 0;
|
||||
|
||||
_controller.Move(velocity * deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,15 +9,21 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
private ReactiveVariable<float> _jumpForce;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private ICompositeCondition _canJump;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_jumpForce = entity.JumpForce;
|
||||
_rigidbody = entity.Rigidbody;
|
||||
_canJump = entity.CanJump;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_canJump.Evaluate() == false)
|
||||
return;
|
||||
|
||||
_rigidbody.AddForce(Vector3.up * _jumpForce.Value, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -9,17 +10,32 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
private ReactiveVariable<Vector3> _moveDirection;
|
||||
private ReactiveVariable<float> _moveSpeed;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private ReactiveVariable<bool> _isMoving;
|
||||
|
||||
private ICompositeCondition _canMove;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveDirection = entity.MoveDirection;
|
||||
_moveSpeed = entity.MoveSpeed;
|
||||
_rigidbody = entity.Rigidbody;
|
||||
|
||||
_isMoving = entity.IsMoving;
|
||||
_canMove = entity.CanMove;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_canMove.Evaluate() == false)
|
||||
{
|
||||
_rigidbody.velocity = Vector3.zero;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 velocity = _moveDirection.Value.normalized * _moveSpeed.Value;
|
||||
|
||||
_isMoving.Value = velocity.magnitude > 0;
|
||||
|
||||
_rigidbody.velocity = velocity;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,16 +11,26 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
|
||||
private ReactiveVariable<float> _speed;
|
||||
private ReactiveVariable<Vector3> _direction;
|
||||
|
||||
private ICompositeCondition _canRotate;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_rigidbody = entity.Rigidbody;
|
||||
_speed = entity.RotationSpeed;
|
||||
_direction = entity.RotateDirection;
|
||||
|
||||
_canRotate = entity.CanRotate;
|
||||
|
||||
if (_direction.Value != Vector3.zero)
|
||||
_rigidbody.transform.rotation = Quaternion.LookRotation(_direction.Value.normalized);
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_canRotate.Evaluate() == false)
|
||||
return;
|
||||
|
||||
if (_direction.Value == Vector3.zero)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user