private void OnPlayerMove(Vector2Int obj) { CurrentMovesCount++; movesText.text = CurrentMovesCount.ToString(); if (CurrentMap.IsAllGoalsDone) { SaveLoadManager.ClearSave(CurrentMap); StartCoroutine(Win()); IEnumerator Win() { print("<color=green>WIN</color>"); yield return(new WaitForSeconds(1f)); levelUI.SetBool("show", false); movesText.text = "0"; SaveRecord(); RankingManager.Record[] records = RankingManager.GetRecords(CurrentMap.name); TextMeshPro text = MainMenu.ModuleNumber == 2 || MainMenu.ModuleNumber == 3 ? winScreenModule2.transform.GetChild(0).GetChild(0).GetComponent <TextMeshPro>() : winScreenModule1.transform.GetChild(0).GetChild(0).GetComponent <TextMeshPro>(); text.text = ""; foreach (RankingManager.Record r in records) { text.text += $"Points: <b>{r.points.ToString()} | </b>Count of moves: <b>{r.moves.ToString()}</b> | Date: <b>{r.date.ToShortDateString()} {r.date.ToShortTimeString()}</b>\n"; } MapManager.CurrentMapManager.ClearMap(); yield return(new WaitForSeconds( (MapManager.CurrentMapManager.allCreatedElements.Count * MapManager.CurrentMapManager.destroyElementDelay) + 1f)); if (MainMenu.ModuleNumber == 1) { winScreenModule1.SetBool("show", true); } else if (MainMenu.ModuleNumber == 2 || MainMenu.ModuleNumber == 3) { winScreenModule2.SetBool("show", true); } cam.transform.rotation = Quaternion.identity; CurrentMovesCount = 0; yield return(new WaitForSeconds(0.1f)); SoundsManager.Manager.WinSound.Play(); } } else { SaveProgress(); } }
IEnumerator InstantiateButtons() { yield return(new WaitForSeconds(0.4f)); int number = 1; for (int i = 0; i < 4; i++) { Vector3 pos = new Vector3(-6.4f, 8.8f - (3.3f * i), 0f); for (int j = 0; j < 5; j++) { GameObject obj = Instantiate(module2MapButton); spawnedMapButtons.Add(obj); obj.transform.SetParent(module2Levels.transform); obj.transform.localPosition = pos; obj.name = "PreLevel" + number.ToString(); RankingManager.Record?bestResult = RankingManager.GetTheBestRecord("PreLevel" + number.ToString()); if (bestResult != null) { obj.transform.GetChild(0).GetComponent <TextMeshPro>().text += $" <size=\"1\"><b>{((RankingManager.Record)bestResult).points.ToString()}</b></size>"; } else { obj.transform.GetChild(0).GetComponent <TextMeshPro>().text += " <size=\"1\"><b>0</b></size>"; } Button3D btn = obj.GetComponent <Button3D>(); string iconPath = $"Maps/{Path.GetFileNameWithoutExtension($"{obj.name}_icon.jpg")}"; MeshRenderer renderer = obj.GetComponent <MeshRenderer>(); Material mat = new Material(Shader.Find("Legacy Shaders/Diffuse")); Texture2D texture = Resources.Load <Texture2D>(iconPath); print(iconPath); if (texture != null) { mat.mainTexture = texture; renderer.material = mat; } btn.OnClick.AddListener((sender) => { MapSerializer serializer = new MapSerializer(MapSerializer.MapsPath + "/" + sender.name); Map deserializedMap = serializer.Deserialize(true); module2Levels.SetActive(false); module2Info.SetActive(true); currentLevelModule2 = sender.name; RankingManager.Record[] records = RankingManager.GetRecords(currentLevelModule2); TextMeshPro text = module2Info.transform.GetChild(2).GetComponent <TextMeshPro>(); text.text = ""; SetMapIcon(MapSerializer.MapsPath + "/" + sender.name + ".xml", module2Info.transform.GetChild(0).gameObject); foreach (RankingManager.Record r in records) { text.text += $"Points: <b>{r.points.ToString()} | </b>Count of moves: <b>{r.moves.ToString()}</b> | Date: <b>{r.date.ToShortDateString()} {r.date.ToShortTimeString()}</b>\n"; } Button3D playBtn = module2Info.transform.GetChild(4).GetComponent <Button3D>(); Button3D playSavedBtn = module2Info.transform.GetChild(5).GetComponent <Button3D>(); playSavedBtn.isClickable = SaveLoadManager.SaveExists(deserializedMap); playSavedBtn.OnClick.RemoveAllListeners(); if (playSavedBtn.isClickable) { playSavedBtn.OnClick.AddListener(s => { Map progressedMap = SaveLoadManager.LoadLevelProgress(deserializedMap, out int movesCount); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); if (spawnModule2ButtonsCor != null) { StopCoroutine(spawnModule2ButtonsCor); spawnModule2ButtonsCor = null; } foreach (GameObject o in spawnedMapButtons) { Destroy(o); } spawnedMapButtons.Clear(); module2.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(progressedMap.biomeType); LevelManager.CurrentManager.LoadLevel(progressedMap, movesCount); } }); } playBtn.OnClick.RemoveAllListeners(); playBtn.OnClick.AddListener(s => { SaveLoadManager.ClearSave(deserializedMap); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); if (spawnModule2ButtonsCor != null) { StopCoroutine(spawnModule2ButtonsCor); spawnModule2ButtonsCor = null; } foreach (GameObject o in spawnedMapButtons) { Destroy(o); } spawnedMapButtons.Clear(); module2.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(deserializedMap.biomeType); LevelManager.CurrentManager.LoadLevel(deserializedMap); } }); }); number++; pos += new Vector3(5.3f, 0f, 0f); yield return(new WaitForSeconds(0.075f)); } } spawnModule2ButtonsCor = null; }
private void LoadModule3() { module3MapButtons.ForEach(item => Destroy(item)); module3MapButtons.Clear(); string[] allAvailableMaps = MapEditor.GetAllMapsPaths(); for (int i = 0; i < allAvailableMaps.Length; i++) { Vector3 pos = new Vector3(4f, 9.7f - (i * 0.6f), 0f); GameObject newBtn = Instantiate(module3MapButton); newBtn.transform.SetParent(module3.transform); newBtn.transform.localPosition = pos; newBtn.transform.rotation = Quaternion.identity; newBtn.transform.GetChild(3).GetComponent <TextMeshPro>().text = Path.GetFileName(allAvailableMaps[i]); newBtn.transform.GetChild(4).GetComponent <TextMeshPro>().text = File.GetLastAccessTime(allAvailableMaps[i]).ToString(); string path = MapEditor.PathToMapsDir + "/" + newBtn.transform.GetChild(1).transform.parent.GetChild(3).GetComponent <TextMeshPro>().text; newBtn.transform.GetChild(1).GetComponent <Button3D>().OnClick.AddListener((sender) => { StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); camAnim.enabled = false; MapSerializer serializer = new MapSerializer(path); Map deserializedMap = serializer.Deserialize(false); mapEditor.InitializeEditor(deserializedMap, path); } }); newBtn.transform.GetChild(0).GetComponent <Button3D>().OnClick.AddListener((sender) => { MapSerializer serializer = new MapSerializer(path); Map deserializedMap = serializer.Deserialize(false); module3.SetActive(false); module2Info.SetActive(true); RankingManager.Record[] records = RankingManager.GetRecords(deserializedMap.name); TextMeshPro text = module2Info.transform.GetChild(2).GetComponent <TextMeshPro>(); text.text = ""; foreach (RankingManager.Record r in records) { text.text += $"Points: <b>{r.points.ToString()} | </b>Count of moves: <b>{r.moves.ToString()}</b> | Date: <b>{r.date.ToShortDateString()} {r.date.ToShortTimeString()}</b>\n"; } SetMapIcon(path, module2Info.transform.GetChild(0).gameObject); Button3D playBtn = module2Info.transform.GetChild(4).GetComponent <Button3D>(); Button3D playSavedBtn = module2Info.transform.GetChild(5).GetComponent <Button3D>(); playSavedBtn.isClickable = SaveLoadManager.SaveExists(deserializedMap); playSavedBtn.OnClick.RemoveAllListeners(); if (playSavedBtn.isClickable) { playSavedBtn.OnClick.AddListener(s => { Map progressedMap = SaveLoadManager.LoadLevelProgress(deserializedMap, out int movesCount); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(progressedMap.biomeType); LevelManager.CurrentManager.LoadLevel(progressedMap, movesCount); } }); } playBtn.OnClick.RemoveAllListeners(); playBtn.OnClick.AddListener(s => { SaveLoadManager.ClearSave(deserializedMap); StartCoroutine(Coroutine()); IEnumerator Coroutine() { camAnim.SetInteger("view", LEVEL); camAnim.SetTrigger("switch"); yield return(new WaitForSeconds(0.5f)); module3.SetActive(false); module2Info.SetActive(false); camAnim.enabled = false; LevelManager.CurrentManager.SetBackgroundColor(deserializedMap.biomeType); LevelManager.CurrentManager.LoadLevel(deserializedMap); } }); }); newBtn.transform.GetChild(2).GetComponent <Button3D>().OnClick.AddListener((sender) => { File.Delete(MapEditor.PathToMapsDir + "/" + sender.transform.parent.GetChild(3).GetComponent <TextMeshPro>().text); LoadModule3(); }); module3MapButtons.Add(newBtn); } }