Steam lobby implemented

This commit is contained in:
Madhav Kapa
2023-06-01 08:03:48 -07:00
parent c7647c8097
commit 49efee80e2
95 changed files with 10258 additions and 6167 deletions

View File

@ -2,115 +2,32 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class InGameManager : MonoBehaviour
{
[SerializeField] private Volume gameVolume;
[SerializeField]
private Volume gameVolume;
[SerializeField]
private Volume pausedVolume;
[SerializeField] private Volume pausedVolume;
[SerializeField]
private bool isPaused = false;
private bool isTransitioning = false;
[SerializeField] private bool isPaused;
// [SerializeField]
// [SerializeField]
//private float pauseTransitionDuration = 1f;
[SerializeField]
private Canvas gameCanvas;
[SerializeField]
private Canvas pausedCanvas;
[SerializeField]
private List<AudioSource> sounds = new List<AudioSource>();
private List<float> initSoundVolumes = new List<float>();
[SerializeField] private Canvas gameCanvas;
public bool IsPaused { get { return this.isPaused; } }
[SerializeField] private Canvas pausedCanvas;
public void TogglePause()
{
if (!isTransitioning)
{
isPaused = !isPaused;
Cursor.visible = isPaused;
if (!isPaused)
{
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.lockState = CursorLockMode.None;
}
StartCoroutine(pauseTransition());
[SerializeField] private List<AudioSource> sounds = new();
}
private readonly List<float> initSoundVolumes = new();
private bool isTransitioning;
}
public void UnPause()
{
if (!isTransitioning)
{
isPaused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = isPaused;
StartCoroutine(pauseTransition());
}
}
public void Pause()
{
if (!isTransitioning)
{
isPaused = true;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = isPaused;
StartCoroutine(pauseTransition());
}
}
public bool IsPaused => isPaused;
IEnumerator pauseTransition()
{
if (pausedCanvas.gameObject.activeInHierarchy && !isPaused)
{
pausedCanvas.gameObject.SetActive(false);
}
if (gameCanvas.gameObject.activeInHierarchy && isPaused)
{
gameCanvas.gameObject.SetActive(false);
}
this.isTransitioning = true;
yield return new WaitForSeconds(0);
this.isTransitioning = false;
print("Unpause canvas?" + isPaused+","+pausedCanvas.gameObject.activeInHierarchy);
if (!pausedCanvas.gameObject.activeInHierarchy && isPaused)
{
pausedCanvas.gameObject.SetActive(true);
}
if (!gameCanvas.gameObject.activeInHierarchy && !isPaused)
{
gameCanvas.gameObject.SetActive(true);
}
}
public void SetVolume(float volume)
{
for (int i = 0;i<sounds.Count;i++)
{
sounds[i].volume = initSoundVolumes[i]*volume;
}
}
// Start is called before the first frame update
void Start()
private void Start()
{
isPaused = false;
Cursor.lockState = CursorLockMode.Locked;
@ -120,23 +37,15 @@ public class InGameManager : MonoBehaviour
gameCanvas.gameObject.SetActive(true);
pausedCanvas.gameObject.SetActive(false);
foreach (AudioSource source in sounds)
{
initSoundVolumes.Add(source.volume);
}
foreach (var source in sounds) initSoundVolumes.Add(source.volume);
}
// Update is called once per frame
void Update()
private void Update()
{
if (Input.GetButtonDown("Pause"))
{
this.TogglePause();
}
if (Input.GetButtonDown("Pause")) TogglePause();
if (isTransitioning||true)
if (isTransitioning || true)
{
if (isPaused)
{
@ -149,20 +58,74 @@ public class InGameManager : MonoBehaviour
//pausedVolume.weight = pausedVolume.weight > 0.9 ? 1 : pausedVolume.weight;
gameVolume.weight = 0;
pausedVolume.weight = 1;
}
else
{
//transition out of pause
gameVolume.weight = 1;
pausedVolume.weight = 0;
}
}
}
public void TogglePause()
{
if (!isTransitioning)
{
isPaused = !isPaused;
Cursor.visible = isPaused;
if (!isPaused)
Cursor.lockState = CursorLockMode.Locked;
else
Cursor.lockState = CursorLockMode.None;
StartCoroutine(pauseTransition());
}
}
public void UnPause()
{
if (!isTransitioning)
{
isPaused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = isPaused;
StartCoroutine(pauseTransition());
}
}
public void Pause()
{
if (!isTransitioning)
{
isPaused = true;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = isPaused;
StartCoroutine(pauseTransition());
}
}
private IEnumerator pauseTransition()
{
if (pausedCanvas.gameObject.activeInHierarchy && !isPaused) pausedCanvas.gameObject.SetActive(false);
if (gameCanvas.gameObject.activeInHierarchy && isPaused) gameCanvas.gameObject.SetActive(false);
isTransitioning = true;
yield return new WaitForSeconds(0);
isTransitioning = false;
print("Unpause canvas?" + isPaused + "," + pausedCanvas.gameObject.activeInHierarchy);
if (!pausedCanvas.gameObject.activeInHierarchy && isPaused) pausedCanvas.gameObject.SetActive(true);
if (!gameCanvas.gameObject.activeInHierarchy && !isPaused) gameCanvas.gameObject.SetActive(true);
}
public void SetVolume(float volume)
{
for (var i = 0; i < sounds.Count; i++) sounds[i].volume = initSoundVolumes[i] * volume;
}
public void ExitToMenu()
{
SceneManager.LoadScene(0);
}
}
}

View File

@ -1,52 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InGameMenuManager : MonoBehaviour
{
[SerializeField]
private Button settingsButton;
[SerializeField]
private Button returnToMenuButton;
private Animator menuAnimator;
[SerializeField]
private Scrollbar sensitivitySlider;
[SerializeField]
private Scrollbar volumeSlider;
private PlayerComponent player;
[SerializeField] private Button settingsButton;
[SerializeField] private Button returnToMenuButton;
[SerializeField] private Scrollbar sensitivitySlider;
[SerializeField] private Scrollbar volumeSlider;
private InGameManager gameManager;
private Animator menuAnimator;
private PlayerComponent player;
// Start is called before the first frame update
void Start()
private void Start()
{
menuAnimator= GetComponent<Animator>();
menuAnimator = GetComponent<Animator>();
settingsButton.onClick.AddListener(SettingsClicked);
returnToMenuButton.onClick.AddListener(SettingsUnClicked);
player = GameObject.FindObjectOfType(typeof(PlayerComponent)) as PlayerComponent;
gameManager = GameObject.FindObjectOfType<InGameManager>();
}
void SettingsClicked()
{
menuAnimator.SetBool("SettingsOpen", true);
}
void SettingsUnClicked()
{
menuAnimator.SetBool("SettingsOpen", false);
}
public void UpdateSensitivity()
{
this.player.SetSensitivity(sensitivitySlider.value*4f);
}
public void UpdateVolume()
{
gameManager.SetVolume(volumeSlider.value*2);
player = FindObjectOfType(typeof(PlayerComponent)) as PlayerComponent;
gameManager = FindObjectOfType<InGameManager>();
}
// Update is called once per frame
void Update()
private void Update()
{
}
}
private void SettingsClicked()
{
menuAnimator.SetBool("SettingsOpen", true);
}
private void SettingsUnClicked()
{
menuAnimator.SetBool("SettingsOpen", false);
}
public void UpdateSensitivity()
{
player.SetSensitivity(sensitivitySlider.value * 4f);
}
public void UpdateVolume()
{
gameManager.SetVolume(volumeSlider.value * 2);
}
}

View File

@ -1,54 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Attach this behavior to a master room collider. Enables everything in this room OnTriggerEnter of [tag]
/// disables everything in this room OnTriggerExit of [tag]
/// Attach this behavior to a master room collider. Enables everything in this room OnTriggerEnter of [tag]
/// disables everything in this room OnTriggerExit of [tag]
/// </summary>
public class Optimizer : MonoBehaviour
{
[SerializeField]
public string Tag;
[SerializeField]
private GameObject[] references;
[SerializeField]
private bool beginDisabled = true;
[SerializeField] public string Tag;
[SerializeField] private GameObject[] references;
[SerializeField] private bool beginDisabled = true;
private void Start()
{
if (beginDisabled)
{
Disable();
}
}
public void Enable()
{
foreach (GameObject go in references)
{
go.SetActive(true);
}
}
public void Disable()
{
foreach (GameObject go in references)
{
go.SetActive(false);
}
if (beginDisabled) Disable();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag(Tag))
{
Enable();
}
if (other.CompareTag(Tag)) Enable();
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag(Tag))
{
Disable();
}
if (other.CompareTag(Tag)) Disable();
}
}
public void Enable()
{
foreach (var go in references) go.SetActive(true);
}
public void Disable()
{
foreach (var go in references) go.SetActive(false);
}
}