Beispiel #1
0
    public void LoadAllLevels()
    {
        string tempPath = Path.Combine(Application.persistentDataPath, "Levels");

        if (!Directory.Exists(tempPath))
        {
            Directory.CreateDirectory(tempPath);
        }
        foreach (string file in Directory.GetFiles(tempPath))
        {
            if (file.EndsWith(".xml"))
            {
                GameObject newLevel = new GameObject();
                newLevel.AddComponent <Level>();
                LevelXml xml = new LevelXml();
                xml.LoadFromXml(Path.Combine(tempPath, file), newLevel.GetComponent <Level>());
                if (FindObjectOfType <DataManager>().transform.Find(newLevel.gameObject.name))
                {
                    Destroy(FindObjectOfType <DataManager>().transform.Find(newLevel.gameObject.name));
                }
                newLevel.transform.parent = FindObjectOfType <DataManager>().transform;
                FindObjectOfType <DataManager>().AddLevel(newLevel);
                maxLevelNumber = FindObjectOfType <DataManager>().levels.Length;
            }
        }
    }
Beispiel #2
0
    public void LoadSelectedLevel()
    {
        string dirPath = Path.Combine(Application.persistentDataPath, "Levels");
        string file    = Path.Combine(dirPath, fileToLoad + ".xml");

        if (File.Exists(file))
        {
            LevelXml xml = new LevelXml();
            xml.LoadFromXml(file, FindObjectOfType <Level>());
            width = FindObjectOfType <Level>().width;
            DisplayWidth();
            height = FindObjectOfType <Level>().height;
            DisplayHeight();
            levelNameIF.text = FindObjectOfType <Level>().gameObject.name;

            // Hide the menu and enable interaction on other UI objects
            loadCanvas.enabled       = false;
            levelNameIF.interactable = true;
            foreach (Button button in uiButtons)
            {
                button.interactable = true;
            }
            UpdatePreview();
        }
    }