65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using Code.Configs;
|
|
using Code.Gameplay.Orders.Order;
|
|
using Cysharp.Threading.Tasks;
|
|
using Reflex.Attributes;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Gameplay.Orders.Order
|
|
{
|
|
public class OrderBox : MonoBehaviour
|
|
{
|
|
[Inject] private IOrderService _orderService;
|
|
public Rigidbody rigidbody;
|
|
private bool _pickupMode;
|
|
// [SerializeField] private AnimationCurve debugCurve;
|
|
|
|
//DEBUG
|
|
// private void Start()
|
|
// {
|
|
// _capturedPosition = transform.position;
|
|
// _floatingCurve = debugCurve;
|
|
// _curveLength = 1f;
|
|
// }
|
|
// DEBUG
|
|
|
|
private float _activationTime;
|
|
[Inject]
|
|
private void Construct(OrderBoxConfig config)
|
|
{
|
|
_floatingCurve = config.floatingCurve;
|
|
_activationTime = config.activationTime;
|
|
_curveLength = config.curveLength;
|
|
}
|
|
public void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!_pickupMode || !other.CompareTag("Player")) return;
|
|
|
|
_orderService.OrderRecieved();
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public async UniTaskVoid SwitchMode()
|
|
{
|
|
await UniTask.WaitForSeconds(_activationTime);
|
|
_pickupMode = true;
|
|
rigidbody.isKinematic = true;
|
|
_capturedPosition = transform.position;
|
|
}
|
|
|
|
private Vector3 _capturedPosition;
|
|
private float _timeForMoving;
|
|
private AnimationCurve _floatingCurve;
|
|
private float _curveLength;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (!_pickupMode) return;
|
|
_timeForMoving += Time.fixedDeltaTime;
|
|
|
|
if (_timeForMoving > _curveLength) _timeForMoving = 0;
|
|
|
|
transform.position = _capturedPosition + new Vector3(0, _floatingCurve.Evaluate(_timeForMoving), 0);
|
|
}
|
|
}
|
|
} |