64 lines
1.3 KiB
C#
64 lines
1.3 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 void Start()
|
|
{
|
|
ShowPlatforms();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
inputReader.OnDragValueChanged += HandleDrag;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
inputReader.OnDragValueChanged -= HandleDrag;
|
|
}
|
|
|
|
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 rotAmount = -drag.normalized.x * rotSpeed;
|
|
|
|
#if UNITY_EDITOR || UNITY_STANDALONE
|
|
if (!inputReader.isMouseButtonPressed) return;
|
|
transform.Rotate(Vector3.up * rotAmount);
|
|
|
|
#elif UNITY_IOS || UNITY_ANDROID
|
|
transform.Rotate(Vector3.up * rotAmount);
|
|
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|
|
public interface IPlatformManager
|
|
{
|
|
void BuildNewPlatform();
|
|
}
|