Exemple #1
0
        private void AdjustPlane(IEnumerable <Vector3Int> planeDirection)
        {
            bool toAdd = false;

            foreach (Vector3Int nextCoordinate in planeDirection)
            {
                // Remove voxels in the negative X-direction
                if (toAdd == false)
                {
                    if (CreatedVoxels.ContainsKey(nextCoordinate) == true)
                    {
                        PoolingManager.ReturnToPool(CreatedVoxels[nextCoordinate]);
                        CreatedVoxels.Remove(nextCoordinate);
                    }
                    if (CreatedCollectables.ContainsKey(nextCoordinate) == true)
                    {
                        PoolingManager.ReturnToPool(CreatedCollectables[nextCoordinate]);
                        CreatedCollectables.Remove(nextCoordinate);
                    }
                }
                else if (toAdd == true)
                {
                    // Add voxels in the positive X-direction
                    AddVoxel(nextCoordinate);
                }
                toAdd = !toAdd;
            }
        }
Exemple #2
0
        private Voxel AddVoxel(Vector3Int pos)
        {
            if (pos.sqrMagnitude <= 4)
            {
                return(null);
            }

            // Calculate position
            Vector3 offsetCoordinate = pos - initialPosition;

            offsetCoordinate *= noiseCoordinate;

            // Grab a voxel
            float perlinNoise = Perlin.Noise(offsetCoordinate);
            Voxel instance = null, prefab = GetVoxel(perlinNoise);

            if (prefab != null)
            {
                // Calculate color noise
                offsetCoordinate  = pos - colorPosition;
                offsetCoordinate *= colorNoiseCoordinate;
                perlinNoise       = Perlin.Noise(offsetCoordinate);
                perlinNoise       = Mathf.Repeat(perlinNoise, 1);

                // Grab an instance of the voxel
                instance            = Singleton.Get <PoolingManager>().GetInstance <Voxel>(prefab);
                instance.VoxelColor = Color.Lerp(lowerVoxelColors.Evaluate(perlinNoise), upperVoxelColors.Evaluate(perlinNoise), Random.value);
                CreatedVoxels.Add(pos, instance);

                // Position the voxel
                instance.transform.position = pos;
            }

            if (Random.value < collectableProbability)
            {
                // Grab an instance of a collectable
                Collectable randomCollectablePrefab = allCollectables[Random.Range(0, allCollectables.Length)];
                Collectable collectableInstance     = Singleton.Get <PoolingManager>().GetInstance <Collectable>(randomCollectablePrefab);
                collectableInstance.Logs = history;
                CreatedCollectables.Add(pos, collectableInstance);

                // Position the voxel
                collectableInstance.transform.position = pos;
            }
            return(instance);
        }