示例#1
0
        /// <summary>
        /// Loads a JSON level file from the given path.
        /// </summary>
        public void LoadLevelFromJSON(string path)
        {
            var asset = JSONFileUtility.LoadFromJSONFile <Level>(path);

            // If asset failed to load
            if (asset == null)
            {
                if (Application.isEditor || Debug.isDebugBuild)
                {
                    Debug.LogError("Failed to load level!");
                }

                return;
            }

            if (loadedLevel != null)
            {
                CloseLevel();
            }

            editor.LastEditedLevelPath = path;

            loadedLevel = asset;
            levelLoaded = true;
            dirty       = false;
            SetupLevelObjects();
            InitObjectCounts();
            GetObjectCounts();
            ReconstructFloor();
            StartEditing();
            onLoadLevel.Invoke();
        }
示例#2
0
        /// <summary>
        /// Saves the current level.
        /// </summary>
        public void SaveCurrentLevelToJSON(bool doUseFilePanel = false)
        {
            if (doUseFilePanel || loadedLevelPath == "")
            {
                string savePath = editor.GetSaveLevelPath();
                if (savePath == default(string) || savePath == "")
                {
                    return;
                }
                JSONFileUtility.SaveToJSONFile(loadedLevel, savePath);
                loadedLevelPath = savePath;
            }

            else
            {
                JSONFileUtility.SaveToJSONFile(loadedLevel, loadedLevelPath);
            }

            dirty = false;
            onSaveLevel.Invoke();
        }