97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Reflection;
|
|
using log4net;
|
|
using Managers;
|
|
using PrimeTween;
|
|
using SlimUI.ModernMenu;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.SceneManagement;
|
|
public class MatchEndMenu : MonoBehaviour
|
|
{
|
|
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
private Canvas Canvas;
|
|
public GameObject Camera;
|
|
public GameObject UIEventSystem;
|
|
public GameObject MenuButtons;
|
|
public GameObject FocusButtonRematch;
|
|
|
|
private EventSystem eventSystem;
|
|
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
Canvas = gameObject.GetComponent<Canvas>();
|
|
Canvas.enabled = false;
|
|
MenuButtons.SetActive(false);
|
|
eventSystem = UIEventSystem.GetComponent<EventSystem>();
|
|
UIEventSystem.SetActive(false);
|
|
}
|
|
|
|
public void Show(Transform transform)
|
|
{
|
|
gameObject.transform.SetPositionAndRotation(
|
|
transform.position,
|
|
transform.rotation);
|
|
Canvas.enabled = true;
|
|
|
|
Vector3 centeredPosition = Camera.transform.position;
|
|
Quaternion centeredRotation = Camera.transform.rotation;
|
|
|
|
Camera.transform.SetPositionAndRotation(
|
|
MatchManager.G.MatchCamera.transform.position,
|
|
MatchManager.G.MatchCamera.transform.rotation);
|
|
|
|
Camera.SetActive(true);
|
|
|
|
Sequence.Create()
|
|
.Group(Tween.Position(Camera.transform, centeredPosition, 1f))
|
|
.Group(Tween.Rotation(Camera.transform, centeredRotation, 1f));
|
|
|
|
|
|
UIEventSystem.SetActive(true);
|
|
MenuButtons.SetActive(true);
|
|
eventSystem.SetSelectedGameObject(FocusButtonRematch, null);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
Canvas.enabled = false;
|
|
Camera.SetActive(false);
|
|
UIEventSystem.SetActive(false);
|
|
}
|
|
|
|
public void OnRematch()
|
|
{
|
|
MatchManager.G.StartRematch();
|
|
UIManager.G.HUD?.Show();
|
|
Hide();
|
|
}
|
|
|
|
public void OnMainMenu()
|
|
{
|
|
UIManager.G.MatchMusic.FadeOutAudio(0.3f, true);
|
|
StartCoroutine(StartSceneTransition());
|
|
}
|
|
|
|
private IEnumerator StartSceneTransition()
|
|
{
|
|
Canvas.enabled = false;
|
|
SceneManager.LoadScene((int)SceneEnum.MainMenu, LoadSceneMode.Additive);
|
|
yield return new WaitForSeconds(0.2f);
|
|
GameObject menu = GameObject.Find("Main Menu Camera");
|
|
if (menu != null && menu.TryGetComponent(out SlimUIMainMenu menuScript))
|
|
{
|
|
UIManager.G.HideHUD();
|
|
menuScript.MenuTransition(Camera.GetComponent<Camera>().transform,
|
|
GameManager.G.CurrentScene);
|
|
}
|
|
else
|
|
{
|
|
Log.Error("Can't transition back to main menu. Menu camera or script not found.");
|
|
}
|
|
}
|
|
|
|
|
|
}
|