414 lines
15 KiB
C#
414 lines
15 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.Animations.Rigging;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Playables;
|
|
using System;
|
|
|
|
public class MainMenu : MonoBehaviour
|
|
{
|
|
public bool hasPressedAnyKey;
|
|
public bool enableGameplayControllerAtLaunch = true;
|
|
public GameObject gameplayController;
|
|
[SerializeField] private UnityEvent afterPressedAnyKeyEvent;
|
|
|
|
[SerializeField] private GameObject continueButton;
|
|
|
|
[SerializeField] private RigBuilder pocketWatchRigBuilder;
|
|
[SerializeField] private MultiAimConstraint multiAimConstraintShortHand;
|
|
[SerializeField] private Transform targetAim;
|
|
[SerializeField] List<float> remainingValues = new List<float>();
|
|
public float transitionDuration = 1f;
|
|
private Coroutine TransitionWeightToAimingShortHandToCurrentTargetCoroutine;
|
|
//private Coroutine TransitionWeightToNotAimingGunsCoroutine;
|
|
|
|
public PlayableDirector gameLaunchedLogosScreen;
|
|
public PlayableDirector gameLaunchedPlayable;
|
|
|
|
[Header("Menus")]
|
|
//[SerializeField] private PlayableDirector returnToMainMenuHomePanel;
|
|
[SerializeField] private PlayableDirector returnFromSaveSlotsMenuPanel;
|
|
[SerializeField] private PlayableDirector returnFromLoadGameMenuPanel;
|
|
[SerializeField] private PlayableDirector returnFromStartGameMenuPanel;
|
|
[SerializeField] private PlayableDirector returnFromSettingsMenuPanel;
|
|
[SerializeField] private PlayableDirector returnFromGraphicsMenuPanel;
|
|
[SerializeField] private PlayableDirector returnFromAudioSettingsMenuPanel;
|
|
[SerializeField] private PlayableDirector retrunFromGameplaySettingsMenuPanel;
|
|
|
|
[Header("Menus Buttons")]
|
|
[SerializeField] private Button mainMenuHomePanelFirstSelectedButton;
|
|
[SerializeField] private Button saveSlotsMenuPanelFirstSelectedButton;
|
|
[SerializeField] private Button loadGameMenuPanelFirstSelectedButton;
|
|
[SerializeField] private Button startGameMenuPanelFirstSelectedButton;
|
|
[SerializeField] private Button settingsMenuPanelFirstSelectedButton;
|
|
[SerializeField] private TMP_Dropdown graphicsMenuPanelFirstSelectedButton;
|
|
[SerializeField] private Slider audioSettingsMenuPanelFirstSelectedButton;
|
|
[SerializeField] private Slider gameplaySettingsMenuPanelFirstSelectedButton;
|
|
|
|
[Header("Date/Time Related")]
|
|
public TextMeshProUGUI[] saveSlotsDateTime;
|
|
public TextMeshProUGUI[] loadSlotDateTime;
|
|
|
|
[Header("New Game Load Scene")]
|
|
[SerializeField] private LoadScene loadNewGameScene;
|
|
[SerializeField] private LoadScene loadDemoNewGameScene;
|
|
|
|
[Header("Currently Selected Save Slot Info")]
|
|
public TextMeshProUGUI currentlySelectedSaveSlot;
|
|
|
|
[Header("DEBUGGING")]
|
|
public MainMenuDebugging mainMenuDebugging;
|
|
|
|
private static MainMenu _instance;
|
|
public static MainMenu GetInstance() { return _instance; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
if (enableGameplayControllerAtLaunch)
|
|
{
|
|
if (GameplayController.GetInstance() == null)
|
|
{
|
|
gameplayController.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Confined;
|
|
//StartCoroutine(PressAnyKeyUpdate());
|
|
if (LoadManager.GetInstance().LoadingMainMenu)
|
|
{
|
|
SaveSlotManager.GetInstance().LoadingScreen.SetActive(false);
|
|
SaveSlotManager.GetInstance().loadingUIAnimator.SetBool("FadeIn", false);
|
|
LoadManager.GetInstance().LoadingMainMenu = false;
|
|
gameLaunchedPlayable.Play();
|
|
}
|
|
}
|
|
|
|
public void GoToMainMenuHomePanelState()
|
|
{
|
|
mainMenuState = MainMenuState.MainMenuHomePanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = mainMenuHomePanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToSaveSlotsMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.SaveSlotsMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = saveSlotsMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToLoadGameMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.LoadGameMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = loadGameMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToStartGameMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.StartGameMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = startGameMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToSettingsMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.SettingsMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = settingsMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToGraphicsMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.GraphicsMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = graphicsMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToAudioSettingsMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.AudioSettingsMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = audioSettingsMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToGameplaySettingsMenuPanelState()
|
|
{
|
|
mainMenuState = MainMenuState.GameplaySettingsMenuPanel;
|
|
EventSystemController.GetInstance().firstSelectedButton = gameplaySettingsMenuPanelFirstSelectedButton.gameObject;
|
|
EventSystem.current.SetSelectedGameObject(EventSystemController.GetInstance().firstSelectedButton);
|
|
}
|
|
|
|
public void GoToEnteringNewGameState()
|
|
{
|
|
mainMenuState = MainMenuState.EnteringNewGame;
|
|
}
|
|
|
|
public enum MainMenuState
|
|
{
|
|
PressAnyKey,
|
|
MainMenuHomePanel,
|
|
SaveSlotsMenuPanel,
|
|
LoadGameMenuPanel,
|
|
StartGameMenuPanel,
|
|
SettingsMenuPanel,
|
|
GraphicsMenuPanel,
|
|
AudioSettingsMenuPanel,
|
|
GameplaySettingsMenuPanel,
|
|
EnteringNewGame
|
|
}
|
|
|
|
public MainMenuState mainMenuState = MainMenuState.MainMenuHomePanel;
|
|
|
|
private void Update()
|
|
{
|
|
switch (mainMenuState)
|
|
{
|
|
case MainMenuState.PressAnyKey:
|
|
//Nothing to see here.
|
|
break;
|
|
case MainMenuState.MainMenuHomePanel:
|
|
//Nothing to see here.
|
|
break;
|
|
case MainMenuState.SaveSlotsMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromSaveSlotsMenuPanel.Play();
|
|
GoToMainMenuHomePanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.LoadGameMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromLoadGameMenuPanel.Play();
|
|
GoToMainMenuHomePanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.StartGameMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromStartGameMenuPanel.Play();
|
|
GoToSaveSlotsMenuPanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.SettingsMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromSettingsMenuPanel.Play();
|
|
GoToMainMenuHomePanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.GraphicsMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromGraphicsMenuPanel.Play();
|
|
GoToSettingsMenuPanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.AudioSettingsMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
returnFromAudioSettingsMenuPanel.Play();
|
|
GoToSettingsMenuPanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.GameplaySettingsMenuPanel:
|
|
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton1))
|
|
{
|
|
retrunFromGameplaySettingsMenuPanel.Play();
|
|
GoToSettingsMenuPanelState();
|
|
}
|
|
break;
|
|
case MainMenuState.EnteringNewGame:
|
|
//Nothing to see here.
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void PressAnyKey()
|
|
{
|
|
StartCoroutine(PressAnyKeyUpdate());
|
|
}
|
|
|
|
IEnumerator PressAnyKeyUpdate()
|
|
{
|
|
while (hasPressedAnyKey == false)
|
|
{
|
|
if (Input.anyKey)
|
|
{
|
|
afterPressedAnyKeyEvent.Invoke();
|
|
hasPressedAnyKey = true;
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
//public void PlayGame()
|
|
//{
|
|
// SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
|
//}
|
|
|
|
public void Feedback()
|
|
{
|
|
Application.OpenURL("https://docs.google.com/forms/d/e/1FAIpQLSekVflFWduV2ivydWJcXKXMDd6a8orKRV0FTvOrU51FIRti5g/viewform");
|
|
print("Is directing player to the feeback form");
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
print("Quited game");
|
|
Application.Quit();
|
|
}
|
|
|
|
public void StartNewGame()
|
|
{
|
|
LoadController.GetInstance().NewGame();
|
|
//loadNewGameScene.LoadSceneAsync();
|
|
if (!GameplayController.GetInstance().demoMode)
|
|
{
|
|
loadNewGameScene.LoadMainAndAdditiveScenesAsync();
|
|
}
|
|
else
|
|
{
|
|
loadDemoNewGameScene.LoadMainAndAdditiveScenesAsync();
|
|
}
|
|
//loadNewGameScene.LoadMainAndAdditiveScenesSynchronously();
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void continueButtonIsInteractable()
|
|
{
|
|
continueButton.GetComponent<Button>().interactable = true;
|
|
}
|
|
|
|
public void continueButtonIsNotInteractable()
|
|
{
|
|
continueButton.GetComponent<Button>().interactable = false;
|
|
}
|
|
|
|
public void IsAimingAtTarget(int target)
|
|
{
|
|
if(TransitionWeightToAimingShortHandToCurrentTargetCoroutine != null)
|
|
{
|
|
StopCoroutine(TransitionWeightToAimingShortHandToCurrentTargetCoroutine);
|
|
}
|
|
TransitionWeightToAimingShortHandToCurrentTargetCoroutine = null;
|
|
TransitionWeightToAimingShortHandToCurrentTargetCoroutine = StartCoroutine(TransitionWeightAimingGuns(multiAimConstraintShortHand.data.sourceObjects[target].weight, 1, 2, target));
|
|
}
|
|
|
|
private IEnumerator TransitionWeightAimingGuns(float startWeight, float targetWeightForAimingAtTarget, float speed, int targetItemInList)
|
|
{
|
|
float elapsedTime = 0f;
|
|
|
|
//List<float> remainingValues = new List<float>();
|
|
remainingValues.Clear();
|
|
|
|
for (int i = 0; i < multiAimConstraintShortHand.data.sourceObjects.Count; i++)
|
|
{
|
|
remainingValues.Add(i);
|
|
remainingValues[i] = multiAimConstraintShortHand.data.sourceObjects.GetWeight(i);
|
|
}
|
|
|
|
while (elapsedTime < transitionDuration)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsedTime / transitionDuration);
|
|
print("time= "+ t);
|
|
|
|
multiAimConstraintShortHand.data.sourceObjects.SetWeight(targetItemInList, Mathf.Lerp(startWeight, targetWeightForAimingAtTarget, speed * t));
|
|
|
|
for (int i = 0; i < multiAimConstraintShortHand.data.sourceObjects.Count; i++)
|
|
{
|
|
if (i != targetItemInList)
|
|
{
|
|
multiAimConstraintShortHand.data.sourceObjects.SetWeight(i, Mathf.Lerp(remainingValues[i], 0f, speed * t));
|
|
}
|
|
}
|
|
pocketWatchRigBuilder.Build();
|
|
yield return null;
|
|
}
|
|
print("Transition weight done");
|
|
//TransitionWeightToAimingShortHandToCurrentTargetCoroutine = null;
|
|
//TransitionWeightToNotAimingGunsCoroutine = null;
|
|
}
|
|
|
|
#region Short Hand Multi Aim Constraint Related Stuff
|
|
public void MultiAimSetSelectedButton(int index)
|
|
{
|
|
IsAimingAtTarget(index);
|
|
}
|
|
|
|
public void MultiAimTeleportTargetToSelectedButton(Transform newTeleportPoint)
|
|
{
|
|
if (TransitionWeightToAimingShortHandToCurrentTargetCoroutine != null)
|
|
{
|
|
StopCoroutine(TransitionWeightToAimingShortHandToCurrentTargetCoroutine);
|
|
}
|
|
TransitionWeightToAimingShortHandToCurrentTargetCoroutine = null;
|
|
TransitionWeightToAimingShortHandToCurrentTargetCoroutine = StartCoroutine(SmoothAimTransitionToNewTarget(newTeleportPoint, 10f));
|
|
}
|
|
|
|
private IEnumerator SmoothAimTransitionToNewTarget(Transform newTeleportPoint, float speed)
|
|
{
|
|
float elapsedTime = 0f;
|
|
Vector3 targetAimStartPos = targetAim.transform.position;
|
|
|
|
while (elapsedTime < transitionDuration)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsedTime / transitionDuration);
|
|
|
|
targetAim.transform.position = Vector3.Lerp(targetAimStartPos, newTeleportPoint.position, speed * t);
|
|
|
|
yield return null;
|
|
}
|
|
print("Transition weight done");
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void ChangeNewGameToLoadChildrenLoopsScene()
|
|
{
|
|
GameManager.GetInstance().currentStoryState = GameManager.StoryState.ChildrenLoops;
|
|
GameplayController.GetInstance().isInDebuggingState = true;
|
|
loadNewGameScene = mainMenuDebugging.ChildrenLoopsLoadScene;
|
|
}
|
|
|
|
public void ChangeNewGameToLoadTestingScene()
|
|
{
|
|
GameManager.GetInstance().currentStoryState = GameManager.StoryState.TestingScene;
|
|
GameplayController.GetInstance().isInDebuggingState = true;
|
|
loadNewGameScene = mainMenuDebugging.TestingLoadScene;
|
|
}
|
|
|
|
public void ChangeNewGameToOriginalNewGameLoadScene()
|
|
{
|
|
GameManager.GetInstance().currentStoryState = GameManager.StoryState.Prologue;
|
|
GameplayController.GetInstance().isInDebuggingState = false;
|
|
loadNewGameScene = mainMenuDebugging.OriginalNewGameLoadScene;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class MainMenuDebugging
|
|
{
|
|
public LoadScene OriginalNewGameLoadScene;
|
|
public LoadScene ChildrenLoopsLoadScene;
|
|
public LoadScene TestingLoadScene;
|
|
}
|