diff --git a/Assets/Prefabs/UI/VictoryDefeatScreen.prefab b/Assets/Prefabs/UI/VictoryDefeatScreen.prefab index 56bcdf0..39c899c 100644 --- a/Assets/Prefabs/UI/VictoryDefeatScreen.prefab +++ b/Assets/Prefabs/UI/VictoryDefeatScreen.prefab @@ -613,7 +613,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Five Up + m_text: Return Map m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -1891,7 +1891,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Return + m_text: Retry m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} diff --git a/Assets/Prefabs/UI/WorldMap/WorldMapCanvas.prefab b/Assets/Prefabs/UI/WorldMap/WorldMapCanvas.prefab index 2ccd1e6..7cb189f 100644 --- a/Assets/Prefabs/UI/WorldMap/WorldMapCanvas.prefab +++ b/Assets/Prefabs/UI/WorldMap/WorldMapCanvas.prefab @@ -36,7 +36,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 846.13, y: 573.41} + m_AnchoredPosition: {x: 846.12, y: -250} m_SizeDelta: {x: 227.75, y: 187.408} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &1388419616670829471 @@ -344,8 +344,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: -61.694} + m_SizeDelta: {x: 0, y: -123.389} m_Pivot: {x: 0.5, y: 0.5} --- !u!1001 &652135141416114485 PrefabInstance: diff --git a/Assets/Scenes/LevelSelect.unity b/Assets/Scenes/LevelSelect.unity index a8d03fd..5cd9090 100644 --- a/Assets/Scenes/LevelSelect.unity +++ b/Assets/Scenes/LevelSelect.unity @@ -537,6 +537,42 @@ PrefabInstance: propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target value: objectReference: {fileID: 1340105976} + - target: {fileID: 1388419616670829464, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_AnchoredPosition.x + value: 828 + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829464, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_AnchoredPosition.y + value: -327.58 + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1340105976} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: WorldReinitialition + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName + value: WorldMapManager, GameAssembly + objectReference: {fileID: 0} + - target: {fileID: 1388419616670829465, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName + value: UnityEngine.Object, UnityEngine + objectReference: {fileID: 0} - target: {fileID: 1388419617042242050, guid: 4a2f48781c26ad247b697aa368358f88, type: 3} propertyPath: m_Pivot.x value: 0 diff --git a/Assets/Scripts/VictoryDefeat.cs b/Assets/Scripts/VictoryDefeat.cs index fde40a0..d650a20 100644 --- a/Assets/Scripts/VictoryDefeat.cs +++ b/Assets/Scripts/VictoryDefeat.cs @@ -10,9 +10,12 @@ public class VictoryDefeat : MonoBehaviour [SerializeField] private Animator _defeatAnimator; public const float positionLoseLimit = -10.0f; + + private WorldMapSave _wms; private void Start() { + _wms = new WorldMapSave(); _isShowingVictoryOrDefeat = false; } @@ -27,6 +30,7 @@ public class VictoryDefeat : MonoBehaviour { _victoryAnimator.Play("ShowVictoryOrDefeat"); _isShowingVictoryOrDefeat = true; + _wms.UnlockNextLevel(); //win ! } @@ -42,4 +46,5 @@ public class VictoryDefeat : MonoBehaviour } } } + } diff --git a/Assets/Scripts/WorldMap/WorldMapManager.cs b/Assets/Scripts/WorldMap/WorldMapManager.cs index 676f3fd..d390a43 100644 --- a/Assets/Scripts/WorldMap/WorldMapManager.cs +++ b/Assets/Scripts/WorldMap/WorldMapManager.cs @@ -22,7 +22,9 @@ public class WorldMapManager : MonoBehaviour void Start() { //TODO: getMajorSaveFile() //Call et obtiens le chemin du fichier de sauvegarde; + _worldMapSave = new WorldMapSave(); + _worldMapSave.WorldInitialition(); UnlockLevels(); PlayerPrefs.SetInt("LevelToLoad", -1); @@ -54,6 +56,13 @@ public class WorldMapManager : MonoBehaviour counterIndex++; } } + + public void WorldReinitialition() + { + _worldMapSave.WorldReinitialition(); + + } + private void ShowLockedIcon(GameObject currentLevelButton) { currentLevelButton.GetComponent().sprite = _lockedIcon; diff --git a/Assets/Scripts/WorldMap/WorldMapSave.cs b/Assets/Scripts/WorldMap/WorldMapSave.cs index fd70d52..83bf361 100644 --- a/Assets/Scripts/WorldMap/WorldMapSave.cs +++ b/Assets/Scripts/WorldMap/WorldMapSave.cs @@ -1,6 +1,8 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; public class WorldMapSave { @@ -11,21 +13,78 @@ public class WorldMapSave SAVED } - private LevelState[] levelUnlocked = { LevelState.UNLOCKED, LevelState.UNLOCKED, LevelState.UNLOCKED, LevelState.UNLOCKED, - LevelState.UNLOCKED, LevelState.SAVED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED }; + private LevelState[] levelUnlocked = { LevelState.SAVED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, + LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED }; - public void UnlockNextLevel(int levelNumber) + private string filePath; + + public void WorldInitialition() { - if(levelNumber == 10) + + filePath = Application.persistentDataPath + "/data.dat"; + + if (File.Exists(filePath)) { - //UnlockNextWorld(); + ReadData(); } else { - levelUnlocked[levelNumber + 1] = LevelState.UNLOCKED; + WriteData(); } } + public void WriteData() + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream fileStream = File.Create(filePath); + formatter.Serialize(fileStream, levelUnlocked); + fileStream.Close(); + } + + public void ReadData() + { + BinaryFormatter formatter = new BinaryFormatter(); + FileStream fileStream = File.Open(filePath, FileMode.Open); + levelUnlocked = (LevelState[])formatter.Deserialize(fileStream); + fileStream.Close(); + } + + private int GetSavedLevelIndex() + { + for (int i = 0; i < levelUnlocked.Length; i++) + { + if (levelUnlocked[i] == LevelState.SAVED) + { + return i; + } + } + + // If LevelState.SAVED not find + return -1; + } + + public void UnlockNextLevel() + { + filePath = Application.persistentDataPath + "/data.dat"; + ReadData(); + //int actuelLevel = PlayerPrefs.GetInt(LevelToLoad,NoLevel); + //Debug.Log(actuelLevel); + levelUnlocked[GetSavedLevelIndex() + 1] = LevelState.SAVED; + levelUnlocked[GetSavedLevelIndex()] = LevelState.UNLOCKED; + WriteData(); + } + + public void WorldReinitialition() + { + if (File.Exists(filePath)) + { + File.Delete(filePath); + levelUnlocked = new LevelState[] { LevelState.SAVED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED, LevelState.LOCKED }; + } + WorldInitialition(); + + } + public LevelState GetLevelState(int index) { return levelUnlocked[index];