Initial commit
This commit is contained in:
63
Assets/Scripts/PlatformScripts/PlatformManager.cs
Normal file
63
Assets/Scripts/PlatformScripts/PlatformManager.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user