mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
init: add project
This commit is contained in:
8
Assets/_Project/Develop/Runtime/Logic/Gameplay.meta
Normal file
8
Assets/_Project/Develop/Runtime/Logic/Gameplay.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fae46e531ec7787489113ce181c37e8e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8729b2af024848039cd2435e34826f40
|
||||
timeCreated: 1771427180
|
||||
@@ -0,0 +1,13 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Common
|
||||
{
|
||||
public class CharacterControllerEntityRegistrator : MonoEntityRegistrator
|
||||
{
|
||||
public override void Register(Entity entity)
|
||||
{
|
||||
entity.AddCharacterController(GetComponent<CharacterController>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 901d0931c1074853a656db4b4364f490
|
||||
timeCreated: 1771433328
|
||||
@@ -0,0 +1,11 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Common
|
||||
{
|
||||
public class RigidbodyComponent : IEntityComponent { public Rigidbody Value; }
|
||||
public class TransformComponent : IEntityComponent { public Transform Value; }
|
||||
public class CharacterControllerComponent : IEntityComponent { public CharacterController Value; }
|
||||
public class NavMeshAgentComponent : IEntityComponent { public NavMeshAgent Value; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29b78ec58e4a493fbc73c343aa2e9144
|
||||
timeCreated: 1771427186
|
||||
@@ -0,0 +1,13 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Common
|
||||
{
|
||||
public class NavMeshAgentEntityRegistrator : MonoEntityRegistrator
|
||||
{
|
||||
public override void Register(Entity entity)
|
||||
{
|
||||
entity.AddNavMeshAgent(GetComponent<NavMeshAgent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8fec398824640aba90f8183ba2b5985
|
||||
timeCreated: 1771435813
|
||||
@@ -0,0 +1,13 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Common
|
||||
{
|
||||
public class RigidbodyEntityRegistrator : MonoEntityRegistrator
|
||||
{
|
||||
public override void Register(Entity entity)
|
||||
{
|
||||
entity.AddRigidbody(GetComponent<Rigidbody>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7fdeece4c60497ea61a1006e47bfbc5
|
||||
timeCreated: 1771427186
|
||||
@@ -0,0 +1,12 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Common
|
||||
{
|
||||
public class TransformEntityRegistrator : MonoEntityRegistrator
|
||||
{
|
||||
public override void Register(Entity entity)
|
||||
{
|
||||
entity.AddTransform(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3d77209b50f4ecf9185ae250a76b909
|
||||
timeCreated: 1771433629
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c87b54b768645cda0de4e1f0e97ed51
|
||||
timeCreated: 1771425395
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public class CollidersRegistryService
|
||||
{
|
||||
private readonly Dictionary<Collider, Entity> _colliderToEntity = new();
|
||||
|
||||
public void Register(Collider collider, Entity entity)
|
||||
{
|
||||
_colliderToEntity.Add(collider, entity);
|
||||
}
|
||||
|
||||
public void Unregister(Collider collider)
|
||||
{
|
||||
_colliderToEntity.Remove(collider);
|
||||
}
|
||||
|
||||
public Entity GetBy(Collider collider)
|
||||
{
|
||||
if (_colliderToEntity.TryGetValue(collider, out Entity entity))
|
||||
return entity;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e43e968a40dc46699c23f272909cf9cb
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,50 @@
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.Movement;
|
||||
using _Project.Develop.Runtime.Utilities.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public class EntitiesFactory
|
||||
{
|
||||
private readonly EntitiesLifeContext _entitiesLifeContext;
|
||||
private readonly MonoEntitiesFactory _monoEntitiesFactory;
|
||||
private readonly IPlayerInputService _playerInput;
|
||||
|
||||
public EntitiesFactory(DIContainer container)
|
||||
{
|
||||
_entitiesLifeContext = container.Resolve<EntitiesLifeContext>();
|
||||
_monoEntitiesFactory = container.Resolve<MonoEntitiesFactory>();
|
||||
_playerInput = container.Resolve<IPlayerInputService>();
|
||||
}
|
||||
|
||||
public Entity CreateTestEntity(Vector3 position)
|
||||
{
|
||||
Entity entity = CreateEmpty();
|
||||
|
||||
_monoEntitiesFactory.Create(entity, position, PathToResources.Entity.TestEntity);
|
||||
|
||||
entity
|
||||
.AddMoveDirection()
|
||||
.AddRotateDirection()
|
||||
.AddMoveSpeed(new ReactiveVariable<float>(10))
|
||||
.AddRotationSpeed(new ReactiveVariable<float>(800));
|
||||
|
||||
entity
|
||||
.AddSystem(new CharacterControllerMovementSystem())
|
||||
.AddSystem(new TransformRotationSystem())
|
||||
// .AddSystem(new RigidbodyMovementSystem())
|
||||
// .AddSystem(new RigidbodyRotationSystem())
|
||||
.AddSystem(new MoveDirectionByInputSystem(_playerInput))
|
||||
.AddSystem(new RotateDirectionByInputSystem(_playerInput));
|
||||
|
||||
_entitiesLifeContext.Add(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Entity CreateEmpty() => new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af347dbf800d4edfadf180cf91c44b1a
|
||||
timeCreated: 1771427064
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public class EntitiesLifeContext : IDisposable
|
||||
{
|
||||
public event Action<Entity> Added;
|
||||
public event Action<Entity> Released;
|
||||
|
||||
private readonly List<Entity> _entities = new();
|
||||
private readonly List<Entity> _releaseRequests = new();
|
||||
|
||||
public IReadOnlyList<Entity> Entities => _entities;
|
||||
|
||||
public void Add(Entity entity)
|
||||
{
|
||||
_entities.Add(entity);
|
||||
|
||||
entity.Initialize();
|
||||
|
||||
Added?.Invoke(entity);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
for (int i = 0; i < _entities.Count; i++)
|
||||
_entities[i].OnUpdate(deltaTime);
|
||||
|
||||
foreach (Entity entity in _releaseRequests)
|
||||
{
|
||||
_entities.Remove(entity);
|
||||
entity.Dispose();
|
||||
Released?.Invoke(entity);
|
||||
}
|
||||
|
||||
_releaseRequests.Clear();
|
||||
}
|
||||
|
||||
public void Release(Entity entity)
|
||||
{
|
||||
_releaseRequests.Add(entity);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (Entity entity in _entities)
|
||||
entity.Dispose();
|
||||
|
||||
_entities.Clear();
|
||||
_releaseRequests.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cee7e44950c49d180ae94ab120fad37
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public partial class Entity : IDisposable
|
||||
{
|
||||
public event Action<Entity> Initialized;
|
||||
|
||||
private readonly Dictionary<Type, IEntityComponent> _components = new();
|
||||
|
||||
private readonly List<IEntitySystem> _systems = new();
|
||||
|
||||
private readonly List<IInitializableSystem> _initializables = new();
|
||||
private readonly List<IUpdatableSystem> _updatables = new();
|
||||
private readonly List<IDisposableSystem> _disposables = new();
|
||||
|
||||
private bool _isInit;
|
||||
|
||||
public bool IsInit => _isInit;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (IInitializableSystem initializable in _initializables)
|
||||
initializable.OnInit(this);
|
||||
|
||||
_isInit = true;
|
||||
|
||||
Initialized?.Invoke(this);
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_isInit == false)
|
||||
return;
|
||||
|
||||
foreach (IUpdatableSystem updatable in _updatables)
|
||||
updatable.OnUpdate(deltaTime);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (IDisposableSystem disposable in _disposables)
|
||||
disposable.OnDispose();
|
||||
|
||||
_isInit = false;
|
||||
}
|
||||
|
||||
public Entity AddComponent<TComponent>(TComponent component) where TComponent : class, IEntityComponent
|
||||
{
|
||||
_components.Add(typeof(TComponent), component);
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool HasComponent<TComponent>() where TComponent : class, IEntityComponent
|
||||
{
|
||||
return _components.ContainsKey(typeof(TComponent));
|
||||
}
|
||||
|
||||
public bool TryGetComponent<TComponent>(out TComponent component) where TComponent : class, IEntityComponent
|
||||
{
|
||||
if(_components.TryGetValue(typeof(TComponent), out IEntityComponent findedObject))
|
||||
{
|
||||
component = (TComponent)findedObject;
|
||||
return true;
|
||||
}
|
||||
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public TComponent GetComponent<TComponent>() where TComponent : class, IEntityComponent
|
||||
{
|
||||
if (TryGetComponent(out TComponent component) == false)
|
||||
throw new ArgumentException($"Entity not exist {typeof(TComponent)}");
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
public Entity AddSystem(IEntitySystem system)
|
||||
{
|
||||
if (_systems.Contains(system))
|
||||
throw new ArgumentException(system.GetType().ToString());
|
||||
|
||||
_systems.Add(system);
|
||||
|
||||
if (system is IInitializableSystem initializable)
|
||||
{
|
||||
_initializables.Add(initializable);
|
||||
|
||||
if (_isInit)
|
||||
initializable.OnInit(this);
|
||||
}
|
||||
|
||||
if (system is IUpdatableSystem updatable)
|
||||
_updatables.Add(updatable);
|
||||
|
||||
if (system is IDisposableSystem disposable)
|
||||
_disposables.Add(disposable);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cae313f27754e89bf5ad980839b9e41
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 658341c858324417b69890cb508b580b
|
||||
timeCreated: 1771428293
|
||||
@@ -0,0 +1,202 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public partial class Entity
|
||||
{
|
||||
public Assets._Project.Develop.Runtime.Gameplay.Common.RigidbodyComponent RigidbodyC => GetComponent<Assets._Project.Develop.Runtime.Gameplay.Common.RigidbodyComponent>();
|
||||
|
||||
public UnityEngine.Rigidbody Rigidbody => RigidbodyC.Value;
|
||||
|
||||
public bool TryGetRigidbody(out UnityEngine.Rigidbody value)
|
||||
{
|
||||
bool result = TryGetComponent(out Assets._Project.Develop.Runtime.Gameplay.Common.RigidbodyComponent component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(UnityEngine.Rigidbody);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddRigidbody(UnityEngine.Rigidbody value)
|
||||
{
|
||||
return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.RigidbodyComponent() {Value = value});
|
||||
}
|
||||
|
||||
public Assets._Project.Develop.Runtime.Gameplay.Common.TransformComponent TransformC => GetComponent<Assets._Project.Develop.Runtime.Gameplay.Common.TransformComponent>();
|
||||
|
||||
public UnityEngine.Transform Transform => TransformC.Value;
|
||||
|
||||
public bool TryGetTransform(out UnityEngine.Transform value)
|
||||
{
|
||||
bool result = TryGetComponent(out Assets._Project.Develop.Runtime.Gameplay.Common.TransformComponent component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(UnityEngine.Transform);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddTransform(UnityEngine.Transform value)
|
||||
{
|
||||
return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.TransformComponent() {Value = value});
|
||||
}
|
||||
|
||||
public Assets._Project.Develop.Runtime.Gameplay.Common.CharacterControllerComponent CharacterControllerC => GetComponent<Assets._Project.Develop.Runtime.Gameplay.Common.CharacterControllerComponent>();
|
||||
|
||||
public UnityEngine.CharacterController CharacterController => CharacterControllerC.Value;
|
||||
|
||||
public bool TryGetCharacterController(out UnityEngine.CharacterController value)
|
||||
{
|
||||
bool result = TryGetComponent(out Assets._Project.Develop.Runtime.Gameplay.Common.CharacterControllerComponent component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(UnityEngine.CharacterController);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddCharacterController(UnityEngine.CharacterController value)
|
||||
{
|
||||
return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.CharacterControllerComponent() {Value = value});
|
||||
}
|
||||
|
||||
public Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent NavMeshAgentC => GetComponent<Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent>();
|
||||
|
||||
public UnityEngine.AI.NavMeshAgent NavMeshAgent => NavMeshAgentC.Value;
|
||||
|
||||
public bool TryGetNavMeshAgent(out UnityEngine.AI.NavMeshAgent value)
|
||||
{
|
||||
bool result = TryGetComponent(out Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(UnityEngine.AI.NavMeshAgent);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddNavMeshAgent(UnityEngine.AI.NavMeshAgent value)
|
||||
{
|
||||
return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveDirection MoveDirectionC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveDirection>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> MoveDirection => MoveDirectionC.Value;
|
||||
|
||||
public bool TryGetMoveDirection(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveDirection component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddMoveDirection()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveDirection() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddMoveDirection(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveDirection() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed MoveSpeedC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> MoveSpeed => MoveSpeedC.Value;
|
||||
|
||||
public bool TryGetMoveSpeed(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddMoveSpeed()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddMoveSpeed(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.MoveSpeed() {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;
|
||||
|
||||
public bool TryGetRotateDirection(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotateDirection component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddRotateDirection()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotateDirection() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddRotateDirection(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<UnityEngine.Vector3> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotateDirection() {Value = value});
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed RotationSpeedC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed>();
|
||||
|
||||
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> RotationSpeed => RotationSpeedC.Value;
|
||||
|
||||
public bool TryGetRotationSpeed(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddRotationSpeed()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddRotationSpeed(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.RotationSpeed() {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;
|
||||
|
||||
public bool TryGetJumpForce(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.JumpForce component);
|
||||
if(result)
|
||||
value = component.Value;
|
||||
else
|
||||
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
|
||||
return result;
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddJumpForce()
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.JumpForce() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
|
||||
}
|
||||
|
||||
public _Project.Develop.Runtime.Entities.Entity AddJumpForce(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
|
||||
{
|
||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.JumpForce() {Value = value});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e923900a2034874cafef87789bb5665
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public interface IEntityComponent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d243cc104e0d40f2959cfce43b78afb3
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4369817573164b8b8612e797f7d47fb9
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public abstract class EntityView : MonoBehaviour
|
||||
{
|
||||
public void Link(Entity entity)
|
||||
{
|
||||
entity.Initialized += OnEntityStartedWork;
|
||||
}
|
||||
|
||||
public virtual void Cleanup(Entity entity)
|
||||
{
|
||||
entity.Initialized -= OnEntityStartedWork;
|
||||
}
|
||||
|
||||
protected abstract void OnEntityStartedWork(Entity entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79a312c3c91a8cd479691cf91a72bcac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public class MonoEntitiesFactory : IInitializable, IDisposable
|
||||
{
|
||||
private readonly ResourcesAssetsLoader _resources;
|
||||
|
||||
private readonly EntitiesLifeContext _entitiesLifeContext;
|
||||
|
||||
private readonly CollidersRegistryService _collidersRegistryService;
|
||||
|
||||
private readonly Dictionary<Entity, MonoEntity> _entityToMono = new();
|
||||
|
||||
public MonoEntitiesFactory(
|
||||
ResourcesAssetsLoader resources,
|
||||
EntitiesLifeContext entitiesLifeContext,
|
||||
CollidersRegistryService collidersRegistryService)
|
||||
{
|
||||
_resources = resources;
|
||||
_entitiesLifeContext = entitiesLifeContext;
|
||||
_collidersRegistryService = collidersRegistryService;
|
||||
}
|
||||
|
||||
public MonoEntity Create(Entity entity, Vector3 position, string path)
|
||||
{
|
||||
MonoEntity prefab = _resources.Load<MonoEntity>(path);
|
||||
MonoEntity viewInstance = Object.Instantiate(prefab, position, Quaternion.identity, null);
|
||||
|
||||
viewInstance.Initialize(_collidersRegistryService);
|
||||
viewInstance.Link(entity);
|
||||
|
||||
_entityToMono.Add(entity, viewInstance);
|
||||
|
||||
return viewInstance;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_entitiesLifeContext.Released += OnEntityReleased;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_entitiesLifeContext.Released -= OnEntityReleased;
|
||||
|
||||
foreach (Entity entity in _entityToMono.Keys)
|
||||
CleanupFor(entity);
|
||||
|
||||
_entityToMono.Clear();
|
||||
}
|
||||
|
||||
private void OnEntityReleased(Entity entity)
|
||||
{
|
||||
CleanupFor(entity);
|
||||
|
||||
_entityToMono.Remove(entity);
|
||||
}
|
||||
|
||||
private void CleanupFor(Entity entity)
|
||||
{
|
||||
MonoEntity monoEntity = _entityToMono[entity];
|
||||
monoEntity.Cleanup(entity);
|
||||
Object.Destroy(monoEntity.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4340f8b4e7105b4ab4cc8aa56dadfd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public class MonoEntity : MonoBehaviour
|
||||
{
|
||||
private CollidersRegistryService _collidersRegistryService;
|
||||
|
||||
private Entity _linkedEntity;
|
||||
|
||||
public Entity LinkedEntity => _linkedEntity;
|
||||
|
||||
public void Initialize(CollidersRegistryService collidersRegistryService)
|
||||
{
|
||||
_collidersRegistryService = collidersRegistryService;
|
||||
}
|
||||
|
||||
public void Link(Entity entity)
|
||||
{
|
||||
_linkedEntity = entity;
|
||||
|
||||
MonoEntityRegistrator[] registrators = GetComponentsInChildren<MonoEntityRegistrator>();
|
||||
|
||||
if (registrators != null)
|
||||
foreach (MonoEntityRegistrator registrator in registrators)
|
||||
registrator.Register(entity);
|
||||
|
||||
EntityView[] views = GetComponentsInChildren<EntityView>();
|
||||
|
||||
if (views != null)
|
||||
foreach (EntityView view in views)
|
||||
view.Link(entity);
|
||||
|
||||
foreach (Collider collider in GetComponentsInChildren<Collider>())
|
||||
_collidersRegistryService.Register(collider, entity);
|
||||
}
|
||||
|
||||
public void Cleanup(Entity entity)
|
||||
{
|
||||
EntityView[] views = GetComponentsInChildren<EntityView>();
|
||||
|
||||
if (views != null)
|
||||
foreach (EntityView view in views)
|
||||
view.Cleanup(entity);
|
||||
|
||||
foreach (Collider collider in GetComponentsInChildren<Collider>())
|
||||
_collidersRegistryService.Unregister(collider);
|
||||
|
||||
_linkedEntity = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fa38a390e3026e4da73b8535ef0c601
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public abstract class MonoEntityRegistrator : MonoBehaviour
|
||||
{
|
||||
public abstract void Register(Entity entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 939999464fd1f194ca5503fc751733d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96088c9d645e452fbcaf26ca7c50a420
|
||||
timeCreated: 1771425427
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public interface IDisposableSystem : IEntitySystem
|
||||
{
|
||||
void OnDispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b59a3191c6d2c654ba8ae385682c038d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public interface IEntitySystem
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d21a2dc9a95626648b96535cd779fd3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public interface IInitializableSystem: IEntitySystem
|
||||
{
|
||||
void OnInit(Entity entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dbd75b82765bbd48affc4dcb6075b7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace _Project.Develop.Runtime.Entities
|
||||
{
|
||||
public interface IUpdatableSystem : IEntitySystem
|
||||
{
|
||||
void OnUpdate(float deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f59af20aa1d2414b9d996039654d260
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 527131188a494fb8aa36b03631dfb201
|
||||
timeCreated: 1770306345
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4400c1c289f4486836ea29e45c9f9da
|
||||
timeCreated: 1771435325
|
||||
@@ -0,0 +1,29 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class MoveDirectionByInputSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private readonly IPlayerInputService _playerInput;
|
||||
|
||||
private ReactiveVariable<Vector3> _moveDirection;
|
||||
|
||||
public MoveDirectionByInputSystem(IPlayerInputService playerInput)
|
||||
{
|
||||
_playerInput = playerInput;
|
||||
}
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveDirection = entity.MoveDirection;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_moveDirection.Value = new Vector3(_playerInput.Move.x, 0, _playerInput.Move.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ead925d5e3184e6882ddb0c3bf60749a
|
||||
timeCreated: 1771432720
|
||||
@@ -0,0 +1,29 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class RotateDirectionByInputSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private readonly IPlayerInputService _playerInput;
|
||||
|
||||
private ReactiveVariable<Vector3> _rotateDirection;
|
||||
|
||||
public RotateDirectionByInputSystem(IPlayerInputService playerInput)
|
||||
{
|
||||
_playerInput = playerInput;
|
||||
}
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_rotateDirection = entity.RotateDirection;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_rotateDirection.Value = new Vector3(_playerInput.Move.x, 0, _playerInput.Move.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8cefa96e10a40cfa0c17a4fc93112cf
|
||||
timeCreated: 1771432904
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 132a224c65af417fa7d0ff6c47dc9e21
|
||||
timeCreated: 1771427534
|
||||
@@ -0,0 +1,14 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
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 RotateDirection : IEntityComponent { public ReactiveVariable<Vector3> Value; }
|
||||
public class RotationSpeed : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
|
||||
public class JumpForce : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbe915c5b653410585247c01d9590343
|
||||
timeCreated: 1771427563
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5a20169d346473281e2c2fe29323264
|
||||
timeCreated: 1771433138
|
||||
@@ -0,0 +1,31 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class AgentMovementSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private ReactiveVariable<float> _moveSpeed;
|
||||
private NavMeshAgent _agent;
|
||||
|
||||
private Vector3 _position;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveSpeed = entity.MoveSpeed;
|
||||
_agent = entity.NavMeshAgent;
|
||||
// _position получить позицию
|
||||
|
||||
_agent.acceleration = 999;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_agent.speed = _moveSpeed.Value;
|
||||
|
||||
// _agent.SetDestination(_position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da364e91e1ad4ac8911a602290e65656
|
||||
timeCreated: 1771435874
|
||||
@@ -0,0 +1,27 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class CharacterControllerMovementSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private ReactiveVariable<Vector3> _moveDirection;
|
||||
private ReactiveVariable<float> _moveSpeed;
|
||||
private CharacterController _controller;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveDirection = entity.MoveDirection;
|
||||
_moveSpeed = entity.MoveSpeed;
|
||||
_controller = entity.CharacterController;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
Vector3 velocity = _moveDirection.Value.normalized * _moveSpeed.Value;
|
||||
|
||||
_controller.Move(velocity * deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f947fab22c9b447aaca17e5b9118bbfc
|
||||
timeCreated: 1771434334
|
||||
@@ -0,0 +1,23 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class RigidbodyJumpSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private ReactiveVariable<float> _jumpForce;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_jumpForce = entity.JumpForce;
|
||||
_rigidbody = entity.Rigidbody;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_rigidbody.AddForce(Vector3.up * _jumpForce.Value, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b7c856150e8421080f58737e14efef4
|
||||
timeCreated: 1771435167
|
||||
@@ -0,0 +1,27 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class RigidbodyMovementSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private ReactiveVariable<Vector3> _moveDirection;
|
||||
private ReactiveVariable<float> _moveSpeed;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_moveDirection = entity.MoveDirection;
|
||||
_moveSpeed = entity.MoveSpeed;
|
||||
_rigidbody = entity.Rigidbody;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
Vector3 velocity = _moveDirection.Value.normalized * _moveSpeed.Value;
|
||||
|
||||
_rigidbody.velocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47ee3c1077054ccda0eac26a6ba5c4ff
|
||||
timeCreated: 1771427601
|
||||
@@ -0,0 +1,33 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class RigidbodyRotationSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private ReactiveVariable<float> _speed;
|
||||
private ReactiveVariable<Vector3> _direction;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_rigidbody = entity.Rigidbody;
|
||||
_speed = entity.RotationSpeed;
|
||||
_direction = entity.RotateDirection;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_direction.Value == Vector3.zero)
|
||||
return;
|
||||
|
||||
Quaternion lookRotation = Quaternion.LookRotation(_direction.Value.normalized);
|
||||
float step = _speed.Value * deltaTime;
|
||||
Quaternion rotation = Quaternion.RotateTowards(_rigidbody.rotation, lookRotation, step);
|
||||
|
||||
_rigidbody.MoveRotation(rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a22ef6d1d9154a0980488560316560f4
|
||||
timeCreated: 1771431944
|
||||
@@ -0,0 +1,33 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
{
|
||||
public class TransformRotationSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private ReactiveVariable<Vector3> _direction;
|
||||
private ReactiveVariable<float> _speed;
|
||||
private Transform _transform;
|
||||
|
||||
private const float DeadZone = 0.1f;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_direction = entity.RotateDirection;
|
||||
_speed = entity.RotationSpeed;
|
||||
_transform = entity.Transform;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_direction.Value.magnitude < DeadZone)
|
||||
return;
|
||||
|
||||
Quaternion lookRotation = Quaternion.LookRotation(_direction.Value);
|
||||
float step = _speed.Value * deltaTime;
|
||||
|
||||
_transform.rotation = Quaternion.RotateTowards(_transform.rotation, lookRotation, step);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a739c8f6f33f4758963ba69b71c36209
|
||||
timeCreated: 1771436669
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaaa738cd49b432428512a7202561086
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using Assets._Project.Develop.Runtime.Infrastructure;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features;
|
||||
using _Project.Develop.Runtime.Utilities.InputManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
{
|
||||
public class GameplayBootstrap : SceneBootstrap
|
||||
{
|
||||
[SerializeField] private TestGameplay _testGameplay;
|
||||
|
||||
private DIContainer _container;
|
||||
private EntitiesLifeContext _entitiesLifeContext;
|
||||
private GameplayInputArgs _gameplayArgs;
|
||||
|
||||
private IPlayerInputService _playerInput;
|
||||
|
||||
public override void ProcessRegistrations(DIContainer container, IInputSceneArgs sceneArgs = null)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
if (sceneArgs is not GameplayInputArgs gameplayInputArgs)
|
||||
throw new ArgumentException($"{nameof(sceneArgs)} is not match with {typeof(GameplayInputArgs)} type");
|
||||
|
||||
GameplayContextRegistrations.Process(_container);
|
||||
_gameplayArgs = gameplayInputArgs;
|
||||
}
|
||||
|
||||
public override IEnumerator Initialize()
|
||||
{
|
||||
_entitiesLifeContext = _container.Resolve<EntitiesLifeContext>();
|
||||
|
||||
_testGameplay.Initialize(_container);
|
||||
yield break;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
_testGameplay.Run();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_entitiesLifeContext?.Update(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efb8e9c18c625dd409580386ad527885
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.UI;
|
||||
using _Project.Develop.Runtime.UI.Core;
|
||||
using _Project.Develop.Runtime.UI.Screens.Gameplay;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
{
|
||||
public class GameplayContextRegistrations
|
||||
{
|
||||
public static void Process(DIContainer container)
|
||||
{
|
||||
// container.RegisterAsSingle(CreateGameplayUIRoot).NonLazy();
|
||||
// container.RegisterAsSingle(CreateGameplayScreenPresenter).NonLazy();
|
||||
// container.RegisterAsSingle(CreateGameplayPresentersFactory);
|
||||
// container.RegisterAsSingle(CreateGameplayPopupService);
|
||||
|
||||
container.RegisterAsSingle(CreateEntitiesFactory);
|
||||
container.RegisterAsSingle(CreateEntitiesLifeContext);
|
||||
container.RegisterAsSingle(CreateCollidersRegistryService);
|
||||
container.RegisterAsSingle(CreateMonoEntitiesFactory).NonLazy();
|
||||
}
|
||||
|
||||
private static EntitiesLifeContext CreateEntitiesLifeContext(DIContainer c) => new();
|
||||
|
||||
private static EntitiesFactory CreateEntitiesFactory(DIContainer c) => new(c);
|
||||
|
||||
private static GameplayPresentersFactory CreateGameplayPresentersFactory(DIContainer c) => new(c);
|
||||
|
||||
private static CollidersRegistryService CreateCollidersRegistryService(DIContainer c) => new();
|
||||
|
||||
private static GameplayPopupService CreateGameplayPopupService(DIContainer c)
|
||||
{
|
||||
return new GameplayPopupService(
|
||||
c.Resolve<ViewsFactory>(),
|
||||
c.Resolve<ProjectPresentersFactory>(),
|
||||
c.Resolve<GameplayUIRoot>(),
|
||||
c.Resolve<GameplayPresentersFactory>());
|
||||
}
|
||||
|
||||
private static GameplayUIRoot CreateGameplayUIRoot(DIContainer c)
|
||||
{
|
||||
ResourcesAssetsLoader loader = c.Resolve<ResourcesAssetsLoader>();
|
||||
GameplayUIRoot uiRootPrefab = loader.Load<GameplayUIRoot>(PathToResources.UI.Screens.Gameplay);
|
||||
|
||||
return Object.Instantiate(uiRootPrefab);
|
||||
}
|
||||
|
||||
private static GameplayScreenPresenter CreateGameplayScreenPresenter(DIContainer c)
|
||||
{
|
||||
GameplayUIRoot uiRoot = c.Resolve<GameplayUIRoot>();
|
||||
GameplayScreenView view = c.Resolve<ViewsFactory>().Create<GameplayScreenView>(uiRoot.HUDLayer);
|
||||
|
||||
return c.Resolve<GameplayPresentersFactory>().CreateGameplayScreenPresenter(view);
|
||||
}
|
||||
|
||||
private static MonoEntitiesFactory CreateMonoEntitiesFactory(DIContainer c)
|
||||
{
|
||||
return new MonoEntitiesFactory(
|
||||
c.Resolve<ResourcesAssetsLoader>(),
|
||||
c.Resolve<EntitiesLifeContext>(),
|
||||
c.Resolve<CollidersRegistryService>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d5d417999b691947ad10beefd0c816c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Gameplay.Infrastructure
|
||||
{
|
||||
public class GameplayInputArgs : IInputSceneArgs
|
||||
{
|
||||
public int LevelNumber { get; }
|
||||
|
||||
public GameplayInputArgs(int levelNumber)
|
||||
{
|
||||
LevelNumber = levelNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c8e145a7052dda4ba1d15ee516320f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.InputManagement;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features
|
||||
{
|
||||
public class TestGameplay : MonoBehaviour
|
||||
{
|
||||
private DIContainer _container;
|
||||
private EntitiesFactory _entitiesFactory;
|
||||
|
||||
private Entity _entity;
|
||||
|
||||
private bool _isRunning;
|
||||
|
||||
public void Initialize(DIContainer container)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
_entitiesFactory = _container.Resolve<EntitiesFactory>();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_entity = _entitiesFactory.CreateTestEntity(Vector3.zero);
|
||||
|
||||
_isRunning = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isRunning == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8be3a7a8111473cbe01d1fabc512e42
|
||||
timeCreated: 1771427485
|
||||
8
Assets/_Project/Develop/Runtime/Logic/Meta.meta
Normal file
8
Assets/_Project/Develop/Runtime/Logic/Meta.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c30183dcf08b5c4b9620b2fd30ec54a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/_Project/Develop/Runtime/Logic/Meta/Features.meta
Normal file
3
Assets/_Project/Develop/Runtime/Logic/Meta/Features.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1a85f8109aa464592f37815723aee63
|
||||
timeCreated: 1770306353
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44bb00937a784327bfbe6de590646c85
|
||||
timeCreated: 1770822778
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace _Project.Develop.Runtime.Logic.Meta.Features.Wallet
|
||||
{
|
||||
public enum CurrencyTypes
|
||||
{
|
||||
Gold,
|
||||
Diamond
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1822fc8809b486dbb88227c36bec03f
|
||||
timeCreated: 1769721690
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.DataManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Features.Wallet
|
||||
{
|
||||
public class WalletService : IDataReader<PlayerData>, IDataWriter<PlayerData>
|
||||
{
|
||||
private readonly Dictionary<CurrencyTypes, ReactiveVariable<int>> _currencies;
|
||||
|
||||
public WalletService(
|
||||
Dictionary<CurrencyTypes, ReactiveVariable<int>> currencies,
|
||||
PlayerDataProvider playerDataProvider)
|
||||
{
|
||||
_currencies = new Dictionary<CurrencyTypes, ReactiveVariable<int>>(currencies);
|
||||
playerDataProvider.RegisterWriter(this);
|
||||
playerDataProvider.RegisterReader(this);
|
||||
}
|
||||
|
||||
public List<CurrencyTypes> AvailableCurrencies => _currencies.Keys.ToList();
|
||||
|
||||
public IReadOnlyVariable<int> GetCurrency(CurrencyTypes type) => _currencies[type];
|
||||
|
||||
public bool Enough(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
return _currencies[type].Value >= amount;
|
||||
}
|
||||
|
||||
public void Add(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
_currencies[type].Value += amount;
|
||||
}
|
||||
|
||||
public void Spend(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (Enough(type, amount) == false)
|
||||
throw new InvalidOperationException("Not enough: " + type.ToString());
|
||||
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
_currencies[type].Value -= amount;
|
||||
}
|
||||
|
||||
public void ReadFrom(PlayerData data)
|
||||
{
|
||||
foreach (KeyValuePair<CurrencyTypes, int> currency in data.WalletData)
|
||||
{
|
||||
if (_currencies.ContainsKey(currency.Key))
|
||||
_currencies[currency.Key].Value = currency.Value;
|
||||
else
|
||||
_currencies.Add(currency.Key, new ReactiveVariable<int>(currency.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteTo(PlayerData data)
|
||||
{
|
||||
foreach (KeyValuePair<CurrencyTypes, ReactiveVariable<int>> currency in _currencies)
|
||||
{
|
||||
if (data.WalletData.ContainsKey(currency.Key))
|
||||
data.WalletData[currency.Key] = currency.Value.Value;
|
||||
else
|
||||
data.WalletData.Add(currency.Key, currency.Value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bac6967622d94d37886219039cead5ed
|
||||
timeCreated: 1769721675
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5af390c397c13478837cc2cccb7cdb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using Assets._Project.Develop.Runtime.Infrastructure;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using System.Collections;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Infrastructure
|
||||
{
|
||||
public class MainMenuBootstrap : SceneBootstrap
|
||||
{
|
||||
private DIContainer _container;
|
||||
|
||||
public override void ProcessRegistrations(DIContainer container, IInputSceneArgs sceneArgs = null)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
MainMenuContextRegistrations.Process(_container);
|
||||
}
|
||||
|
||||
public override IEnumerator Initialize()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{ }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c18e030accfe8446bfca4a0bc7ebbb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using _Project.Develop.Runtime.UI;
|
||||
using _Project.Develop.Runtime.UI.Core;
|
||||
using _Project.Develop.Runtime.UI.Screens.MainMenu;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Infrastructure
|
||||
{
|
||||
public class MainMenuContextRegistrations
|
||||
{
|
||||
public static void Process(DIContainer container)
|
||||
{
|
||||
container.RegisterAsSingle(CreateMainMenuUIRoot).NonLazy();
|
||||
container.RegisterAsSingle(CreateMainMenuPresentersFactory);
|
||||
container.RegisterAsSingle(CreateMainMenuScreenPresenter).NonLazy();
|
||||
container.RegisterAsSingle(CreateMainMenuPopupService);
|
||||
}
|
||||
|
||||
private static MainMenuPresentersFactory CreateMainMenuPresentersFactory(DIContainer c) => new(c);
|
||||
|
||||
private static MainMenuPopupService CreateMainMenuPopupService(DIContainer c)
|
||||
{
|
||||
return new MainMenuPopupService(
|
||||
c.Resolve<ViewsFactory>(),
|
||||
c.Resolve<ProjectPresentersFactory>(),
|
||||
c.Resolve<MainMenuUIRoot>());
|
||||
}
|
||||
|
||||
private static MainMenuUIRoot CreateMainMenuUIRoot(DIContainer c)
|
||||
{
|
||||
ResourcesAssetsLoader loader = c.Resolve<ResourcesAssetsLoader>();
|
||||
MainMenuUIRoot uiRootPrefab = loader.Load<MainMenuUIRoot>(PathToResources.UI.Screens.MainMenu);
|
||||
|
||||
return Object.Instantiate(uiRootPrefab);
|
||||
}
|
||||
|
||||
private static MainMenuScreenPresenter CreateMainMenuScreenPresenter(DIContainer c)
|
||||
{
|
||||
MainMenuUIRoot uiRoot = c.Resolve<MainMenuUIRoot>();
|
||||
MainMenuScreenView view = c.Resolve<ViewsFactory>().Create<MainMenuScreenView>(uiRoot.HUDLayer);
|
||||
MainMenuScreenPresenter presenter = c.Resolve<MainMenuPresentersFactory>().CreateMainMenuScreen(view);
|
||||
|
||||
return presenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a75665c6d4b5574dbfa1ffa841b7348
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user