示例#1
0
 public void AddVoxel(WaterVoxel voxel)
 {
     this.activeVoxels.Add(voxel);
     this.allVoxels.Add(voxel);
     voxel.Mass = this;
     voxel.transform.SetParent(this.transform);
 }
示例#2
0
    private void BecomeWaterVoxelMass()
    {
        WaterVoxelMass mass       = WaterVoxelManager.Instance.SpawnWaterVoxelMass();
        WaterVoxel     waterVoxel = WaterVoxelManager.Instance.SpawnWaterVoxel(this.transform.position);

        mass.AddVoxel(waterVoxel);
        ObjectPooler.Instance.Reclaim(this.gameObject);
    }
示例#3
0
    public void Grow()
    {
        List <WaterVoxel> newVoxels = new List <WaterVoxel>();

        foreach (WaterVoxel voxel in this.activeVoxels)
        {
            int count = 0;

            if (this.GrowToPosition((int)voxel.transform.position.x, (int)voxel.transform.position.z - WaterVoxelManager.Instance.VoxelSize, newVoxels, voxel))
            {
                count++;
            }
            if (this.GrowToPosition((int)voxel.transform.position.x, (int)voxel.transform.position.z + WaterVoxelManager.Instance.VoxelSize, newVoxels, voxel))
            {
                count++;
            }
            if (this.GrowToPosition((int)voxel.transform.position.x - WaterVoxelManager.Instance.VoxelSize, (int)voxel.transform.position.z, newVoxels, voxel))
            {
                count++;
            }
            if (this.GrowToPosition((int)voxel.transform.position.x + WaterVoxelManager.Instance.VoxelSize, (int)voxel.transform.position.z, newVoxels, voxel))
            {
                count++;
            }
        }

        if (newVoxels.Count == 0)
        {
            // Set activeVoxels to one new voxel above lowest position
            Vector3 lowestPosition = this.FindLowestPosition(this.activeVoxels);
            lowestPosition.y += WaterVoxelManager.Instance.VoxelSize;

            WaterVoxel newWaterVoxel = WaterVoxelManager.Instance.SpawnWaterVoxel(lowestPosition);
            this.activeVoxels.Clear();
            this.AddVoxel(newWaterVoxel);
        }
        else
        {
            this.activeVoxels.Clear();
            foreach (WaterVoxel voxel in newVoxels)
            {
                this.AddVoxel(voxel);
            }
        }
    }
示例#4
0
    private bool GrowToPosition(int x, int z, List <WaterVoxel> newVoxels, WaterVoxel voxel)
    {
        if (0 <= x && x <= 256 && 0 <= z && z <= 256)
        {
            float height = float.NaN;

            // no water here
            if (WaterVoxelManager.Instance.WaterHeight[x, z] < 0)
            {
                Vector3 terrainPos = new Vector3(x, 0, z);

                terrainPos.y = GameManager.Instance.GetTerrainHeight(terrainPos);

                if (terrainPos.y + WaterVoxelManager.Instance.VoxelSize < voxel.transform.position.y)
                {
                    height = terrainPos.y;
                }
                else if (terrainPos.y <= voxel.transform.position.y)
                {
                    height = voxel.transform.position.y;
                }
            }
            // there is VERY lower water here
            else if (WaterVoxelManager.Instance.WaterHeight[x, z] + WaterVoxelManager.Instance.VoxelSize < voxel.transform.position.y)
            {
                height = WaterVoxelManager.Instance.WaterHeight[x, z] + WaterVoxelManager.Instance.VoxelSize;
            }
            // there is low water here
            else if (WaterVoxelManager.Instance.WaterHeight[x, z] < voxel.transform.position.y)
            {
                height = voxel.transform.position.y;
            }

            if (!float.IsNaN(height))
            {
                WaterVoxel waterVoxel = WaterVoxelManager.Instance.SpawnWaterVoxel(new Vector3(x, height, z));

                WaterVoxelManager.Instance.WaterHeight[x, z] = height;
                newVoxels.Add(waterVoxel);

                return(true);
            }
        }
        return(false);
    }
示例#5
0
 public void RemoveVoxel(WaterVoxel voxel)
 {
     this.allVoxels.Remove(voxel);
     this.activeVoxels.Remove(voxel);
     voxel.Mass = null;
 }