65 lines
1.3 KiB
C#
65 lines
1.3 KiB
C#
using Darkmatter.Core;
|
|
using UnityEngine;
|
|
using VContainer;
|
|
|
|
public class PlatformManager : MonoBehaviour,IPlatformManager
|
|
{
|
|
[Inject] private IPool<Platform> pool;
|
|
[Inject] private IInputReader inputReader;
|
|
|
|
private float yPos = 0f;
|
|
|
|
[SerializeField] private float inputScale = 360f;
|
|
float rotAmount = 0;
|
|
|
|
|
|
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
|
|
|
|
// Apply rotation
|
|
transform.Rotate(Vector3.up * rotAmount, Space.World);
|
|
}
|
|
|
|
private void HandleDrag(Vector2 drag)
|
|
{
|
|
rotAmount = -drag.x/Screen.width * inputScale;
|
|
}
|
|
|
|
private void ShowPlatforms()
|
|
{
|
|
foreach (Platform 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--;
|
|
}
|
|
}
|
|
|
|
|