示例#1
0
        /// <summary>
        /// Sets a cell at the given cell coordinates.
        /// </summary>
        public void SetCell(int x, int y, int z, CellMaterial material, sbyte density)
        {
            Chunk chunk;
            var   coord = new Vector3int16(RoundDownDivide(x, ChunkSize), RoundDownDivide(y, ChunkSize),
                                           RoundDownDivide(z, ChunkSize));

            lock (Locker)
            {
                if (!_chunks.TryGetValue(coord, out chunk))
                {
                    chunk          = new Chunk(this, coord);
                    _chunks[coord] = chunk;
                }
            }

            chunk[
                Math.Abs(x % ChunkSize),
                Math.Abs(y % ChunkSize),
                Math.Abs(z % ChunkSize)] = new Cell(material, density);

            if (chunk.OccupiedCells == 0)
            {
                _chunks.TryRemove(coord);
            }
        }
示例#2
0
            public Cell(CellMaterial material, sbyte density)
            {
                Material = material;

                if (material == CellMaterial.Air)
                {
                    density = 0;
                }

                Density = density;
            }
示例#3
0
 /// <summary>
 /// Fills a region of terrain.
 /// </summary>
 /// <param name="region">The region to fill.</param>
 /// <param name="material">The material for each cell.</param>
 /// <param name="density">The density for each cell.</param>
 public void FillRegion(Region3int16 region, CellMaterial material, sbyte density)
 {
     Parallel.For(region.Min.x, region.Max.x, x =>
     {
         for (short y = region.Min.y; y < region.Max.y; y++)
         {
             for (short z = region.Min.z; z < region.Max.z; z++)
             {
                 SetCell(x, y, z, material, density);
             }
         }
     });
 }
示例#4
0
    public void SetMaterial(GameObject prefab)
    {
        if (this._materialGO != null)
        {
            GameObject.Destroy(this._materialGO);
        }
        // spawn material prefab (visualization + values)
        this._materialGO = Instantiate(prefab);
        this._materialGO.transform.parent        = transform;
        this._materialGO.transform.localPosition = new Vector3(0, 0.1f, 0);

        materialType = this._materialGO.GetComponent <CellMaterial>();
        materialSet  = true;
    }
示例#5
0
 private void SetCell(Vector3int16 cellPos, CellMaterial material, sbyte density)
 {
     SetCell(cellPos.x, cellPos.y, cellPos.z, material, density);
 }
示例#6
0
文件: Cell.cs 项目: Spierek/FireSim
    public void SetMaterial(GameObject prefab)
    {
        if(this._materialGO != null)
        {
            GameObject.Destroy(this._materialGO);
        }
        // spawn material prefab (visualization + values)
        this._materialGO = Instantiate(prefab);
        this._materialGO.transform.parent = transform;
        this._materialGO.transform.localPosition = new Vector3(0, 0.1f, 0);

        materialType = this._materialGO.GetComponent<CellMaterial>();
        materialSet = true;
    }