Beispiel #1
0
    // Generate "random" Biomes for the alphamap, based on Perlin noise
    private void generateBiomes()
    {
        // Create the layers with the right texture for each biome
        Dictionary <Biome, Texture2D> layers = GetLayers();

        LayersHelper layersHelper = new LayersHelper(GameSettings.terrainAlphamapRes, layers);

        terrainData.terrainLayers = layersHelper.GetTerrainLayers();

        // Gnenerate an terrainData.heigthMap using Perlin Noise

        generateHeightsMap();

        // Map the terrain to layers according to biomes (based on altitude, temperature & humidity)
        BiomeHelper  biomes = new BiomeHelper(this);
        TerrainTiles tiles  = new TerrainTiles(biomes);

        Biome biome;
        int   hmx, hmz;
        float height;
        float jitter = 1f / GameSettings.terrainAlphamapRes;

        float[,] flatHeight = new float[1, 1];
        flatHeight[0, 0]    = 0.5f;
        for (int z = 0; z < GameSettings.terrainAlphamapRes; z++)
        {
            for (int x = 0; x < GameSettings.terrainAlphamapRes; x++)
            {
                hmx    = (int)(x * GameSettings.factor_h2a);
                hmz    = (int)(z * GameSettings.factor_h2a);
                height = terrainData.GetHeight(hmx, hmz) / GameSettings.terrainMaxAltitude;

                var pos = new Vector2Int(x, z);
                biome = biomes.GetBiomeAt(pos, height);

                layersHelper.SetAt(x, z, biome);

                if (height < flatHeight[0, 0])
                {
                    height = flatHeight[0, 0];
                    // Flaten the low lands, to get to ~50% of flat areas (easier to build on)
                    terrainData.SetHeights(hmx, hmz, flatHeight);
                }

                // Create a tile (at alphamap location) with items on it according to it's biome
                tiles.AddTile(pos, height, biome);
            }
        }
        terrainData.SetAlphamaps(0, 0, layersHelper.GetAlphaMaps());
    }
Beispiel #2
0
        private void RpcInstantiateWeaponOnClients(string weaponName)
        {
            if (weaponName == null)
            {
                return;
            }

            GameObject newWeapon = Instantiate(WeaponsResourceManager.GetWeapon(weaponName).baseWeaponPrefab,
                                               weaponsHolderSpot);

            if (isLocalPlayer)
            {
                LayersHelper.SetLayerRecursively(newWeapon, LayerMask.NameToLayer(weaponLayerName));
            }
        }
Beispiel #3
0
        private void Start()
        {
            //Create all existing weapons on start
            for (int i = 0; i < weapons.Count; i++)
            {
                GameObject newWeapon =
                    Instantiate(WeaponsResourceManager.GetWeapon(weapons[i].Weapon).baseWeaponPrefab,
                                weaponsHolderSpot);

                if (isLocalPlayer)
                {
                    LayersHelper.SetLayerRecursively(newWeapon, LayerMask.NameToLayer(weaponLayerName));
                }

                newWeapon.SetActive(SelectedWeaponIndex == i);
            }
        }
        private static void CreateArea(MenuCommand command)
        {
            var ambianceArea = new GameObject("Ambiance Volume", typeof(AmbianceArea));

            LayersHelper.SetOnLayer(ambianceArea, "Audio");

            var parent = command.context as GameObject;

            if (parent != null)
            {
                ambianceArea.transform.SetParent(parent.transform);
                ambianceArea.transform.localPosition = Vector3.zero;
                ambianceArea.transform.localRotation = Quaternion.identity;
                ambianceArea.transform.localScale    = Vector3.one;
            }

            Selection.activeGameObject = ambianceArea;
        }