Esempio n. 1
0
 public void CreateLevel()
 {
     developerMode = true;
     if (GameController.gameController.numOfRows >= minimumRows && GameController.gameController.numOfCols >= mimimumCols && GameController.gameController.levelName.Length > 0 && !EditLevelList.IsAlreadyLevel(GameController.gameController.levelName))
     {
         GameController.gameController.levelMode = LevelMode.Constructing;
         LoadLevel();
     }
     else //Leave debug for now
     {
         if (EditLevelList.IsAlreadyLevel(levelName))
         {
             Debug.Log(levelName + " has already been used!");
         }
     }
 }
Esempio n. 2
0
    public void SaveLevelData()
    {
        saveFileName = GameController.gameController.levelName + ".json";

        savedLevelData.numOfRows = GameController.gameController.numOfRows;
        savedLevelData.numOfCols = GameController.gameController.numOfCols;
        Debug.Log("Saving obstacles...");
        // Collect information on all obstacles within the lvel
        GameObject[] obstacleList = GameObject.FindGameObjectsWithTag("Obstacle");
        savedLevelData.obstacles = new ObstacleClass[obstacleList.Length];
        savedObstacleIndex       = 0;
        for (int i = 0; i < obstacleList.Length; i++)
        {
            AddObstacleData(obstacleList[i]);
        }
        Debug.Log("Saving spawn platform...");
        // Collect informatino about where the player is within the level
        GameObject spawnPlatform = GameObject.FindGameObjectWithTag("SpawnPlatform");

        if (spawnPlatform == null)
        {
            Debug.Log("Spawn platform is required in order to save!");
        }
        AddInitialSpawnData(spawnPlatform);

        Debug.Log("Saving checkpoints...");
        GameObject[] checkpointList = GameObject.FindGameObjectsWithTag("Checkpoint");
        savedLevelData.checkpoints = new ObstacleClass[checkpointList.Length];
        savedCheckpointIndex       = 0;
        for (int i = 0; i < checkpointList.Length; i++)
        {
            AddCheckPointData(checkpointList[i]);
        }
        Debug.Log("Saving goals...");
        // Collect information on all goals within the level
        GameObject[] goalList = GameObject.FindGameObjectsWithTag("Goal");
        if (goalList.Length == 0)
        {
            Debug.Log("At least one goal is required in order to save!");
        }
        savedLevelData.goals = new ObstacleClass[goalList.Length];
        savedGoalIndex       = 0;
        for (int i = 0; i < goalList.Length; i++)
        {
            AddGoalData(goalList[i]);
        }
        Debug.Log("DONE! Saving file");


        string obstacleDataAsJson = JsonUtility.ToJson(savedLevelData);

        string filePath = Path.Combine(EditLevelList.levelsFolderPath, saveFileName);

        File.WriteAllText(filePath, obstacleDataAsJson);

        // Successful save, so add to level list if not already there
        if (!EditLevelList.IsAlreadyLevel(GameController.gameController.levelName))
        {
            EditLevelList.AddLevel(GameController.gameController.levelName);
        }
    }