示例#1
0
 private void OpenDemoWorld(string mapName, string templateName)
 {
     if (voxelArray == null || SelectedMap.Instance().mapName != mapName)
     {
         // create and load the file
         string filePath = WorldFiles.GetFilePath(mapName);
         if (!File.Exists(filePath))
         {
             TextAsset mapText = Resources.Load <TextAsset>(templateName);
             using (FileStream fileStream = File.Create(filePath))
             {
                 using (var sw = new StreamWriter(fileStream))
                 {
                     sw.Write(mapText.text);
                     sw.Flush();
                 }
             }
         }
         if (voxelArray != null)
         {
             voxelArray.GetComponent <EditorFile>().Save();
         }
         SelectedMap.Instance().mapName = mapName;
         SceneManager.LoadScene("editScene");
     }
     Destroy(this);
 }
示例#2
0
    public static void OpenMap(string name, string scene)
    {
        SelectedMap selectedMap = SelectedMap.Instance();

        selectedMap.mapName = name;
        SceneManager.LoadScene(scene);
    }
示例#3
0
    private IEnumerator LoadCoroutine()
    {
        yield return null;
        string mapName = SelectedMap.Instance().mapName;
        Debug.unityLogger.Log("EditorFile", "Loading " + mapName);
        MapFileReader reader = new MapFileReader(mapName);
        List<string> warnings;
        try
        {
            warnings = reader.Read(cameraPivot, voxelArray, true);
        }
        catch (MapReadException e)
        {
            var dialog = loadingGUI.gameObject.AddComponent<DialogGUI>();
            dialog.message = e.Message;
            dialog.yesButtonText = "Close";
            dialog.yesButtonHandler = () =>
            {
                voxelArray.unsavedChanges = false;
                Close();
            };
            // fix issue where message dialog doesn't use correct skin:
            dialog.guiSkin = loadingGUI.guiSkin;
            Destroy(loadingGUI);
            Debug.Log(e.InnerException);
            yield break;
        }
        // reading the file creates new voxels which sets the unsavedChanges flag
        // and clears existing voxels which sets the selectionChanged flag
        voxelArray.unsavedChanges = false;
        voxelArray.selectionChanged = false;

        Destroy(loadingGUI);
        foreach (MonoBehaviour b in enableOnLoad)
            b.enabled = true;
        if (warnings.Count > 0)
        {
            string message = "There were some issues with reading the world:\n\n  •  " +
                string.Join("\n  •  ", warnings.ToArray());
            LargeMessageGUI.ShowLargeMessageDialog(loadingGUI.gameObject, message);
        }

        if (!PlayerPrefs.HasKey("last_editScene_version"))
        {
            var dialog = loadingGUI.gameObject.AddComponent<DialogGUI>();
            dialog.message = "This is your first time using the app. Would you like a tutorial?";
            dialog.yesButtonText = "Yes";
            dialog.noButtonText = "No";
            dialog.yesButtonHandler = () =>
            {
                TutorialGUI.StartTutorial(Tutorials.INTRO_TUTORIAL, dialog.gameObject, voxelArray, touchListener);
            };
        }
        PlayerPrefs.SetString("last_editScene_version", Application.version);
    }
示例#4
0
 public void Save()
 {
     if (!voxelArray.unsavedChanges)
     {
         Debug.unityLogger.Log("EditorFile", "No unsaved changes");
         return;
     }
     Debug.unityLogger.Log("EditorFile", "Saving...");
     MapFileWriter writer = new MapFileWriter(SelectedMap.Instance().mapName);
     writer.Write(cameraPivot, voxelArray);
     voxelArray.unsavedChanges = false;
 }
示例#5
0
    private IEnumerator LoadCoroutine()
    {
        yield return(null);

        MapFileReader reader = new MapFileReader(SelectedMap.Instance().mapName);

        try
        {
            reader.Read(null, GetComponent <VoxelArray>(), false);
        }
        catch (MapReadException)
        {
            SceneManager.LoadScene("editScene"); // TODO: this is a very bad solution
        }
        loadingText.enabled = false;
    }