Exemplo n.º 1
0
        // load level if player is coming back from a test session
        // register for events
        private void Start()
        {
            ExampleGame_LoadSave.Init();

            // when the game was started from the editor and the user is coming back to the editor from his game session
            // he probably will want the level that he has played to be loaded into the editor
            if (m_isComingBackFromGame)
            {
                // reload level
                LE_ExtensionInterface.Load.Delegate(this, (byte[][] p_levelData) =>
                {
                    if (LE_LevelEditorMain.Instance.IsReady)
                    {
                        StartCoroutine(LateLoad(LE_LevelEditorMain.Instance.GetLoadEvent(), p_levelData));
                    }
                    else
                    {
                        LE_LevelEditorMain.Instance.ExecuteWhenReady(() => StartCoroutine(LateLoad(LE_LevelEditorMain.Instance.GetLoadEvent(), p_levelData)));
                    }
                }, true);
            }
            m_isComingBackFromGame = false;
            // set up the event handling (link the buttons in the editor to functions in this script)
            LE_EventInterface.OnSave += OnSave;
            LE_EventInterface.OnLoad += OnLoad;
        }
Exemplo n.º 2
0
        // 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;
        }
Exemplo n.º 3
0
 // 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");
         }
     });
 }
Exemplo n.º 4
0
        // save the level and show the info dialog
        public void Save(LE_SaveEvent p_args)
        {
            // save to file
            string popupText = ExampleGame_LoadSave.SaveByFileName(LEVEL_FILE_NAME, p_args.SavedLevelData, p_args.SavedLevelMeta);

            if (p_args.RemovedDuplicatesCount > 0)
            {
                popupText += "\n'" + p_args.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");
        }
Exemplo n.º 5
0
        private void Start()
        {
            ExampleGame_LoadSave.Init();

            // load level
            LE_ExtensionInterface.Load.Delegate(this, (byte[][] p_levelData) =>
            {
                if (p_levelData != null && p_levelData.Length > 0 && p_levelData[0] != null)
                {
                    // load level data (we do not need p_levelData[1], since it contains only meta data for example the level icon)
                    // however, you might want to load it as well when you add other information to it for example the level time
                    LE_SaveLoadData level = LE_SaveLoad.LoadLevelDataFromByteArray(
                        p_levelData[0],
                        TERRAIN_LAYER,
                        TERRAIN_TEXTURE_CONFIG.TERRAIN_TEXTURES,
                        TERRAIN_TEXTURE_CONFIG.TERRAIN_TEXTURE_SIZES,
                        TERRAIN_TEXTURE_CONFIG.TERRAIN_TEXTURE_OFFSETS);
                    // call this function to destroy level editing scripts and improve performance
                    LE_SaveLoad.DisableLevelEditing(level);
                }
                else
                {
                    Debug.LogError("ExampleGame_Game: No saved level found!");
                }

                // hide loading popup shown after calling LE_ExtensionInterface.Load
                uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_LOADING);

                // find player start position

                /*	GameObject goPlayerStart = GameObject.Find("Objects/PlayerStartPosition");
                 *      if (goPlayerStart != null)
                 *      {
                 *              PLAYER.transform.position = goPlayerStart.transform.position + goPlayerStart.transform.up;
                 *              Destroy(goPlayerStart); // not needed any more
                 *      }
                 *      else
                 *      {
                 *              Debug.LogError("ExampleGame_Game: could not find a PlayerStartPosition GameObject!");
                 *      } */
            }, true);
        }
Exemplo n.º 6
0
 // 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");
         }
     }));
 }