// load level if player is coming back from a test session // register for events private void Start() { ExampleGame_LoadSave.Init(); if (PLAYER != null) { PLAYER.enabled = false; } // show a loading message uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_LOADING); // try load dungeon level from file if (ExampleGame_LoadSave.IsLevelFileFound(LEVEL_FILE_NAME)) { // load level from file StartCoroutine(ExampleGame_LoadSave.LoadRoutineByFileName(LEVEL_FILE_NAME, (byte[][] p_levelData) => { LE_LevelEditorMain.Instance.ExecuteWhenReady(() => StartCoroutine(LateLoad(LE_LevelEditorMain.Instance.GetLoadEvent(), p_levelData))); })); } else { // load default dungeon level if no file is saved string[] dataAsStringArray = ExampleGame_DungeonGame_Level.LEVEL.Split('#'); byte[][] loadedByteArrays = new byte[][] { System.Convert.FromBase64String(dataAsStringArray[0]), System.Convert.FromBase64String(dataAsStringArray[1]) }; LE_LevelEditorMain.Instance.ExecuteWhenReady(() => StartCoroutine(LateLoad(LE_LevelEditorMain.Instance.GetLoadEvent(), loadedByteArrays))); } // set up the event handling (link the buttons in the editor to functions in this script) LE_EventInterface.OnSave += OnSave; LE_EventInterface.OnLoad += OnLoad; }
// set load and save callbacks in the LE_ExtensionInterface (these callbacks can be overwritten by MRLE extensions bought in the Asset Store) public static void Init() { LE_ExtensionInterface.Load.SetDelegate(1, (object p_sender, System.Action <byte[][]> p_onLoadedCallback, bool p_isReload) => { // show a loading message if (uMyGUI_PopupManager.Instance != null) { uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_LOADING); } // try load level ((MonoBehaviour)p_sender).StartCoroutine(ExampleGame_LoadSave.LoadRoutineByFileName(LEVEL_FILE_NAME, p_onLoadedCallback)); }); LE_ExtensionInterface.Save.SetDelegate(1, (object p_sender, byte[] p_levelData, byte[] p_levelMeta, int p_removedDuplicatesCount) => { // save to file string popupText = ExampleGame_LoadSave.SaveByFileName(LEVEL_FILE_NAME, p_levelData, p_levelMeta); if (uMyGUI_PopupManager.Instance != null) { if (p_removedDuplicatesCount > 0) { popupText += "\n'" + p_removedDuplicatesCount + "' duplicate object(s) removed before saving\n(duplicate = same: object, position, rotation, scale)."; } ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)).SetText("Level Saved", popupText).ShowButton("ok"); } }); }
// try to load the saved level file and show a loading dialog or an error message private void OnLoad(object p_sender, LE_LoadEvent p_args) { // show a loading message uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_LOADING); // try load level StartCoroutine(ExampleGame_LoadSave.LoadRoutineByFileName(LEVEL_FILE_NAME, (byte[][] p_levelData) => { if (p_levelData != null && p_levelData.Length == 2 && p_levelData[0] != null && p_levelData[1] != null) { // load the level from file if the file exists StartCoroutine(LateLoad(p_args, p_levelData)); } else { uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_LOADING); // show an error message if there is no saved level ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)).SetText( "No saved level found!", "You first need to save a level!\nNo saved level was found!\nIn the webplayer the level must be in the clipboard!").ShowButton("ok"); } })); }