示例#1
0
 void OnCameraStateChanged(Coords2 coords, CameraObjectController cameraController)
 {
     Camera camera;
     if (cameras.TryGetValue(coords, out camera))
     {
         camera.isOn = cameraController.IsOn();
         camera.origin = cameraController.GetOrigin();
     }
     else
     {
         //if camera is not found in registry create a new one
         camera = new Camera();
         camera.origin = cameraController.GetOrigin();
         camera.isOn = cameraController.IsOn();
         //get an unused shader property id from stack to use for that camera
         camera.shaderPropertyId = unusedShaderPropertyIds.Pop();
         cameras.Add(coords, camera);
     }
     UpdateShaderProperty(camera);
 }
示例#2
0
    public override void Generate(Map map)
    {
        Prefabs prefabs = GameManager.instance.GetPrefabs();

        int width  = map.width;
        int height = map.height;

        GameObject wallTilePrefab = prefabs.wallTilePrefabs[0];

        GameObject[] floorTilePrefabs          = prefabs.floorTilePrefabs;
        GameObject[] verticalDoorTilePrefabs   = prefabs.verticalDoorTilePrefabs;
        GameObject[] horizontalDoorTilePrefabs = prefabs.horizontalDoorTilePrefabs;

        GameObject[,] floorLayerTiles  = new GameObject[width, height];
        GameObject[,] wallLayerTiles   = new GameObject[width, height];
        GameObject[,] worldObjectLayer = new GameObject[width, height];

        //fill with random floor
        //and with the currently only wall with connected texture
        //TODO: make all walls be connected and randomize them properly
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                floorLayerTiles[x, y]  = RandomizeTile(floorTilePrefabs);
                wallLayerTiles[x, y]   = wallTilePrefab;
                worldObjectLayer[x, y] = null;
            }
        }

        //remove some walls to form a maze
        BacktrackCarve(map, wallLayerTiles);

        if (doorChance > 0.0f)
        {
            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    if (wallLayerTiles[x, y] != null)
                    {
                        continue;
                    }

                    float r = Random.Range(0.0f, 1.0f);
                    if (r < doorChance)
                    {
                        TryPlaceDoor(map, wallLayerTiles, horizontalDoorTilePrefabs, verticalDoorTilePrefabs, new Coords2(x, y));
                    }
                }
            }
        }

        //TEMP placement of camera object for tests
        worldObjectLayer[0, 1] = prefabs.cameraPrefab;
        worldObjectLayer[3, 4] = prefabs.enginePrefab;
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                Coords2 coords = new Coords2(x, y);

                GameObject floorToInstantiate = floorLayerTiles[x, y];
                map.CreateFloorTile(coords, floorToInstantiate);

                GameObject wallToInstantiate = wallLayerTiles[x, y];
                if (wallToInstantiate != null)
                {
                    map.CreateWallTile(coords, wallToInstantiate);
                }

                GameObject worldObjectToInstantiate = worldObjectLayer[x, y];
                //TEMP instantiation of world object and initialization, which should be done more carefully
                if (worldObjectToInstantiate != null)
                {
                    CameraObjectController cameraController = map.CreateWorldObject(new Coords2(x, y), worldObjectToInstantiate).GetComponent <CameraObjectController>();
                    if (cameraController != null)
                    {
                        cameraController.SetOrigin(coords, new Vector2(x + 1.2f, y + 0.5f));
                        cameraController.SetAnchor(new Vector2(x + 0.5f, y - 0.2f));
                        cameraController.RotateAroundOrigin(45.0f);
                        cameraController.SetEnabled(coords, false);
                    }
                }
            }
        }

        //update wall sprites to connect after all walls are placed
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                GameObject wallTile = map.GetWallTile(new Coords2(x, y));
                if (wallTile != null)
                {
                    wallTile.GetComponent <WallTileController>().UpdateSprite(new Coords2(x, y));
                }
            }
        }
    }
示例#3
0
    public override void Generate(Map map)
    {
        Prefabs prefabs = GameManager.instance.GetPrefabs();

        int width  = map.width;
        int height = map.height;

        GameObject[] wallTilePrefabs           = prefabs.wallTilePrefabs;
        GameObject[] floorTilePrefabs          = prefabs.floorTilePrefabs;
        GameObject[] verticalDoorTilePrefabs   = prefabs.verticalDoorTilePrefabs;
        GameObject[] horizontalDoorTilePrefabs = prefabs.horizontalDoorTilePrefabs;
        GameObject   serverPrefab = prefabs.serverPrefab;

        GameObject[,] floorLayerTiles  = new GameObject[width, height];
        GameObject[,] wallLayerTiles   = new GameObject[width, height];
        GameObject[,] worldObjectLayer = new GameObject[width, height];



        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                floorLayerTiles[x, y]  = RandomizeTile(floorTilePrefabs);
                wallLayerTiles[x, y]   = null;
                worldObjectLayer[x, y] = null;
            }
        }

        //random point where walls cross
        int crossX, crossY, missingWallOrientation;

        crossX = Random.Range(minRoomSize - 1, width - minRoomSize);
        crossY = Random.Range(minRoomSize - 1, height - minRoomSize);

        //selection of missing wall
        missingWallOrientation = Random.Range(0, 4);
        int horizontalWallMin = 1;
        int horizontalWallMax = width - 2;
        int verticalWallMin   = 1;
        int verticalWallMax   = height - 2;

        switch (missingWallOrientation)
        {
        case 0:
            verticalWallMin = crossY;
            break;

        case 1:
            horizontalWallMax = crossX;
            break;

        case 2:
            verticalWallMax = crossY;
            break;

        case 3:
            horizontalWallMin = crossX;
            break;
        }

        //placing walls
        for (int x = 0; x < width; ++x)
        {
            wallLayerTiles[x, 0]          = RandomizeTile(wallTilePrefabs);
            wallLayerTiles[x, height - 1] = RandomizeTile(wallTilePrefabs);
            if (x >= horizontalWallMin && x <= horizontalWallMax)
            {
                wallLayerTiles[x, crossY] = RandomizeTile(wallTilePrefabs);
            }
        }
        for (int y = 0; y < height; ++y)
        {
            wallLayerTiles[0, y]         = RandomizeTile(wallTilePrefabs);
            wallLayerTiles[width - 1, y] = RandomizeTile(wallTilePrefabs);
            if (y >= verticalWallMin && y <= verticalWallMax)
            {
                wallLayerTiles[crossX, y] = RandomizeTile(wallTilePrefabs);
            }
        }

        //selecting positions for doors
        int doorX = crossX;

        while (doorX == crossX)
        {
            doorX = Random.Range(horizontalWallMin, horizontalWallMax + 1);
        }
        int doorY = crossY;

        while (doorY == crossY)
        {
            doorY = Random.Range(verticalWallMin, verticalWallMax + 1);
        }

        //placing doors
        wallLayerTiles[doorX, crossY] = RandomizeTile(verticalDoorTilePrefabs);
        wallLayerTiles[crossX, doorY] = RandomizeTile(horizontalDoorTilePrefabs);
        worldObjectLayer[0, 1]        = prefabs.cameraPrefab;
        worldObjectLayer[5, 5]        = prefabs.enginePrefab;
        worldObjectLayer[2, 3]        = serverPrefab;
        //worldObjectLayer[3, 4] = prefabs.enginePrefab;
        //instantiating tiles
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                Coords2 coords = new Coords2(x, y);

                GameObject floorToInstantiate = floorLayerTiles[x, y];
                map.CreateFloorTile(coords, floorToInstantiate);

                GameObject wallToInstantiate = wallLayerTiles[x, y];
                if (wallToInstantiate != null)
                {
                    map.CreateWallTile(coords, wallToInstantiate);
                }

                GameObject worldObjectToInstantiate = worldObjectLayer[x, y];
                if (worldObjectToInstantiate != null)
                {
                    CameraObjectController cameraController = map.CreateWorldObject(new Coords2(x, y), worldObjectToInstantiate).GetComponent <CameraObjectController>();
                    if (cameraController != null)
                    {
                        cameraController.SetOrigin(coords, new Vector2(x + 1.2f, y + 0.5f));
                        cameraController.SetAnchor(new Vector2(x + 0.5f, y - 0.2f));
                        cameraController.RotateAroundOrigin(45.0f);
                        cameraController.SetEnabled(coords, false);
                    }
                }
            }
        }

        //

        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                GameObject floorToInstantiate = floorLayerTiles[x, y];
                map.CreateFloorTile(new Coords2(x, y), floorToInstantiate);

                GameObject wallToInstantiate = wallLayerTiles[x, y];
                if (wallToInstantiate != null)
                {
                    map.CreateWallTile(new Coords2(x, y), wallToInstantiate);
                }
            }
        }
    }