Example #1
0
        public void Spawn()
        {
            GameObject tileAtPos = TerrainManager.instance.GetTileAtPosition(tilePos.ToVector2());
            Vector3    spawnPos  = new Vector3(tilePos.x, tileAtPos.transform.position.y, tilePos.y);
            Island     island    = tileAtPos.transform.parent.GetComponent <Island>();

            for (int i = 0; i < stackHeight; i++)
            {
                switch (pickupType)
                {
                case 0:
                    TerrainManager.instance.SpawnResource(spawnPos, ResourceInfo.GetInfoFromIndex(index), island);
                    break;

                case 1:
                    TerrainManager.instance.SpawnWeapon(spawnPos, WeaponInfo.GetInfoFromIndex(index), island);
                    break;

                case 2:
                    TerrainManager.instance.SpawnAugment(spawnPos, AugmentInfo.GetInfoFromIndex(index), island);
                    break;

                default:
                    Debug.LogError("Unrecognized pickup type");
                    break;
                }
            }
        }
Example #2
0
        public void Spawn()
        {
            ResourceInfo info = ResourceInfo.GetInfoFromIndex(resourceIndex);

            TerrainManager.Tile tile = TerrainManager.instance.tiles [tilePos.ToVector2()];

            tile.resourceType = info.type;
            tile.tile.GetComponent <Renderer> ().material.color = info.colorLight;
        }
Example #3
0
    void GenerateTiles()
    {
        tiles = new TerrainManager.Tile[tilePositions.Count];

        // void tiles
        voidTileIndexes = new List <int> ();
        for (int i = 0; i < voidCount; i++)
        {
            voidTileIndexes.Add(GetAvaiableTileIndex(true));
        }

        // resource tiles
        List <int> tileSpawnIDs = new List <int> ();

        foreach (var setSpawn in setSpawns)
        {
            if (setSpawn.type == TerrainManager.SetSpawn.SpawnType.Tile)
            {
                tileSpawnIDs.Add(setSpawn.spawnID);
            }
        }
        int tilesLeft = resourceTileCount - tileSpawnIDs.Count;

        for (int i = 0; i < tilesLeft; i++)
        {
            tileSpawnIDs.Add(teirInfo.resourceIndexes[Random.Range(0, teirInfo.resourceIndexes.Length)]);
//			print ("Index: " + i + ", ID: " + tileSpawnIDs [i]);
        }

        List <int> resourceTileSpawnIndexs = new List <int> ();

        for (int i = 0; i < tileSpawnIDs.Count; i++)
        {
            resourceTileSpawnIndexs.Add(GetAvaiableTileIndex(false));
        }

        int index = 0;
        int resourceSpawnListIndex = 0;

        foreach (Vector2 tile in tilePositions)
        {
            if (!voidTileIndexes.Contains(index))
            {
                int        layer    = Random.Range(0, teirInfo.layers.Length);
                float      y        = layer * heightPerLayer;
                Vector3    position = new Vector3(tile.x, y, tile.y);
                GameObject tileGO   = (GameObject)Instantiate(tilePrefab, transform);
                tileGO.transform.localPosition = position;
                tileGO.name = "Tile (" + tile.x + "," + tile.y + ")";

                ResourceInfo.ResourceType resourceInfoType;
                Color tileColor;

                ResourceInfo resourceInfo = new ResourceInfo();
                if (resourceTileSpawnIndexs.Contains(index) && !GameManager.isLoadingFromSave)
                {
                    int resourceIndex = tileSpawnIDs [resourceSpawnListIndex];
                    resourceSpawnListIndex++;

                    resourceInfo = ResourceInfo.GetInfoFromIndex(resourceIndex);



                    if (resourceInfo.hasTile)
                    {
                        resourceInfoType = resourceInfo.type;
                        tileColor        = resourceInfo.tileColor;
                    }
                    else
                    {
                        resourceInfoType = ResourceInfo.ResourceType.None;
                        tileColor        = teirInfo.layers [layer].color;
                    }
                }
                else
                {
                    resourceInfoType = ResourceInfo.ResourceType.None;
                    tileColor        = teirInfo.layers [layer].color;
                }

                TerrainManager.Tile tileInfo = new TerrainManager.Tile(tileGO, resourceInfoType, GetComponent <Island> (), tileColor, y);
                tileGO.GetComponent <MeshRenderer> ().material.color = tileColor;
                tiles [index] = tileInfo;
                if (!GameManager.isLoadingFromSave || !SavedGame.data.civilizedIslandIndexes.Contains(islandIndex))
                {
                    tm.tiles.Add(new Vector2(tile.x + transform.position.x, tile.y + transform.position.z), tileInfo);
                }

                if (resourceTileSpawnIndexs.Contains(index) && !GameManager.isLoadingFromSave)
                {
                    for (int i = 0; i < resourcesPerTile; i++)
                    {
                        tm.SpawnResource(position: transform.TransformPoint(position), info: resourceInfo, island: GetComponent <Island>(), initialSpawn: true);
                    }

                    if (tileInfo.resourceType != ResourceInfo.ResourceType.None)
                    {
                        SavedGame.AddResourceTile(tileInfo);
                    }
                }
            }

            index++;
        }
    }