mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-07 16:06:29 -06:00
makeshift system for moving UI elements back and forth using tweening, implemented about/title tweens and button behaviour for title screen
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class UIController : MonoBehaviour {
|
public class UIController : MonoBehaviour {
|
||||||
|
public Canvas canvas;
|
||||||
|
public BoidController boidController;
|
||||||
|
|
||||||
|
// Main Title Screen Elements
|
||||||
public Button startButton;
|
public Button startButton;
|
||||||
public Button settingsButton;
|
public Button settingsButton;
|
||||||
|
public Button aboutButton;
|
||||||
public Text titleText;
|
public Text titleText;
|
||||||
public BoidController boidController;
|
|
||||||
|
public RectTransform aboutPanel;
|
||||||
|
public Button aboutCloseButton;
|
||||||
|
|
||||||
// Element Groups
|
// Element Groups
|
||||||
private GameObject[] _titleElements;
|
private GameObject[] _titleElements;
|
||||||
@@ -14,6 +21,13 @@ public class UIController : MonoBehaviour {
|
|||||||
private GameObject[] _aboutElements;
|
private GameObject[] _aboutElements;
|
||||||
private GameObject[] _adjustmentElements;
|
private GameObject[] _adjustmentElements;
|
||||||
|
|
||||||
|
// Element Group
|
||||||
|
private bool _titleActive = true;
|
||||||
|
private bool _aboutActive = false;
|
||||||
|
private bool _settingsActive = false;
|
||||||
|
private bool _playActive = false;
|
||||||
|
private bool _adjustmentsActive = false;
|
||||||
|
|
||||||
private UIStance _currentUI;
|
private UIStance _currentUI;
|
||||||
|
|
||||||
private enum UIStance {
|
private enum UIStance {
|
||||||
@@ -24,9 +38,15 @@ public class UIController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
|
// Basic variable setup
|
||||||
|
_currentUI = UIStance.Title;
|
||||||
|
|
||||||
// Add event functions
|
// Add event functions
|
||||||
startButton.onClick.AddListener(OnStartButton);
|
startButton.onClick.AddListener(OnStartButton);
|
||||||
settingsButton.onClick.AddListener(OnSettingsButton);
|
aboutButton.onClick.AddListener(OnAboutButton);
|
||||||
|
aboutCloseButton.onClick.AddListener(OnAboutClose);
|
||||||
|
|
||||||
|
// settingsButton.onClick.AddListener(OnSettingsButton);
|
||||||
|
|
||||||
// Organize all UI Game Objects
|
// Organize all UI Game Objects
|
||||||
_titleElements = new GameObject[]
|
_titleElements = new GameObject[]
|
||||||
@@ -39,20 +59,75 @@ public class UIController : MonoBehaviour {
|
|||||||
|
|
||||||
// Handle Start Button Clicking
|
// Handle Start Button Clicking
|
||||||
private void OnStartButton() {
|
private void OnStartButton() {
|
||||||
// Move the Title Text up
|
switch (_currentUI) {
|
||||||
startButton.interactable = settingsButton.interactable = false;
|
case UIStance.Title: {
|
||||||
foreach (GameObject element in _titleElements) {
|
Debug.Log("Switching to Play Screen");
|
||||||
LeanTween
|
MoveTitleElements(true);
|
||||||
.move(element, element.transform.position + new Vector3(0, 500, 0), 1.2f)
|
break;
|
||||||
.setEase(LeanTweenType.easeInCubic);
|
}
|
||||||
|
// Shouldn't be processed
|
||||||
|
case UIStance.Play:
|
||||||
|
case UIStance.Settings:
|
||||||
|
case UIStance.About:
|
||||||
|
Debug.LogWarning($"User clicked Start Button out of Title Screen ({_currentUI})");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwitchScreen(UIStance next) {
|
// Move Title Elements In/Out
|
||||||
|
private void MoveTitleElements(bool away) {
|
||||||
|
foreach (GameObject element in _titleElements) {
|
||||||
|
LeanTween
|
||||||
|
.move(element, element.transform.position + new Vector3(0, 500 * (away ? 1 : -1), 0), 1f)
|
||||||
|
.setEase(LeanTweenType.easeInCubic);
|
||||||
|
}
|
||||||
|
|
||||||
|
LeanTween
|
||||||
|
.move(aboutButton.gameObject, aboutButton.transform.position + new Vector3(100 * (away ? 1 : -1), 0, 0),
|
||||||
|
0.75f)
|
||||||
|
.setEase(LeanTweenType.easeInCubic);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Settings Button Clicking
|
// Move About Elements In/Out
|
||||||
private void OnSettingsButton() {
|
private void MoveAboutElements(bool away) {
|
||||||
|
LeanTween
|
||||||
|
.move(aboutPanel.gameObject, aboutPanel.transform.position + new Vector3(760 * (away ? 1 : -1), 0, 0), 1.2f)
|
||||||
|
.setEase(LeanTweenType.easeInCubic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle switching to the About Screen
|
||||||
|
private void OnAboutButton() {
|
||||||
|
if (_currentUI == UIStance.Title) {
|
||||||
|
Debug.Log($"Screen Transition: {_currentUI} -> {UIStance.About}");
|
||||||
|
MoveAboutElements(false);
|
||||||
|
MoveTitleElements(true);
|
||||||
|
_currentUI = UIStance.About;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle returning to the Title Screen, closing the About Screen
|
||||||
|
private void OnAboutClose() {
|
||||||
|
if (_currentUI == UIStance.About) {
|
||||||
|
Debug.Log($"Screen Transition: {_currentUI} -> {UIStance.Title}");
|
||||||
|
MoveAboutElements(true);
|
||||||
|
MoveTitleElements(false);
|
||||||
|
_currentUI = UIStance.Title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToTitle() {
|
||||||
|
_currentUI = UIStance.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToAbout() {
|
||||||
|
_currentUI = UIStance.About;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToSettings() {
|
||||||
|
_currentUI = UIStance.Settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SwitchToPlay() {
|
||||||
|
_currentUI = UIStance.Play;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user