public IEnumerator GetLevelListAsync(System.Action <LevelFile[]> p_onLoaded) { // show loading popup if (uMyGUI_PopupManager.Instance != null) { uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_LOADING); } // load file with the level file names WWW www = new WWW(UtilityPlatformIO.FixFilePath(Path.Combine(Application.persistentDataPath, LEVEL_FILE_NAMES_PATH))); yield return(www); string savedLevelFileNamesText; if (string.IsNullOrEmpty(www.error)) { savedLevelFileNamesText = www.text; } else { savedLevelFileNamesText = ""; } // hide loading popup if (uMyGUI_PopupManager.Instance != null) { uMyGUI_PopupManager.Instance.HidePopup(LE_FileSelectionHelpers.POPUP_LOADING); } // callback with the loaded level names string[] savedLevelFileNames = savedLevelFileNamesText.Split(new string[] { "\r\n", "\n" }, System.StringSplitOptions.RemoveEmptyEntries); if (p_onLoaded != null) { LevelFile[] levelFiles = new LevelFile[savedLevelFileNames.Length]; for (int i = 0; i < levelFiles.Length; i++) { levelFiles[i] = new LevelFile() { Name = savedLevelFileNames[i], PathData = Path.Combine(Application.persistentDataPath, savedLevelFileNames[i] + ".txt"), PathIcon = Path.Combine(Application.persistentDataPath, savedLevelFileNames[i] + ".png") }; } p_onLoaded(levelFiles); } }
/// <summary> /// Load data from a text file /// </summary> public static IEnumerator LoadRoutineByFilePath(string p_filePath, System.Action <byte[][]> p_onLoaded) { // load level data with the WWW class (WWW is supported on all platforms for disk IO) WWW www = new WWW(UtilityPlatformIO.FixFilePath(p_filePath)); yield return(www); string savedLevel; if (string.IsNullOrEmpty(www.error)) { savedLevel = www.text; } else { Debug.LogError("ExampleGame_LoadSave: LoadRoutine: could load file '" + www.url + "'! Error:\n" + www.error); savedLevel = null; } LoadFromStr(savedLevel, p_onLoaded); }
private IEnumerator LoadLevelIcon(string p_iconPath) { if (m_iconImage != null) { float startTime = Time.realtimeSinceStartup; // wait for icon to be fully loaded WWW iconWWW = null; WaitForEndOfFrame frameEnd = new WaitForEndOfFrame(); while (iconWWW == null || !iconWWW.isDone) { // start loading icon (after a little delay (wait for the popup animation to finish)) if (iconWWW == null && Time.realtimeSinceStartup - startTime >= 0.65f && s_streamCount < MAX_STREAMS) { iconWWW = new WWW(UtilityPlatformIO.FixFilePath(p_iconPath)); s_streamCount++; m_isIconLoading = true; } // rotate loading indicator if (m_iconImage != null) { m_iconImage.transform.eulerAngles = 140f * Vector3.back * Time.realtimeSinceStartup; } if (m_iconOverlay != null) { m_iconOverlay.transform.rotation = Quaternion.identity; } yield return(frameEnd); } m_isIconLoading = false; s_streamCount--; // show icon if (string.IsNullOrEmpty(iconWWW.error) && iconWWW.texture != null) { if (m_iconImage != null) { // reset icon rotation m_iconImage.transform.rotation = Quaternion.identity; if (m_iconOverlay != null) { m_iconOverlay.transform.rotation = Quaternion.identity; } // set texture if (iconWWW.texture.width > iconWWW.texture.height) { float aspectChangeFactor = (float)iconWWW.texture.width / (float)iconWWW.texture.height; float aspectCorrectedWidth = m_iconImage.rectTransform.rect.width; aspectCorrectedWidth *= aspectChangeFactor; m_iconImage.rectTransform.pivot = new Vector2(0f, m_iconImage.rectTransform.pivot.y); m_iconImage.rectTransform.localPosition -= Vector3.right * m_iconImage.rectTransform.rect.width * 0.5f; m_iconImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, aspectCorrectedWidth); } m_iconImage.texture = iconWWW.texture; } m_isIconLoaded = true; } else { // hide icon on error (not found) if (m_iconImage != null) { m_iconImage.enabled = false; } } } else { yield return(null); } }