SanAndreasUnity/Assets/Scripts/UI/MainMenu.cs

104 lines
2.4 KiB
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using System.Collections.Generic;
using UnityEngine;
using SanAndreasUnity.Behaviours;
using UnityEngine.SceneManagement;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.UI
{
public class MainMenu : MonoBehaviour {
public float minButtonHeight = 25f;
public float minButtonWidth = 70f;
public float spaceAtBottom = 15f;
public float spaceBetweenButtons = 5f;
public bool drawBackground = false;
public Color backgroundColor = Color.black;
public bool drawLogo = false;
private static GUILayoutOption[] s_buttonOptions = new GUILayoutOption[0];
public static GUILayoutOption[] ButtonLayoutOptions { get { return s_buttonOptions; } }
2019-07-09 15:22:07 +00:00
static MenuEntry s_rootMenuEntry = new MenuEntry();
2020-05-31 17:07:22 +00:00
void Start ()
{
}
void OnGUI ()
{
if (!GameManager.IsInStartupScene)
return;
// draw main menu gui
// background
if (this.drawBackground)
{
GUIUtils.DrawRect (GUIUtils.ScreenRect, this.backgroundColor);
}
// logo
if (this.drawLogo)
{
if (GameManager.Instance.logoTexture != null)
{
GUI.DrawTexture (GUIUtils.GetCenteredRect (GameManager.Instance.logoTexture.GetSize ()), GameManager.Instance.logoTexture);
}
}
// draw buttons at bottom of screen: Main scene, Demo scene, Options, Change path to GTA, Exit
s_buttonOptions = new GUILayoutOption[]{ GUILayout.MinWidth(minButtonWidth), GUILayout.MinHeight(minButtonHeight) };
GUILayout.BeginArea (new Rect (0f, Screen.height - (minButtonHeight + spaceAtBottom), Screen.width, minButtonHeight + spaceAtBottom));
// GUILayout.Space (5);
// GUILayout.FlexibleSpace ();
GUILayout.BeginHorizontal ();
GUILayout.Space (5);
GUILayout.FlexibleSpace ();
// draw registered menu items
2019-07-09 15:22:07 +00:00
foreach (var item in s_rootMenuEntry.children)
2020-05-31 17:07:22 +00:00
{
2019-07-09 15:22:07 +00:00
if (item.drawAction != null)
item.drawAction();
2020-05-31 17:07:22 +00:00
GUILayout.Space (this.spaceBetweenButtons);
}
if (GUILayout.Button ("Exit", s_buttonOptions))
{
GameManager.ExitApplication ();
}
GUILayout.FlexibleSpace ();
GUILayout.Space (5);
GUILayout.EndHorizontal ();
// add some space below buttons
// GUILayout.Space (spaceAtBottom);
GUILayout.EndArea ();
}
2019-07-09 15:22:07 +00:00
public static void RegisterMenuItem (MenuEntry menuEntry)
2020-05-31 17:07:22 +00:00
{
2019-07-09 15:22:07 +00:00
s_rootMenuEntry.AddChild (menuEntry);
2020-05-31 17:07:22 +00:00
}
}
}