mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-27 11:58:51 +02:00
feat: load dynamically level music
This commit is contained in:
@ -7,10 +7,14 @@ public class Level
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string MusicPath { get; set; }
|
||||
public string MusicName { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int TotalJumps { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int TotalAttempts { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int KilledCount { get; set; }
|
||||
}
|
||||
|
@ -1,28 +1,18 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LevelLoader : MonoBehaviour
|
||||
public class LevelsLoader : MonoBehaviour
|
||||
{
|
||||
public Text levelNameText;
|
||||
public Level level;
|
||||
|
||||
void Start()
|
||||
public void Start()
|
||||
{
|
||||
LoadLevel();
|
||||
if (level != null)
|
||||
{
|
||||
levelNameText.text = level.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
levelNameText.text = "Failed to Load Level";
|
||||
}
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
// var jsonTextFile = Resources.Load<TextAsset>("Text/jsonFile01");
|
||||
//Then use JsonUtility.FromJson<T>() to deserialize jsonTextFile into an object
|
||||
|
||||
void LoadLevel()
|
||||
{
|
||||
string path = Path.Combine(Application.dataPath, "Levels", "back-on-track.json");
|
||||
if (File.Exists(path))
|
||||
{
|
8
Assets/Scripts/LevelsSelect.meta
Normal file
8
Assets/Scripts/LevelsSelect.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 946cccb716439eccfa13f90e2fe2abe1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/LevelsSelect/LevelHomeButton.cs
Normal file
10
Assets/Scripts/LevelsSelect/LevelHomeButton.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LevelHomeButton : MonoBehaviour
|
||||
{
|
||||
public void GoToHome()
|
||||
{
|
||||
SceneManager.LoadScene("HomeScene");
|
||||
}
|
||||
}
|
2
Assets/Scripts/LevelsSelect/LevelHomeButton.cs.meta
Normal file
2
Assets/Scripts/LevelsSelect/LevelHomeButton.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef2acea012085a3bb9a981fc334afaec
|
10
Assets/Scripts/LevelsSelect/LevelNameButton.cs
Normal file
10
Assets/Scripts/LevelsSelect/LevelNameButton.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LevelNameButton : MonoBehaviour
|
||||
{
|
||||
public void PlayLevel()
|
||||
{
|
||||
SceneManager.LoadScene("LevelScene");
|
||||
}
|
||||
}
|
2
Assets/Scripts/LevelsSelect/LevelNameButton.cs.meta
Normal file
2
Assets/Scripts/LevelsSelect/LevelNameButton.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3617637b5b720115a8f1a856cb43f8a5
|
15
Assets/Scripts/LevelsSelect/LevelNameText.cs
Normal file
15
Assets/Scripts/LevelsSelect/LevelNameText.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LevelNameText : MonoBehaviour
|
||||
{
|
||||
public LevelsLoader levelsLoader;
|
||||
public Text levelNameText;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent<LevelsLoader>();
|
||||
levelNameText.text = levelsLoader.level.Name;
|
||||
}
|
||||
}
|
2
Assets/Scripts/LevelsSelect/LevelNameText.cs.meta
Normal file
2
Assets/Scripts/LevelsSelect/LevelNameText.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9d2aa88c034d40f187d6ff84705da65
|
9
Assets/Scripts/LevelsSelect/LevelNextButton.cs
Normal file
9
Assets/Scripts/LevelsSelect/LevelNextButton.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelNextButton : MonoBehaviour
|
||||
{
|
||||
public void NextLevel()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
2
Assets/Scripts/LevelsSelect/LevelNextButton.cs.meta
Normal file
2
Assets/Scripts/LevelsSelect/LevelNextButton.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c34ef065650ba0802be580828cc0d474
|
9
Assets/Scripts/LevelsSelect/LevelPreviousButton.cs
Normal file
9
Assets/Scripts/LevelsSelect/LevelPreviousButton.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelPreviousButton : MonoBehaviour
|
||||
{
|
||||
public void PreviousLevel()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
2
Assets/Scripts/LevelsSelect/LevelPreviousButton.cs.meta
Normal file
2
Assets/Scripts/LevelsSelect/LevelPreviousButton.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c53cba3260b30d02b79e69a3198546c
|
@ -1,13 +1,14 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.IO;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public Rigidbody2D rigidBody;
|
||||
public GameObject playerObject;
|
||||
public ParticleSystem particle;
|
||||
public LevelLoader levelLoader;
|
||||
public LevelsLoader levelsLoader;
|
||||
|
||||
public bool isColliding = true;
|
||||
public AudioSource audioSource;
|
||||
@ -17,26 +18,24 @@ public class Player : MonoBehaviour
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// levelLoader = GameObject.FindGameObjectWithTag("LevelLoader").GetComponent<LevelLoader>();
|
||||
levelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent<LevelsLoader>();
|
||||
|
||||
string musicPath = Path.Combine("Musics", Path.GetFileNameWithoutExtension(levelsLoader.level.MusicName));
|
||||
AudioClip clip = Resources.Load<AudioClip>(musicPath);
|
||||
if (clip == null)
|
||||
{
|
||||
Debug.LogError("Music file not found at: " + musicPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.Play();
|
||||
}
|
||||
|
||||
var mainModule = particle.main;
|
||||
mainModule.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
particle.transform.parent = null;
|
||||
|
||||
// if (levelLoader.level != null)
|
||||
// {
|
||||
// string musicPath = Path.Combine("Musics", Path.GetFileNameWithoutExtension(levelLoader.level.MusicPath));
|
||||
// AudioClip clip = Resources.Load<AudioClip>(musicPath);
|
||||
// if (clip != null)
|
||||
// {
|
||||
// audioSource.clip = clip;
|
||||
// audioSource.Play();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("Failed to load music: " + musicPath);
|
||||
// }
|
||||
// }
|
||||
|
||||
Invoke(nameof(EnableInput), 0.1f);
|
||||
}
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SelectLevelMenu : MonoBehaviour
|
||||
{
|
||||
public Text levelNameText;
|
||||
|
||||
public void PlayLevel()
|
||||
{
|
||||
SceneManager.LoadScene("LevelScene");
|
||||
}
|
||||
|
||||
public void BackBtn()
|
||||
{
|
||||
SceneManager.LoadScene("HomeScene");
|
||||
}
|
||||
|
||||
public void LastLevel()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void NextLevel()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void LevelStatsBtn()
|
||||
{
|
||||
// SceneManager.LoadSceneAsync(?);
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78914afaa50342f4fbc6b2f0d1a6c036
|
Reference in New Issue
Block a user