Пример #1
0
    IEnumerator WaitingToSave()
    {
        // Display the pop-up and disable the interaction on other UI objects
        replaceFileCanvas.enabled = true;
        levelNameIF.interactable  = false;
        foreach (Button button in uiButtons)
        {
            button.interactable = false;
        }

        replaceFileToSave = false; // default, just to be sure

        // Wait for user answer
        while (replaceFileCanvas.enabled)
        {
            yield return(new WaitForSeconds(Time.deltaTime));
        }
        // Allow the interaction on other UY objects after the pop-up was hidden
        levelNameIF.interactable = true;
        foreach (Button button in uiButtons)
        {
            button.interactable = true;
        }
        // Save level if replaceFileToSave is true
        if (replaceFileToSave)
        {
            string   tempPath = Path.Combine(Application.persistentDataPath, "Levels");
            LevelXml xml      = new LevelXml();
            xml.SaveToXml(FindObjectOfType <Level>(), Path.Combine(tempPath, levelNameIF.text + ".xml"));
        }
    }
Пример #2
0
    public void SaveLevel()
    {
        //Debug.Log(Application.persistentDataPath);
        string levelName = FindObjectOfType <Level>().gameObject.name = levelNameIF.text;

        if (levelName.Equals(""))
        {
            // Display the pop-up warning and disable the interaction on other UI opject
            warningCanvas.transform.Find("WarningText").GetComponent <Text>().text = "Warning!\nYou must put a level name to save the level.\n(The level was not saved)";
            warningCanvas.enabled    = true;
            levelNameIF.interactable = false;
            foreach (Button button in uiButtons)
            {
                button.interactable = false;
            }
            return;
        }

        string tempPath = Path.Combine(Application.persistentDataPath, "Levels");

        if (File.Exists(Path.Combine(tempPath, levelNameIF.text + ".xml")))
        {
            StartCoroutine(WaitingToSave());
            return;
        }
        else
        {
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            LevelXml xml = new LevelXml();
            xml.SaveToXml(FindObjectOfType <Level>(), Path.Combine(tempPath, levelNameIF.text + ".xml"));
        }
    }