Added MainMenu + PauseMenu + Settings

Need to fix PauseMenu when load fist level because it's always displayed
Need to find a way to access to DontDestroyOnLoad Objects to get back Settings Menu
This commit is contained in:
Patience Zampasi 2024-02-06 23:55:01 +01:00
parent 2f61f47445
commit 084dcf9903
19 changed files with 5000 additions and 13 deletions

6
.vsconfig Normal file
View File

@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}

32
Assets/DontDestroy.cs Normal file
View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DontDestroy : MonoBehaviour
{
[HideInInspector]
public string objectId;
private void Awake()
{
objectId = name + transform.position.ToString();
}
void Start()
{
for (int i = 0; i < Object.FindObjectsOfType<DontDestroy>().Length; i++)
{
if (Object.FindObjectsOfType<DontDestroy>()[i] != this)
{
if (Object.FindObjectsOfType<DontDestroy>()[i].objectId == objectId)
{
Destroy(gameObject);
}
}
DontDestroyOnLoad(gameObject);
}
}
}

View File

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

View File

@ -5,18 +5,22 @@ using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
public Slider slider;
public Slider slider;
public void SetMaxHealth(int health){
void Start()
{
slider.value = float.MaxValue;
}
slider.maxValue = health;
slider.value = health;
public void SetMaxHealth(int health)
{
slider.maxValue = health;
slider.value = health;
}
}
public void SetHealth(int health){
slider.value = health;
}
public void SetHealth(int health)
{
slider.value = health;
}
}

33
Assets/MainMenu.cs Normal file
View File

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour {
public string levelToLoad;
public GameObject settingPanel;
public GameObject gameName;
public void StartGame()
{
SceneManager.LoadScene(levelToLoad);
Time.timeScale = 1;
}
public void SettingsOpen()
{
settingPanel.SetActive(true);
gameName.SetActive(false);
}
public void SettingsClose()
{
settingPanel.SetActive(false);
gameName.SetActive(true);
}
public void QuitGame()
{
Application.Quit();
}
}

11
Assets/MainMenu.cs.meta Normal file
View File

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

70
Assets/MainMixer.mixer Normal file
View File

@ -0,0 +1,70 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!241 &24100000
AudioMixerController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: MainMixer
m_OutputGroup: {fileID: 0}
m_MasterGroup: {fileID: 24300002}
m_Snapshots:
- {fileID: 24500006}
m_StartSnapshot: {fileID: 24500006}
m_SuspendThreshold: -80
m_EnableSuspend: 1
m_UpdateMode: 0
m_ExposedParameters:
- guid: 3b4dd768d4fbdcf468517256a486d94c
name: Volume
m_AudioMixerGroupViews:
- guids:
- 8880efb31ef30984b9fae8757a6fd2dc
name: View
m_CurrentViewIndex: 0
m_TargetSnapshot: {fileID: 24500006}
--- !u!243 &24300002
AudioMixerGroupController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Master
m_AudioMixer: {fileID: 24100000}
m_GroupID: 8880efb31ef30984b9fae8757a6fd2dc
m_Children: []
m_Volume: 3b4dd768d4fbdcf468517256a486d94c
m_Pitch: 8ad2bb3d1b609f94b8ab425c320d5123
m_Send: 00000000000000000000000000000000
m_Effects:
- {fileID: 24400004}
m_UserColorIndex: 0
m_Mute: 0
m_Solo: 0
m_BypassEffects: 0
--- !u!244 &24400004
AudioMixerEffectController:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_EffectID: b7d35504c28af654385a08360844673a
m_EffectName: Attenuation
m_MixLevel: a07d6a9830ee00849a083cb67140aecc
m_Parameters: []
m_SendTarget: {fileID: 0}
m_EnableWetMix: 0
m_Bypass: 0
--- !u!245 &24500006
AudioMixerSnapshotController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Snapshot
m_AudioMixer: {fileID: 24100000}
m_SnapshotID: 3b089584237129f49ac131913f9d0d74
m_FloatValues: {}
m_TransitionOverrides: {}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3c9e45a164a51664cb33058ac7a5bc76
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 24100000
userData:
assetBundleName:
assetBundleVariant:

55
Assets/PauseMenu.cs Normal file
View File

@ -0,0 +1,55 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public GameObject pauseMenuUI;
public DontDestroy notDestroyedObjects;
public static bool gameIsPaused = false;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gameIsPaused)
{
Resume();
}
else
{
Paused();
}
}
}
void Paused()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0;
gameIsPaused = true;
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1;
gameIsPaused = false;
}
public void LoadMainMenu()
{
SceneManager.LoadScene("MainMenu");
}
public void Settings()
{
}
}

11
Assets/PauseMenu.cs.meta Normal file
View File

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

File diff suppressed because it is too large Load Diff

3507
Assets/Scenes/MainMenu.unity Normal file

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -32,6 +32,7 @@ MonoBehaviour:
m_FsrSharpness: 0.92
m_EnableLODCrossFade: 1
m_LODCrossFadeDitheringType: 1
m_ShEvalMode: 0
m_MainLightRenderingMode: 1
m_MainLightShadowsSupported: 1
m_MainLightShadowmapResolution: 2048
@ -52,9 +53,11 @@ MonoBehaviour:
m_CascadeBorder: 0.1
m_ShadowDepthBias: 1
m_ShadowNormalBias: 1
m_AnyShadowsSupported: 1
m_SoftShadowsSupported: 0
m_ConservativeEnclosingSphere: 0
m_NumIterationsEnclosingSphere: 64
m_SoftShadowQuality: 2
m_AdditionalLightsCookieResolution: 2048
m_AdditionalLightsCookieFormat: 3
m_UseSRPBatcher: 1
@ -69,6 +72,7 @@ MonoBehaviour:
m_ColorGradingMode: 0
m_ColorGradingLutSize: 32
m_UseFastSRGBLinearConversion: 0
m_SupportDataDrivenLensFlare: 1
m_ShadowType: 1
m_LocalShadowsSupported: 0
m_LocalShadowsAtlasResolution: 256
@ -78,5 +82,33 @@ MonoBehaviour:
m_Textures:
blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3}
bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3}
m_PrefilteringModeMainLightShadows: 4
m_PrefilteringModeAdditionalLight: 4
m_PrefilteringModeAdditionalLightShadows: 0
m_PrefilterXRKeywords: 1
m_PrefilteringModeForwardPlus: 0
m_PrefilteringModeDeferredRendering: 0
m_PrefilteringModeScreenSpaceOcclusion: 0
m_PrefilterDebugKeywords: 1
m_PrefilterWriteRenderingLayers: 1
m_PrefilterHDROutput: 1
m_PrefilterSSAODepthNormals: 1
m_PrefilterSSAOSourceDepthLow: 1
m_PrefilterSSAOSourceDepthMedium: 1
m_PrefilterSSAOSourceDepthHigh: 1
m_PrefilterSSAOInterleaved: 1
m_PrefilterSSAOBlueNoise: 1
m_PrefilterSSAOSampleCountLow: 1
m_PrefilterSSAOSampleCountMedium: 1
m_PrefilterSSAOSampleCountHigh: 1
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 1
m_PrefilterSoftShadowsQualityLow: 1
m_PrefilterSoftShadowsQualityMedium: 1
m_PrefilterSoftShadowsQualityHigh: 1
m_PrefilterSoftShadows: 0
m_PrefilterScreenCoord: 1
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
m_ShadowCascades: 0

61
Assets/SettingsMenu.cs Normal file
View File

@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
using System.Linq;
public class SettingsMenu : MonoBehaviour
{
Resolution[] resolutions;
public AudioMixer audioMixer;
public Dropdown resolutionDropdown;
public void Start()
{
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
resolutionDropdown.ClearOptions();
List<string> listOptions = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
listOptions.Add(option);
if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
{
currentResolutionIndex = i;
}
}
resolutionDropdown.AddOptions(listOptions);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
Screen.fullScreen = true;
}
public void SetVolume(float volume)
{
audioMixer.SetFloat("Volume", volume);
}
public void SetFullScreen(bool isFullScreen)
{
Screen.fullScreen = isFullScreen;
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
}

View File

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

View File

@ -0,0 +1,18 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"DebugDataKind": 1,
"EnableArmv9SecurityFeatures": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX32": 6,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}

View File

@ -0,0 +1,6 @@
{
"MonoBehaviour": {
"Version": 4,
"DisabledWarnings": ""
}
}

View File

@ -5,6 +5,12 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/MainMenu.unity
guid: a8072e168e535f0488e2280624204750
- enabled: 1
path: Assets/Scenes/Level_One.unity
guid: a0ee3565caba26b40aaf77d99f395ed3
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 8c9cfa26abfee488c85f1582747f6a02