2022-12-14 18:33:44 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
|
|
public class BaseMenu : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] protected Selectable _startingOption = default;
|
2023-10-09 12:39:56 +03:00
|
|
|
|
public Selectable PreviousSelectable { get; private set; }
|
2022-12-14 18:33:44 +02:00
|
|
|
|
|
|
|
|
|
|
public void OpenMenuHideCurrent(BaseMenu menu)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
menu.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OpenMenu(BaseMenu menu)
|
|
|
|
|
|
{
|
|
|
|
|
|
menu.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-30 14:07:58 +02:00
|
|
|
|
public virtual void Show()
|
2022-12-14 18:33:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
gameObject.SetActive(true);
|
2023-10-10 16:16:19 +03:00
|
|
|
|
if (gameObject.activeSelf)
|
|
|
|
|
|
StartCoroutine(ActivateCoroutine());
|
2022-12-14 18:33:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Hide()
|
|
|
|
|
|
{
|
2023-07-19 17:10:21 +03:00
|
|
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
2022-12-14 18:33:44 +02:00
|
|
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-09 12:39:56 +03:00
|
|
|
|
protected virtual void OnEnable()
|
2022-12-14 18:33:44 +02:00
|
|
|
|
{
|
2023-10-10 17:32:12 +03:00
|
|
|
|
if (gameObject.activeSelf)
|
|
|
|
|
|
StartCoroutine(ActivateCoroutine());
|
2022-12-14 18:33:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-03 13:45:29 +02:00
|
|
|
|
protected IEnumerator ActivateCoroutine()
|
2022-12-14 18:33:44 +02:00
|
|
|
|
{
|
2023-10-09 12:39:56 +03:00
|
|
|
|
GameObject currentSelected = EventSystem.current.currentSelectedGameObject;
|
|
|
|
|
|
if (currentSelected != null)
|
|
|
|
|
|
PreviousSelectable = EventSystem.current.currentSelectedGameObject.GetComponent<Selectable>();
|
2022-12-14 18:33:44 +02:00
|
|
|
|
yield return null;
|
|
|
|
|
|
if (_startingOption != null)
|
|
|
|
|
|
_startingOption.Select();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|