You've already forked Darklings-FightingGame
mirror of
https://github.com/izzy2lost/Darklings-FightingGame.git
synced 2026-03-10 11:35:19 -07:00
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class BaseMenu : MonoBehaviour
|
|
{
|
|
[SerializeField] protected Selectable _startingOption = default;
|
|
public Selectable PreviousSelectable { get; private set; }
|
|
|
|
public void OpenMenuHideCurrent(BaseMenu menu)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
gameObject.SetActive(false);
|
|
menu.Show();
|
|
}
|
|
|
|
public void OpenMenu(BaseMenu menu)
|
|
{
|
|
menu.gameObject.SetActive(true);
|
|
}
|
|
|
|
public virtual void Show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
StartCoroutine(ActivateCoroutine());
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
StartCoroutine(ActivateCoroutine());
|
|
}
|
|
|
|
IEnumerator ActivateCoroutine()
|
|
{
|
|
GameObject currentSelected = EventSystem.current.currentSelectedGameObject;
|
|
if (currentSelected != null)
|
|
PreviousSelectable = EventSystem.current.currentSelectedGameObject.GetComponent<Selectable>();
|
|
yield return null;
|
|
if (_startingOption != null)
|
|
_startingOption.Select();
|
|
}
|
|
}
|