示例#1
0
        public static void SaveLevel(string p_levelDataFilePath, string p_levelIconFileName, byte[] p_levelData, byte[] p_levelMeta, int p_removedDuplicatesCount)
        {
            // info popup
            System.Action <string> infoPopup = (string p_infoText) =>
            {
                if (uMyGUI_PopupManager.Instance != null)
                {
                    if (p_removedDuplicatesCount > 0)
                    {
                        p_infoText += "\n'" + p_removedDuplicatesCount + "' duplicate object(s) removed before saving\n(duplicate = same: object, position, rotation, scale).";
                    }
                    ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(POPUP_TEXT)).SetText("Level Saved", p_infoText).ShowButton("ok");
                }
            };

            // save level icon as png
            LE_SaveLoad.LevelMetaData loadedMeta = LE_SaveLoad.LoadLevelMetaFromByteArray(p_levelMeta, true);
            if (loadedMeta.Icon != null)
            {
                Texture2D downScaledIcon = LE_FileSelectionHelpers.DownscaleTexture(loadedMeta.Icon, 255, 128);
                // save to file
                string path = Path.Combine(Application.persistentDataPath, p_levelIconFileName);
                // need to use own implementation of SaveToFile to keep backwards compatibility with MRLE v1.31 (had no UtilityPlatformIO.SaveToFile(..., bytes[]))
                LE_FileSelectionHelpers.SaveToFile(path, downScaledIcon.EncodeToPNG());
                Object.Destroy(loadedMeta.Icon);
                Object.Destroy(downScaledIcon);
            }

            // save level
            infoPopup(ExampleGame_LoadSave.SaveByFilePath(p_levelDataFilePath, p_levelData, p_levelMeta));
        }
示例#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);
        }