Assemblies Made and Refactored Code Folders

Created assemblies for the new design code. Relocated legacy scripts into a legacy folder and made a "new_design" folder for new design.
This commit is contained in:
MarcoHampel
2023-09-11 19:39:27 -04:00
parent 84b455b473
commit f8590432ba
209 changed files with 729 additions and 0 deletions

View File

@ -0,0 +1,25 @@
{
"name": "Game_Assembly",
"rootNamespace": "Game",
"references": [
"GUID:457756d89b35d2941b3e7b37b4ece6f1",
"GUID:a075b55b404a34748ac14ea9b6039911",
"GUID:78bd2ddd6e276394a9615c203e574844",
"GUID:344e024b5bc996043a11da352e2c9150",
"GUID:304b399c7a7ca8f45afdcd73cf5552b3",
"GUID:5b5e144fbbfa9e24188cdc68fa9a4b3c",
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
"GUID:6e5480588ffa37d4f82fe96c45e8ce9c",
"GUID:bf043f86dbf1bda4398ec83eebe40b8c",
"GUID:f0bbd04fc036a3046993adc87bbfb698"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ed2e13dc5752a434aadb5bd0b74dd42a
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,139 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
namespace Game
{
public class InGameManager : MonoBehaviour
{
[SerializeField] private Volume gameVolume;
[SerializeField] private Volume pausedVolume;
[SerializeField] private bool isPaused;
// [SerializeField]
//private float pauseTransitionDuration = 1f;
[SerializeField] private Canvas gameCanvas;
[SerializeField] private Canvas pausedCanvas;
[SerializeField] private List<AudioSource> sounds = new();
private readonly List<float> initSoundVolumes = new();
private bool isTransitioning;
public bool IsPaused => isPaused;
[SerializeField] private Scriptable.GameState state;
// Start is called before the first frame update
private void Start()
{
isPaused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = isPaused;
gameVolume.weight = 1;
pausedVolume.weight = 0;
gameCanvas.gameObject.SetActive(true);
pausedCanvas.gameObject.SetActive(false);
foreach (var source in sounds) initSoundVolumes.Add(source.volume);
}
// Update is called once per frame
private void Update()
{
state.IsPaused = isPaused;
if (Input.GetButtonDown("Pause")) TogglePause();
if (isTransitioning || true)
{
if (isPaused)
{
//transition into pause
//gameVolume.weight = Mathf.Lerp(gameVolume.weight, 0, Time.deltaTime);
//pausedVolume.weight = Mathf.Lerp(pausedVolume.weight, 1, Time.deltaTime);
//gameVolume.weight = gameVolume.weight < 0.1 ? 0 : gameVolume.weight;
//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

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d805c17d8132601478d1da4480f05fb0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,56 @@
using UnityEngine;
using UnityEngine.UI;
namespace Game
{
public class InGameMenuManager : MonoBehaviour
{
[SerializeField] private Button settingsButton;
[SerializeField] private Button returnToMenuButton;
[SerializeField] private Scrollbar sensitivitySlider;
[SerializeField] private Scrollbar volumeSlider;
private InGameManager gameManager;
private Animator menuAnimator;
[SerializeField] private Scriptable.GameSettings settings;
// Start is called before the first frame update
private void Start()
{
menuAnimator = GetComponent<Animator>();
settingsButton.onClick.AddListener(SettingsClicked);
returnToMenuButton.onClick.AddListener(SettingsUnClicked);
gameManager = FindObjectOfType<InGameManager>();
}
// Update is called once per frame
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);
settings.Sensitivity = sensitivitySlider.value * 4f;
}
public void UpdateVolume()
{
gameManager.SetVolume(volumeSlider.value * 2);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 557d1d026294ceb4eb459580401a637c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,41 @@
using UnityEngine;
namespace Game {
/// <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]
/// </summary>
public class Optimizer : MonoBehaviour
{
[SerializeField] public string Tag;
[SerializeField] private GameObject[] references;
[SerializeField] private bool beginDisabled = true;
private void Start()
{
if (beginDisabled) Disable();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag(Tag)) Enable();
}
private void OnTriggerExit(Collider other)
{
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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ce10ec9aaa603bb4da9dfadd6e590584
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: