Files

52 lines
1.8 KiB
C#
Raw Permalink Normal View History

2022-07-14 16:19:51 +03:00
using System.Collections;
2022-03-12 18:06:55 +01:00
using UnityEngine;
2023-10-04 15:28:25 +03:00
using UnityEngine.EventSystems;
using UnityEngine.UI;
2022-03-12 18:06:55 +01:00
public class PatchNotesMenu : BaseMenu
{
2022-11-21 18:08:37 +02:00
[SerializeField] private InputManager _inputManager = default;
[SerializeField] private RectTransform _scrollView = default;
[SerializeField] private RectTransform _patchNotes = default;
2023-09-20 22:07:55 +03:00
[SerializeField] private Vector2 _boundaries = default;
2022-11-21 18:08:37 +02:00
private readonly int _scrollSpeed = 350;
2022-03-12 18:06:55 +01:00
2023-09-20 22:07:55 +03:00
void Update() => Scroll(_inputManager.NavigationInput.y * 4);
2023-08-29 17:42:32 +03:00
public void Scroll(float navigationInput)
2022-11-21 18:08:37 +02:00
{
2023-08-29 17:42:32 +03:00
float movement = navigationInput * Time.deltaTime * _scrollSpeed * -1;
2023-09-20 22:07:55 +03:00
if (movement < 0 && _patchNotes.anchoredPosition.y > _boundaries.x || movement > 0 && _patchNotes.anchoredPosition.y <= _boundaries.y)
2022-11-21 18:08:37 +02:00
{
2023-09-20 22:07:55 +03:00
_patchNotes.anchoredPosition += new Vector2(0.0f, movement);
if (_patchNotes.anchoredPosition.y < _boundaries.x)
_patchNotes.anchoredPosition = new Vector2(0.0f, _boundaries.x);
else if (_patchNotes.anchoredPosition.y > _boundaries.y)
_patchNotes.anchoredPosition = new Vector2(0.0f, _boundaries.y);
2022-11-21 18:08:37 +02:00
}
}
2022-04-19 14:29:23 +02:00
2023-10-09 12:39:56 +03:00
protected override void OnEnable()
2023-10-04 15:28:25 +03:00
{
_scrollView.anchoredPosition = Vector2.zero;
2023-10-09 12:39:56 +03:00
base.OnEnable();
2023-10-04 15:28:25 +03:00
EventSystem.current.SetSelectedGameObject(null);
}
2022-07-14 16:19:51 +03:00
2023-10-04 15:28:25 +03:00
void OnDisable()
{
2023-12-04 09:55:55 +02:00
if (PreviousSelectable != null)
PreviousSelectable.Select();
2023-10-04 15:28:25 +03:00
_inputManager.SetPrompts(_inputManager.PreviousPrompts);
}
2023-08-29 17:42:32 +03:00
2023-08-28 02:38:39 +03:00
void Start() => StartCoroutine(SetUpPatchNotesCoroutine());
2022-07-14 16:19:51 +03:00
2022-11-21 18:08:37 +02:00
IEnumerator SetUpPatchNotesCoroutine()
{
yield return null;
2023-09-20 22:07:55 +03:00
_boundaries = new Vector2(-_patchNotes.rect.height, _scrollView.rect.height);
_patchNotes.anchoredPosition = new Vector2(0.0f, -_patchNotes.rect.height);
2022-11-21 18:08:37 +02:00
}
2022-03-12 18:06:55 +01:00
}