Пример #1
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);
        }
Пример #2
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);
        }