feat: add teleport system

This commit is contained in:
Bragin Stepan
2026-02-22 16:34:56 +05:00
parent 366a388036
commit 6a2f3a39d3
12 changed files with 349 additions and 6 deletions

View File

@@ -78,6 +78,183 @@ namespace _Project.Develop.Runtime.Entities
return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent() {Value = value}); return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent() {Value = value});
} }
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget TeleportTargetC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget>();
public UnityEngine.Transform TeleportTarget => TeleportTargetC.Value;
public bool TryGetTeleportTarget(out UnityEngine.Transform value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget component);
if(result)
value = component.Value;
else
value = default(UnityEngine.Transform);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddTeleportTarget(UnityEngine.Transform value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint TeleportToPointC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint>();
public UnityEngine.Transform TeleportToPoint => TeleportToPointC.Value;
public bool TryGetTeleportToPoint(out UnityEngine.Transform value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint component);
if(result)
value = component.Value;
else
value = default(UnityEngine.Transform);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddTeleportToPoint(UnityEngine.Transform value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.CanStartTeleport CanStartTeleportC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.CanStartTeleport>();
public _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition CanStartTeleport => CanStartTeleportC.Value;
public bool TryGetCanStartTeleport(out _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.CanStartTeleport component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddCanStartTeleport(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.CanStartTeleport() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportProcess InTeleportProcessC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportProcess>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> InTeleportProcess => InTeleportProcessC.Value;
public bool TryGetInTeleportProcess(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportProcess 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 AddInTeleportProcess()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportProcess() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean>() });
}
public _Project.Develop.Runtime.Entities.Entity AddInTeleportProcess(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportProcess() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportRequest StartTeleportRequestC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportRequest>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent StartTeleportRequest => StartTeleportRequestC.Value;
public bool TryGetStartTeleportRequest(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportRequest component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddStartTeleportRequest()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportRequest() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddStartTeleportRequest(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportRequest() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportEvent StartTeleportEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent StartTeleportEvent => StartTeleportEventC.Value;
public bool TryGetStartTeleportEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddStartTeleportEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddStartTeleportEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.StartTeleportEvent() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent EndTeleportEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent EndTeleportEvent => EndTeleportEventC.Value;
public bool TryGetEndTeleportEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddEndTeleportEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddEndTeleportEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost EnergyTeleportCostC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> EnergyTeleportCost => EnergyTeleportCostC.Value;
public bool TryGetEnergyTeleportCost(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddEnergyTeleportCost()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32>() });
}
public _Project.Develop.Runtime.Entities.Entity AddEnergyTeleportCost(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent CapsuleColliderC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent>(); public _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent CapsuleColliderC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent>();
public UnityEngine.CapsuleCollider CapsuleCollider => CapsuleColliderC.Value; public UnityEngine.CapsuleCollider CapsuleCollider => CapsuleColliderC.Value;

View File

@@ -21,20 +21,20 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems
{ {
_currentEnergy = entity.CurrentEnergy; _currentEnergy = entity.CurrentEnergy;
_useEnergyRequest = entity.RegenEnergyRequest; _useEnergyRequest = entity.UseEnergyRequest;
_useEnergyEvent = entity.RegenEnergyEvent; _useEnergyEvent = entity.UseEnergyEvent;
_canUse = entity.CanRegenEnergy; _canUse = entity.CanUseEnergy;
_useRequestDispose = _useEnergyRequest.Subscribe(OnRegenRequest); _useRequestDispose = _useEnergyRequest.Subscribe(OnUseRequest);
} }
private void OnRegenRequest(int value) private void OnUseRequest(int value)
{ {
if (value <= 0) if (value <= 0)
throw new ArgumentException($"Energy use value must be positive. Received: {value}", nameof(value)); throw new ArgumentException($"Energy use value must be positive. Received: {value}", nameof(value));
if (_canUse.Evaluate() == false || _currentEnergy.Value < value) if (_canUse.Evaluate() == false)
return; return;
_currentEnergy.Value -= value; _currentEnergy.Value -= value;

View File

@@ -0,0 +1,36 @@
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utils.InputManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
using UnityEngine;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Input
{
public class TeleportByInputSystem : IInitializableSystem, IDisposableSystem
{
private readonly IPlayerInput _playerInput;
private ReactiveEvent _startTeleportRequest;
public TeleportByInputSystem(IPlayerInput playerInput)
{
_playerInput = playerInput;
}
public void OnInit(Entity entity)
{
_startTeleportRequest = entity.StartTeleportRequest;
_playerInput.Jump.Enter += OnTeleportRequest;
}
private void OnTeleportRequest(float value)
{
_startTeleportRequest.Invoke();
}
public void OnDispose()
{
_playerInput.Jump.Enter -= OnTeleportRequest;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 585250d7186e42928f1909e712a63f12
timeCreated: 1771759696

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 13758f03c6ec4963a8b410da943fb2ef
timeCreated: 1771754702

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fa09db11825842cfbe7d717c61c0af1c
timeCreated: 1771754762

View File

@@ -0,0 +1,40 @@
using System;
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
using UnityEngine;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
{
public class ProcessTeleportSystem : IInitializableSystem, IDisposableSystem
{
private Transform _target;
private Transform _toPoint;
private ReactiveEvent _startTeleportEvent;
private ReactiveEvent _endTeleportEvent;
private IDisposable _startTeleportEventDisposable;
public void OnInit(Entity entity)
{
_target = entity.TeleportTarget;
_toPoint = entity.TeleportToPoint;
_startTeleportEvent = entity.StartTeleportEvent;
_endTeleportEvent = entity.EndTeleportEvent;
_startTeleportEventDisposable = _startTeleportEvent.Subscribe(OnStartTeleportProcess);
}
private void OnStartTeleportProcess()
{
_target.position = _toPoint.position;
_endTeleportEvent.Invoke();
}
public void OnDispose()
{
_startTeleportEventDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 10244fce53bb47079bf5d24b96ce2515
timeCreated: 1771758234

View File

@@ -0,0 +1,51 @@
using System;
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utilities.Conditions;
using _Project.Develop.Runtime.Utils.ReactiveManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
{
public class StartTeleportByEnergySystem: IInitializableSystem, IDisposableSystem
{
private ReactiveEvent<int> _useEnergyRequest;
private ReactiveEvent _startTeleportRequest;
private ReactiveEvent _startTeleportEvent;
private ReactiveVariable<bool> _inTeleportProcess;
private ReactiveVariable<int> _teleportCost;
private ICompositeCondition _canStartTeleport;
private IDisposable _teleportRequestDispose;
public void OnInit(Entity entity)
{
_teleportCost = entity.EnergyTeleportCost;
_useEnergyRequest = entity.UseEnergyRequest;
_startTeleportRequest = entity.StartTeleportRequest;
_startTeleportEvent = entity.StartTeleportEvent;
_inTeleportProcess = entity.InTeleportProcess;
_canStartTeleport = entity.CanStartTeleport;
_teleportRequestDispose = _startTeleportRequest.Subscribe(OnTeleportRequest);
}
private void OnTeleportRequest()
{
if (_canStartTeleport.Evaluate())
{
_inTeleportProcess.Value = true;
_useEnergyRequest.Invoke(_teleportCost.Value);
_startTeleportEvent.Invoke();
}
}
public void OnDispose()
{
_teleportRequestDispose.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 94ff3554a2634a4bb835ed4ffd6240a6
timeCreated: 1771754851

View File

@@ -0,0 +1,21 @@
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utilities.Conditions;
using _Project.Develop.Runtime.Utils.ReactiveManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
using UnityEngine;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
{
public class TeleportTarget : IEntityComponent { public Transform Value; }
public class TeleportToPoint : IEntityComponent { public Transform Value; }
public class CanStartTeleport : IEntityComponent { public ICompositeCondition Value; }
public class InTeleportProcess : IEntityComponent { public ReactiveVariable<bool> Value; }
public class StartTeleportRequest : IEntityComponent { public ReactiveEvent Value; }
public class StartTeleportEvent : IEntityComponent { public ReactiveEvent Value; }
public class EndTeleportEvent : IEntityComponent { public ReactiveEvent Value; }
public class EnergyTeleportCost : IEntityComponent { public ReactiveVariable<int> Value; }
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 22478060bdbf4b2b8556c31a7b93a97b
timeCreated: 1771754772