75 lines
1.6 KiB
C#
75 lines
1.6 KiB
C#
using UnityEngine;
|
|
using VContainer;
|
|
|
|
public class PlatformManager : MonoBehaviour,IPlatformManager
|
|
{
|
|
[Inject] private IPool pool;
|
|
[Inject] private IInputReader inputReader;
|
|
private float yPos = 0f;
|
|
|
|
public float rotSpeed = 5f;
|
|
|
|
private float targetRotAmount;
|
|
private float smoothRotAmount;
|
|
|
|
private void Start()
|
|
{
|
|
ShowPlatforms();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
inputReader.OnDragValueChanged += HandleDrag;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
inputReader.OnDragValueChanged -= HandleDrag;
|
|
}
|
|
private void LateUpdate()
|
|
{
|
|
#if UNITY_EDITOR || UNITY_STANDALONE
|
|
if (!inputReader.isMouseButtonPressed) return;
|
|
#endif
|
|
|
|
smoothRotAmount = Mathf.MoveTowards(
|
|
smoothRotAmount,
|
|
targetRotAmount,
|
|
Time.deltaTime * 80f
|
|
);
|
|
|
|
transform.Rotate(Vector3.up * smoothRotAmount, Space.World);
|
|
|
|
}
|
|
void ShowPlatforms()
|
|
{
|
|
foreach (var platform in pool.All)
|
|
{
|
|
platform.gameObject.SetActive(true);
|
|
platform.transform.position = new Vector3(0, yPos, 0);
|
|
yPos--;
|
|
}
|
|
}
|
|
|
|
public void BuildNewPlatform()
|
|
{
|
|
Platform platform = pool.GetFromPool();
|
|
platform.transform.position = new Vector3(0, yPos, 0);
|
|
yPos--;
|
|
}
|
|
|
|
private void HandleDrag(Vector2 drag)
|
|
{
|
|
float raw = drag.x / Screen.width;
|
|
|
|
targetRotAmount = -raw * rotSpeed * 180f;
|
|
|
|
targetRotAmount = Mathf.Clamp(targetRotAmount, -10f,10f);
|
|
}
|
|
}
|
|
|
|
public interface IPlatformManager
|
|
{
|
|
void BuildNewPlatform();
|
|
}
|