remanaged drag input and platform movement
This commit is contained in:
@@ -13728,7 +13728,10 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 393df497de02fce4399040e619446397, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::PlatformManager
|
||||
rotSpeed: 8
|
||||
inputScale: 360
|
||||
maxAngularSpeed: 25
|
||||
acceleration: 150
|
||||
deceleration: 170
|
||||
--- !u!1 &1942266448
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -5,6 +5,7 @@ public interface IInputReader
|
||||
{
|
||||
event Action<Vector2> OnDragValueChanged;
|
||||
bool isMouseButtonPressed { get; }
|
||||
bool isDragging { get; }
|
||||
Vector2 dragInput { get; }
|
||||
|
||||
void LockInput();
|
||||
|
||||
@@ -14,6 +14,8 @@ public class InputReaderSO : ScriptableObject, GameInputAction.IPlayerActions ,
|
||||
OnDragValueChanged?.Invoke(_dragInput);
|
||||
}
|
||||
}
|
||||
public bool isDragging => isMouseButtonPressed && dragInput.sqrMagnitude > 0.001f;
|
||||
|
||||
|
||||
public bool isMouseButtonPressed { get;private set; }
|
||||
private Vector2 _dragInput;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using UnityEngine;
|
||||
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;
|
||||
[SerializeField] private float inputScale = 360f;
|
||||
float rotAmount = 0;
|
||||
|
||||
private float targetRotAmount;
|
||||
private float smoothRotAmount;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -26,22 +26,23 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
{
|
||||
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);
|
||||
|
||||
// Apply rotation
|
||||
transform.Rotate(Vector3.up * rotAmount, Space.World);
|
||||
}
|
||||
void ShowPlatforms()
|
||||
|
||||
private void HandleDrag(Vector2 drag)
|
||||
{
|
||||
rotAmount = -drag.x/Screen.width * inputScale;
|
||||
}
|
||||
|
||||
private void ShowPlatforms()
|
||||
{
|
||||
foreach (var platform in pool.All)
|
||||
{
|
||||
@@ -57,15 +58,6 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user