Пример #1
0
        // load level delayed by a few frames so that the loading message is rendered first
        private IEnumerator LateLoad(LE_LoadEvent p_args, byte[][] p_data)
        {
            // wait a few frames until the loading diolog is rendered and start loading the level
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            // close loading popup (the rest of the loading mechanics will happen in this frame)
            uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_LOADING);
            if (PLAYER != null)
            {
                PLAYER.enabled = true;
            }

            // safe load level
            p_args.LoadLevelDataFromBytesCallback(p_data[0]);
            p_args.LoadLevelMetaFromBytesCallback(p_data[1]);
        }
Пример #2
0
        // load level delayed by a few frames so that the loading message is rendered first
        private IEnumerator LateLoad(LE_LoadEvent p_args, byte[][] p_data)
        {
            // wait a few frames until the loading diolog is rendered and start loading the level
            yield return(new WaitForSeconds(0.3f));

            // close loading popup (the rest of the loading mechanics will happen in this frame)
            uMyGUI_PopupManager.Instance.HidePopup(uMyGUI_PopupManager.POPUP_LOADING);

            // while the level is stored in a different file on all platforms except the webplayer, the webplayer can load a level created with the
            // full level editor example or the dungeon game example from the clipboard. The code below will identify such loading operations
            bool isLevelNotSupported = false;

#if UNITY_5_3_OR_NEWER
            if (SceneManager.GetActiveScene().name == "LE_ExampleEditorTerrainOnly")
#else
            if (Application.loadedLevelName == "LE_ExampleEditorTerrainOnly")
#endif
            {
                LE_TerrainTextureConfig confTerrain   = FindObjectOfType <LE_ConfigTerrain>().TerrainTextureConfig;
                LE_SaveLoadDataPeek     peekLevelData = LE_SaveLoad.PeekLevelDataFromByteArray(p_data[0], confTerrain.TERRAIN_TEXTURES, confTerrain.TERRAIN_TEXTURE_SIZES, confTerrain.TERRAIN_TEXTURE_OFFSETS);
                isLevelNotSupported =
                    // the terrain only level has no create terrain UI, because it has a default terrain, therefore all saved levels must have a terrain
                    peekLevelData.TerrainDataPreview == null ||
                    // in the terrain only example the terrain must have the width and length of 500 to fit into the level
                    peekLevelData.TerrainDataPreview.size.x != 500 || peekLevelData.TerrainDataPreview.size.z != 500 ||
                    // additionally, crashes are possible if a 9 patch terrain is used with different heightmap resolutions (see 'TT_Terrain9Patch.CrashCheck')
                    peekLevelData.TerrainDataPreview.heightmapResolution != 257 ||
                    // besides, there is no object editing supported in the terrain only example
                    peekLevelData.LevelObjectsCount > 0;
                Destroy(peekLevelData.TerrainDataPreview);
                if (isLevelNotSupported)
                {
                    ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(uMyGUI_PopupManager.POPUP_TEXT)).SetText(
                        "Loading Failed", "It seems that you have a level saved in your clipboard that comes from the full " +
                        "level editor example or from the dungeon game example. However, this is a terrain only editor example that cannot load such levels...").ShowButton("ok");
                }
            }

            if (!isLevelNotSupported)
            {
                // load level
                p_args.LoadLevelDataFromBytesCallback(p_data[0]);
                p_args.LoadLevelMetaFromBytesCallback(p_data[1]);
                // wait until the old level is really destroyed
                yield return(new WaitForEndOfFrame());

                // look at player
                GameObject player = GameObject.Find("Objects/PlayerStartPosition");
                if (player != null)
                {
                    Camera.main.transform.LookAt(player.transform.position, Vector3.up);
                }
                // just loaded a level -> it has no changes
                m_lastSaveFrame = Time.frameCount + 1;               // plus one because LE_LevelEditorMain.LastChangeFrame is set to this frame
            }
        }
Пример #3
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)
 {
     // try load level
     LE_ExtensionInterface.Load.Delegate(this, (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");
         }
     }, false);
 }
Пример #4
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");
         }
     }));
 }
Пример #5
0
// LOGIC --------------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Call to load a level into the level editor. Use the callbacks in the returned event args to start loading from byte arrays.
        /// Use if loading is needed without using the load button. Learn more:
        /// http://www.freebord-game.com/index.php/multiplatform-runtime-level-editor/documentation/load
        /// </summary>
        public LE_LoadEvent GetLoadEvent()
        {
            LE_LoadEvent loadEventArgs = new LE_LoadEvent((byte[] p_savedLevelData) =>
                                                          // LoadLevelDataFromBytes callback
            {
                Vector3 removedOffset = new Vector3(99999f, -99999f, 99999f);
                // clean up level (remove all LE_Objects)
                LE_Object[] objs = Object.FindObjectsOfType <LE_Object>();
                for (int i = 0; i < objs.Length; i++)
                {
                    objs[i].transform.position += removedOffset;
                    Object.Destroy(objs[i].gameObject);
                }
                // load level data
                LE_SaveLoadData level = LE_SaveLoad.LoadLevelDataFromByteArray(p_savedLevelData, m_GUI3dTerrain != null?m_GUI3dTerrain.TERRAIN_LAYER:0, m_configTextures, m_configTextureSizes, m_configTextureOffsets);
                // process all level objects as if they were new
                for (int i = 0; i < level.LevelObjects.Length; i++)
                {
                    LE_SaveLoadData.ObjectData obj = level.LevelObjects[i];
                    if (obj.Result == LE_SaveLoadData.ObjectData.EResult.INSTANCE)
                    {
                        // add snapping if needed
                        if (m_GUI3dObject != null)
                        {
                            LE_LogicObjects.AddSnappingScripts(m_GUI3dObject, obj.Instance);
                        }
                    }
                    else if (obj.Result == LE_SaveLoadData.ObjectData.EResult.STREAMED)
                    {
                        // add snapping if needed once spawned
                        LS_ManagedObjectBase managedObj = LS_LevelStreamingSceneManager.Instance.GetManagedObject(obj.StreamedLevelObjectID);
                        if (managedObj != null)
                        {
                            // add snapping if needed
                            if (m_GUI3dObject != null)
                            {
                                managedObj.m_onShow += (object p_object, System.EventArgs p_args) =>
                                {
                                    if (m_GUI3dObject != null && p_object is LS_ManagedObjectInstantiateDestroy)
                                    {
                                        LE_LogicObjects.AddSnappingScripts(m_GUI3dObject, ((LS_ManagedObjectInstantiateDestroy)p_object).Instance.GetComponent <LE_Object>());
                                    }
                                };
                            }
                        }
                    }
                }
                // inform listeners that the level is now fully loaded
                if (LE_EventInterface.OnLoadedLevelInEditor != null)
                {
                    LE_EventInterface.OnLoadedLevelInEditor(this, System.EventArgs.Empty);
                }
            }, (byte[] p_savedLevelMeta) =>
                                                          // LoadLevelMetaFromBytes callback
            {
                // load level meta
                LE_SaveLoad.LevelMetaData meta = LE_SaveLoad.LoadLevelMetaFromByteArray(p_savedLevelMeta, true);
                m_levelIcon = meta.Icon;
                if (LE_GUIInterface.Instance.delegates.SetLevelIcon != null)
                {
                    LE_GUIInterface.Instance.delegates.SetLevelIcon(meta.Icon);
                }
                else if (meta.Icon != null)
                {
                    Debug.LogError("LE_LogicLevel: GetLoadEvent: LE_LoadEvent: LoadLevelMetaFromBytes: you level meta seems to contain an icon, but you have not provided the LE_GUIInterface.delegates.SetLevelIcon delegate. Level icon will not be shown!");
                }
            });

            return(loadEventArgs);
        }