mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-02 22:31:10 +00:00
feat: add conditions
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
|
||||
public static class Entity
|
||||
{
|
||||
public const string TestEntity = "Entities/TestEntity";
|
||||
public const string Ghost = "Entities/TestEntity";
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, string> _scriptableObject = new()
|
||||
|
||||
@@ -19,12 +19,12 @@ namespace _Project.Develop.Runtime.Entities
|
||||
_monoEntitiesFactory = container.Resolve<MonoEntitiesFactory>();
|
||||
_playerInput = container.Resolve<IPlayerInputService>();
|
||||
}
|
||||
|
||||
public Entity CreateTestEntity(Vector3 position)
|
||||
|
||||
public Entity CreateGhostEntity(Vector3 position)
|
||||
{
|
||||
Entity entity = CreateEmpty();
|
||||
|
||||
_monoEntitiesFactory.Create(entity, position, PathToResources.Entity.TestEntity);
|
||||
_monoEntitiesFactory.Create(entity, position, PathToResources.Entity.Ghost);
|
||||
|
||||
entity
|
||||
.AddMoveDirection()
|
||||
@@ -33,10 +33,8 @@ namespace _Project.Develop.Runtime.Entities
|
||||
.AddRotationSpeed(new ReactiveVariable<float>(800));
|
||||
|
||||
entity
|
||||
.AddSystem(new CharacterControllerMovementSystem())
|
||||
.AddSystem(new TransformRotationSystem())
|
||||
// .AddSystem(new RigidbodyMovementSystem())
|
||||
// .AddSystem(new RigidbodyRotationSystem())
|
||||
.AddSystem(new RigidbodyMovementSystem())
|
||||
.AddSystem(new RigidbodyRotationSystem())
|
||||
.AddSystem(new MoveDirectionByInputSystem(_playerInput))
|
||||
.AddSystem(new RotateDirectionByInputSystem(_playerInput));
|
||||
|
||||
|
||||
@@ -126,6 +126,49 @@ namespace _Project.Develop.Runtime.Entities
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.IsMoving IsMovingC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.IsMoving>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> IsMoving => IsMovingC.Value;
|
||||
|
||||
public bool TryGetIsMoving(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.IsMoving component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddIsMoving()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.IsMoving() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddIsMoving(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.IsMoving() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanMove CanMoveC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanMove>();
|
||||
|
||||
public _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition CanMove => CanMoveC.Value;
|
||||
|
||||
public bool TryGetCanMove(out _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanMove component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddCanMove(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanMove() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotateDirection RotateDirectionC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotateDirection>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> RotateDirection => RotateDirectionC.Value;
|
||||
@@ -174,6 +217,25 @@ namespace _Project.Develop.Runtime.Entities
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanRotate CanRotateC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanRotate>();
|
||||
|
||||
public _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition CanRotate => CanRotateC.Value;
|
||||
|
||||
public bool TryGetCanRotate(out _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanRotate component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddCanRotate(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanRotate() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.JumpForce JumpForceC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.JumpForce>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> JumpForce => JumpForceC.Value;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -6,9 +7,13 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class MoveDirection : IEntityComponent { public ReactiveVariable<Vector3> Value; }
|
||||
public class MoveSpeed : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
|
||||
public class IsMoving : IEntityComponent { public ReactiveVariable<bool> Value; }
|
||||
public class CanMove : IEntityComponent { public ICompositeCondition Value; }
|
||||
|
||||
public class RotateDirection : IEntityComponent { public ReactiveVariable<Vector3> Value; }
|
||||
public class RotationSpeed : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
public class CanRotate : IEntityComponent { public ICompositeCondition Value; }
|
||||
|
||||
public class JumpForce : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_entity = _entitiesFactory.CreateTestEntity(Vector3.zero);
|
||||
_entity = _entitiesFactory.CreateGhostEntity(Vector3.zero);
|
||||
|
||||
_isRunning = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a03759ea3f034fa6a538e0a167d7c72a
|
||||
timeCreated: 1771515376
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace _Project.Develop.Runtime.Utilities.Conditions
|
||||
{
|
||||
public class CompositeCondition : ICompositeCondition
|
||||
{
|
||||
private List<(ICondition, Func<bool, bool, bool>, int)> _conditions = new();
|
||||
private Func<bool, bool, bool> _standardLogicOperation;
|
||||
|
||||
public CompositeCondition(Func<bool, bool, bool> standardLogicOperation)
|
||||
{
|
||||
_standardLogicOperation = standardLogicOperation;
|
||||
}
|
||||
|
||||
public CompositeCondition() : this(LogicOperationsUtils.And)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ICompositeCondition Add(ICondition condition, int order = 0, Func<bool, bool, bool> logicOperation = null)
|
||||
{
|
||||
_conditions.Add((condition, logicOperation, order));
|
||||
_conditions = _conditions.OrderBy(cond => cond.Item3).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool Evaluate()
|
||||
{
|
||||
if (_conditions.Count == 0)
|
||||
return false;
|
||||
|
||||
bool result = _conditions[0].Item1.Evaluate();
|
||||
|
||||
for (int i = 1; i < _conditions.Count; i++)
|
||||
{
|
||||
(ICondition, Func<bool, bool, bool>, int) currentCondition = _conditions[i];
|
||||
|
||||
if (currentCondition.Item2 != null)
|
||||
result = currentCondition.Item2.Invoke(result, currentCondition.Item1.Evaluate());
|
||||
else
|
||||
result = _standardLogicOperation.Invoke(result, currentCondition.Item1.Evaluate());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ICompositeCondition Remove(ICondition condition)
|
||||
{
|
||||
(ICondition, Func<bool, bool, bool>, int) conditionPair = _conditions.First(condPair => condPair.Item1 == condition);
|
||||
_conditions.Remove(conditionPair);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f44783069f2d1fb42bdd6608da2e604a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace _Project.Develop.Runtime.Utilities.Conditions
|
||||
{
|
||||
public class FuncCondition : ICondition
|
||||
{
|
||||
private Func<bool> _condition;
|
||||
|
||||
public FuncCondition(Func<bool> condition)
|
||||
{
|
||||
_condition = condition;
|
||||
}
|
||||
|
||||
public bool Evaluate() => _condition.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d62e21bbc0d33c7408a9cd905463b830
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace _Project.Develop.Runtime.Utilities.Conditions
|
||||
{
|
||||
public interface ICompositeCondition : ICondition
|
||||
{
|
||||
ICompositeCondition Add(ICondition condition, int order = 0, Func<bool, bool, bool> logicOperation = null);
|
||||
|
||||
ICompositeCondition Remove(ICondition condition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3bfaadc771fd854f9d27882b2212136
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _Project.Develop.Runtime.Utilities.Conditions
|
||||
{
|
||||
public interface ICondition
|
||||
{
|
||||
bool Evaluate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36fcc8f7fc765414388895dc842fe0f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace _Project.Develop.Runtime.Utilities.Conditions
|
||||
{
|
||||
public class LogicOperationsUtils
|
||||
{
|
||||
public static bool And(bool a, bool b) => a && b;
|
||||
public static bool Or(bool a, bool b) => a || b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44cb53d5052ea6244b01f10d6f37b4a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user