70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using Unity.Collections;
|
|
using Unity.Jobs;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
using Random = Unity.Mathematics.Random;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class CropsChunkMeshGenerator : GrassChunkMeshGeneratorBase<CropsGrassTileMask>
|
|
{
|
|
public CropsChunkMeshGenerator(World world, GameConfig config) : base(world, config)
|
|
{
|
|
}
|
|
|
|
protected override int GetLodCount()
|
|
{
|
|
return Config.Terrain.CropsLODs.Length;
|
|
}
|
|
|
|
protected override string GetGameObjectName(string chunkName, int2 chunkCoords, int lod)
|
|
{
|
|
return $"{chunkName}_Crops_LOD{lod}";
|
|
}
|
|
|
|
protected override void InitializeChunk(TerrainChunk chunk, int lod, GameObject gameObject, Mesh mesh, Renderer renderer)
|
|
{
|
|
base.InitializeChunk(chunk, lod, gameObject, mesh, renderer);
|
|
|
|
chunk.CropsLODs[lod] = new TerrainChunk.RenderData(mesh, renderer);
|
|
}
|
|
|
|
protected override Mesh GetMesh(TerrainChunk chunk, int lod)
|
|
{
|
|
return chunk.CropsLODs[lod].Mesh;
|
|
}
|
|
|
|
protected override JobHandle ScheduleJob(ChunkGenerationJobState jobState, NativeArray<int2> chunkCoords, NativeArray<Random> randomArray)
|
|
{
|
|
var job = new GenerateGrassChunkJob<CropsGrassTileMask>();
|
|
PrepareJob(jobState, chunkCoords, randomArray, jobState.Lod, ref job);
|
|
return job.Schedule(chunkCoords.Length, Config.WorldGen.ChunksPerThread);
|
|
}
|
|
|
|
protected override Renderer GetRenderer(TerrainChunk chunk, int lod)
|
|
{
|
|
return chunk.CropsLODs[lod].Renderer;
|
|
}
|
|
|
|
protected override Material GetMaterial(int lod)
|
|
{
|
|
return Config.Terrain.CropsMaterial;
|
|
}
|
|
|
|
protected override GameConfig.WorldGenConfig.GrassConfig GetGrassGenerationConfig()
|
|
{
|
|
return Config.WorldGen.Crops;
|
|
}
|
|
|
|
protected override CropsGrassTileMask GetMask()
|
|
{
|
|
var fertility = World.Fertility.GetNativeArray();
|
|
return new CropsGrassTileMask { Fertility = fertility };
|
|
}
|
|
|
|
protected override int GetDensityForLOD(int lod)
|
|
{
|
|
return Config.Terrain.CropsLODs[lod].Density;
|
|
}
|
|
}
|
|
} |