Made menu working in android build
This commit is contained in:
parent
647432278c
commit
30c6393a4e
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,8 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CloseApp : MonoBehaviour
|
||||
{ public void doExitGame()
|
||||
{
|
||||
public void doExitGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor; // Needed to access SceneAsset in the editor
|
||||
#endif
|
||||
using System.Collections;
|
||||
|
||||
public class LevelManager : MonoBehaviour
|
||||
{
|
||||
@ -13,37 +10,15 @@ public class LevelManager : MonoBehaviour
|
||||
[System.Serializable]
|
||||
public class LevelEntry
|
||||
{
|
||||
public Button levelButton; // UI Button assigned in the inspector
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public SceneAsset levelScene; // Reference to a .unity file, editable in the Inspector (Editor only)
|
||||
#endif
|
||||
|
||||
[HideInInspector]
|
||||
public string sceneName; // Runtime scene name used for loading (stored automatically)
|
||||
public Button levelButton;
|
||||
public string sceneName;
|
||||
}
|
||||
|
||||
// A list of LevelEntry objects that can be filled in the inspector
|
||||
public List<LevelEntry> levels = new List<LevelEntry>();
|
||||
|
||||
// Called when the GameObject is first initialized (before Start)
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// In the editor, we convert SceneAsset references into usable scene names
|
||||
foreach (var entry in levels)
|
||||
{
|
||||
if (entry.levelScene != null)
|
||||
{
|
||||
// Get the full path to the scene asset
|
||||
entry.sceneName = AssetDatabase.GetAssetPath(entry.levelScene);
|
||||
|
||||
// Extract only the scene name (e.g., "Level1" from "Assets/Scenes/Level1.unity")
|
||||
entry.sceneName = System.IO.Path.GetFileNameWithoutExtension(entry.sceneName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Loop through each level entry and hook up the button to load the correct scene
|
||||
foreach (var entry in levels)
|
||||
{
|
||||
@ -53,15 +28,25 @@ public class LevelManager : MonoBehaviour
|
||||
// Store the scene name locally to avoid closure issues in the lambda
|
||||
string sceneToLoad = entry.sceneName;
|
||||
|
||||
// Add an onClick listener that loads the correct scene when the button is clicked
|
||||
entry.levelButton.onClick.AddListener(() => LoadLevel(sceneToLoad));
|
||||
entry.levelButton.onClick.AddListener(() => OnClickLoadLevel(sceneToLoad));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This method is called when a button is clicked, and loads the given scene by name
|
||||
public void LoadLevel(string sceneName)
|
||||
public void OnClickLoadLevel(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName); // Load the scene using Unity’s SceneManager
|
||||
StartCoroutine(LoadAsyncScene(sceneName));
|
||||
}
|
||||
|
||||
IEnumerator LoadAsyncScene(string sceneName)
|
||||
{
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
|
||||
|
||||
// Wait until the asynchronous scene fully loads
|
||||
while (!asyncLoad.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ EditorBuildSettings:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/2.2-Geschaeft.unity
|
||||
guid: 498707af75f244daa9eacd8a71c6ee5f
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/2.6-Castello.unity
|
||||
guid: 8554de5c9e3d141a1bee7985b31e8313
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/3.0-SBB.unity
|
||||
guid: a21f6e13e09234179a685c8f89b0e031
|
||||
|
Loading…
x
Reference in New Issue
Block a user