Exemple #1
0
    public void NewGameState(string gameStateString)
    {
        // Convert the string to our DTO format.
        GameStateDTO gameState = ConvertJSONtoDTO(gameStateString);

        // Check if this is the first game-state event received. If so, set
        // up the terrain and don't do it ever again.
        if (gameStateEventCount == 1)
        {
            TerrainGenerator terrainGenerator = new TerrainGenerator();
            int width  = terrainGenerator.CalculateWidthFromGameState(gameState);
            int height = terrainGenerator.CalculateHeightFromGameState(gameState);

            TerrainDTO terrainDTO = new TerrainDTO(width, height);
            terrainGenerator.GenerateTerrainMMO(terrainDTO);

            OverlayGenerator overlayGenerator = new OverlayGenerator(terrainFolder: terrainGenerator.terrainFolder);
            overlayGenerator.GenerateGridForTerrain(terrainDTO);

            // Generate the obstacles only on initial game creation. Don't duplicate.
            ObstacleDTO[] obstacles = gameState.obstacles;
            obstacleManager.UpdateFeatures(obstacles);
        }

        RenderGameState(gameState);

        gameStateEventCount++;
    }
Exemple #2
0
    public GameObject GenerateTerrainEdgeMMO(TerrainDTO terrainDTO)
    {
        GameObject terrainEdgePrefab = Resources.Load <GameObject>("Prefabs/Terrains/terrainEdge_future");

        terrainEdgeGameObject = UnityEngine.Object.Instantiate(terrainEdgePrefab) as GameObject;
        terrainEdgeGameObject.transform.SetParent(terrainFolder.transform, false);
        terrainEdgeGameObject.transform.localPosition = new Vector3(0, -0.1f, 0);

        GenerateTerrainEdge(terrainDTO);

        return(terrainEdgeGameObject);
    }
Exemple #3
0
    public GameObject GenerateTerrainEdge(TerrainDTO terrain)
    {
        terrainFolder         = terrainFolder ?? GetTerrainFolder();
        terrainEdgeGameObject = terrainEdgeGameObject ?? GetTerrainEdgeGameObject();
        Vector3 newScale = new Vector3(TerrainScalingFactor * (terrain.width + 100),
                                       TerrainScalingFactor,
                                       TerrainScalingFactor * (terrain.height + 100));

        terrainEdgeGameObject.transform.localScale = newScale;

        return(terrainEdgeGameObject);
    }
Exemple #4
0
 private void DisplayTerrainSizeInputs()
 {
     EditorGUILayout.BeginHorizontal();
     EditorGUI.BeginChangeCheck();
     terrainSize = EditorGUILayout.Vector2IntField("Size", terrainSize);
     if (EditorGUI.EndChangeCheck())
     {
         TerrainDTO terrainDTO = new TerrainDTO(terrainSize.x, terrainSize.y);
         terrainGenerator.GenerateTerrain(terrainDTO);
         overlayGenerator.GenerateGridForTerrain(terrainDTO);
     }
     EditorGUILayout.EndHorizontal();
 }
Exemple #5
0
    public GameObject GenerateTerrainMMO(TerrainDTO terrainDTO)
    {
        GameObject terrainPrefab = Resources.Load <GameObject>("Prefabs/Terrains/terrain_future_default");

        terrainGameObject = UnityEngine.Object.Instantiate(terrainPrefab) as GameObject;
        terrainGameObject.transform.SetParent(terrainFolder.transform, false);
        terrainGameObject.transform.localPosition = new Vector3(0, 0, 0);

        GenerateTerrain(terrainDTO);

        UpdateTerrainMaterial(terrainDTO);

        return(terrainGameObject);
    }
    public GameObject GenerateGridForTerrain(TerrainDTO terrain)
    {
        if (!gridGameObject)
        {
            gridGameObject = GetGridGameObject();
        }
        Vector3 newScale = new Vector3(TerrainGenerator.TerrainScalingFactor * terrain.width,
                                       TerrainGenerator.TerrainScalingFactor,
                                       TerrainGenerator.TerrainScalingFactor * terrain.height);

        if (gridGameObject.transform.localScale != newScale)
        {
            gridGameObject.transform.localScale = newScale;
        }
        UpdateGridMaterial(terrain);
        return(gridGameObject);
    }
    public GameObject GenerateTerrain(TerrainDTO terrain)
    {
        terrainFolder     = terrainFolder ?? GetTerrainFolder();
        terrainGameObject = terrainGameObject ?? GetTerrainGameObject();
        Vector3 newScale = new Vector3(TerrainScalingFactor * terrain.width,
                                       TerrainScalingFactor,
                                       TerrainScalingFactor * terrain.height);

        if (terrainGameObject.transform.localScale != newScale)
        {
            float shiftX = terrain.width % 2 == 0 ? TerrainSnapToGridShift : 0f;
            float shiftZ = terrain.height % 2 == 0 ? TerrainSnapToGridShift : 0f;
            terrainFolder.transform.localPosition  = new Vector3(shiftX, 0f, shiftZ);
            terrainGameObject.transform.localScale = newScale;
        }
        return(terrainGameObject);
    }
Exemple #8
0
        public void TestGridGeneratedByDTO()
        {
            SetUpMainScene();

            TerrainDTO       terrainDTO       = new TerrainDTO(81, 2);
            GameObject       terrainFolder    = new GameObject();
            OverlayGenerator overlayGenerator = new OverlayGenerator(terrainFolder: terrainFolder);

            GameObject generatedGrid = overlayGenerator.GenerateGridForTerrain(terrainDTO);

            Assert.AreEqual(generatedGrid.transform.parent, terrainFolder.transform);
            Assert.AreEqual(generatedGrid.transform.name, "overlay_grid(Clone)");

            Assert.AreEqual(generatedGrid.transform.transform.localPosition.x, 0);
            Assert.AreEqual(generatedGrid.transform.transform.localPosition.y, 0.01f);
            Assert.AreEqual(generatedGrid.transform.transform.localPosition.z, 0);
            Assert.AreEqual(
                generatedGrid.GetComponent <Renderer>().sharedMaterial.mainTextureScale,
                new Vector2(81, 2)
                );
        }
    private void UpdateGridMaterial(TerrainDTO terrain)
    {
        Material material = gridGameObject.GetComponent <Renderer>().sharedMaterial;

        material.mainTextureScale = new Vector2(terrain.width, terrain.height);
    }
 public void SetUpTerrainDTO()
 {
     terrainDTO = new TerrainDTO();
 }