Import 2D Level
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Platformer.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple controller for switching between UI panels.
|
||||
/// </summary>
|
||||
public class MainUIController : MonoBehaviour
|
||||
{
|
||||
public GameObject[] panels;
|
||||
|
||||
public void SetActivePanel(int index)
|
||||
{
|
||||
for (var i = 0; i < panels.Length; i++)
|
||||
{
|
||||
var active = i == index;
|
||||
var g = panels[i];
|
||||
if (g.activeSelf != active) g.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
SetActivePanel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Platformer.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// The MetaGameController is responsible for switching control between the high level
|
||||
/// contexts of the application, eg the Main Menu and Gameplay systems.
|
||||
/// </summary>
|
||||
public class MetaGameController : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// The main UI object which used for the menu.
|
||||
/// </summary>
|
||||
public MainUIController mainMenu;
|
||||
|
||||
/// <summary>
|
||||
/// A list of canvas objects which are used during gameplay (when the main ui is turned off)
|
||||
/// </summary>
|
||||
public Canvas[] gamePlayCanvasii;
|
||||
|
||||
/// <summary>
|
||||
/// The game controller.
|
||||
/// </summary>
|
||||
public GameController gameController;
|
||||
|
||||
bool showMainCanvas = false;
|
||||
private InputAction m_MenuAction;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_ToggleMainMenu(showMainCanvas);
|
||||
m_MenuAction = InputSystem.actions.FindAction("Player/Menu");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn the main menu on or off.
|
||||
/// </summary>
|
||||
/// <param name="show"></param>
|
||||
public void ToggleMainMenu(bool show)
|
||||
{
|
||||
if (this.showMainCanvas != show)
|
||||
{
|
||||
_ToggleMainMenu(show);
|
||||
}
|
||||
}
|
||||
|
||||
void _ToggleMainMenu(bool show)
|
||||
{
|
||||
if (show)
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
mainMenu.gameObject.SetActive(true);
|
||||
foreach (var i in gamePlayCanvasii) i.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
mainMenu.gameObject.SetActive(false);
|
||||
foreach (var i in gamePlayCanvasii) i.gameObject.SetActive(true);
|
||||
}
|
||||
this.showMainCanvas = show;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (m_MenuAction.WasPressedThisFrame())
|
||||
{
|
||||
ToggleMainMenu(show: !showMainCanvas);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user