Esempio n. 1
0
    private void LoadLevelFile(string levelPath)     //levelPath eg. levels/level1.ini
    {
        IniFileTool iniReader = new IniFileTool(levelPath, true);

        levelDuration = iniReader.getValue("level", "durationInSecs", 30);       //loads the time
        GameObject.Find("GameInfoObject").GetComponent <GameInfo>().levelName = iniReader.getValue("level", "name", "Unnamed level");
        //the following loop will load the times and wolves into the wolvesToSpawn dictionary
        int numberOfGroups = iniReader.getNumberOfGroups();

        for (int i = 0; i < numberOfGroups; i++)
        {
            string groupName = iniReader.getGroupByIndex(i);
            int    sec       = ConvertStringToInt(groupName);
            if (sec != -1)          //is a group that specifies time
            {
                string wolves  = iniReader.getValue(groupName, "spawn", "wolf");
                string message = iniReader.getValue(groupName, "message", "");
                wolvesToSpawn.Add(sec, wolves.Split(';')); //sets the time as value and wolves obtained from the level file to the dictionary
                messages.Add(sec, message);                //Adds a message to the list
            }
        }

        //Loading defined sceneObjects
        int numberOfObjects = iniReader.getNumberOfKeys("sceneObjects");

        for (int i = 0; i < numberOfObjects; i++)
        {
            String newObj = iniReader.getValueByIndex("sceneObjects", i, null);
            if (newObj != null)          //there is a new object to add
            {
                string[] objSettings = newObj.Split(';');
                string   objName     = objSettings[0];
                Vector3  position    = new Vector3(ConvertStringToFloat(objSettings[1]), ConvertStringToFloat(objSettings[2]), ConvertStringToFloat(objSettings[3]));
                SpawnGameObject(objName, -1, position, Quaternion.identity);
            }
        }
    }
Esempio n. 2
0
 /**
  * Parses the level directory.
  */
 private void LoadLevelMenuItems()
 {
     string[] files = Directory.GetFiles(this.iniPath);
     foreach (string fileName in files)
     {
         if (fileName.EndsWith(".ini"))
         {
             IniFileTool iniFileTool    = new IniFileTool(fileName);
             string      levelName      = iniFileTool.getValue("level", "name", "Unnamed level");
             int         levelCompleted = PlayerPrefs.GetInt(fileName);
             if (levelCompleted != 0)      //if the level has been completed, show it in the level name
             {
                 levelName = levelName + " (Score: " + levelCompleted + ")";
             }
             this.items.AddLast(new LevelMenu.LevelMenuItem(levelName, fileName));
         }
     }
 }