public void Update() { m_GenPointCloudJob = new GeneratePointCloudJob() { pointCloud = m_PointCloud, center = Random.insideUnitSphere * 2, radius = k_PointCloudRadius }; m_DistancesJob = new CalculateDistancesJob() { points = m_PointCloud, squareMagnitudes = m_SquareMagnitudes }; m_NormalizeJob = new NormalizationJob() { points = m_PointCloud, normalizedPoints = m_NormalizedPointCloud, }; m_GeneratePointsJobHandle = m_GenPointCloudJob.Schedule(m_PointCloud.Length, 64); m_DistancesJobHandle = m_DistancesJob.Schedule(m_PointCloud.Length, 64, m_GeneratePointsJobHandle); m_NormalizeJobHandle = m_NormalizeJob.Schedule(m_PointCloud.Length, 64, m_GeneratePointsJobHandle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!m_ScatterSystem.ShouldGenerateTile) { return(inputDeps); } var scatterSingletonQuery = GetEntityQuery(typeof(ProceduralScatterPrefab)); var scatterSingleton = scatterSingletonQuery.GetSingletonEntity(); // Unload { var unloadCounter = (_Counter + (_MaxDim * _MaxDim / 2) + 7) % (_MaxDim * _MaxDim); var unloadTile = new int3((unloadCounter % _MaxDim), 0, (unloadCounter / _MaxDim)); m_ScatterSystem.UnloadTile(unloadTile, scatterSingleton); } // Generate { var tile = new int3((_Counter % _MaxDim), 0, (_Counter / _MaxDim)); var job = new GeneratePointCloudJob(); job.TileOffset = (float3)tile * _TileSize; job.TileSize = _TileSize; job.Instances = new NativeList <ProceduralInstanceData>(0, Allocator.TempJob); job.ScatterSettings = new NativeArray <TrivialScatterPrefabSettings>(EntityManager.GetBuffer <TrivialScatterPrefabSettings>(scatterSingleton).AsNativeArray(), Allocator.TempJob); var genJob = job.Schedule(); m_ScatterSystem.GenerateTileAsync(tile, scatterSingleton, job.Instances, genJob); } _Counter++; if (_Counter >= _MaxDim * _MaxDim) { _Counter = 0; } return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!m_ScatterSystem.ShouldGenerateTile) { return(inputDeps); } var scatterSingletonQuery = GetComponentGroup(typeof(ProceduralScatterPrefab)); var scatterSingleton = scatterSingletonQuery.GetSingletonEntity(); var tile = new int3((counter % maxDim), 0, (counter / maxDim)); var job = new GeneratePointCloudJob(); job.TileOffset = (float3)tile * tileSize; job.TileSize = tileSize; //@TODO: Background temp job job.Instances = new NativeList <ProceduralInstanceData>(0, Allocator.Persistent); job.ScatterSettings = new NativeArray <TrivialScatterPrefabSettings>(EntityManager.GetBuffer <TrivialScatterPrefabSettings>(scatterSingleton).AsNativeArray(), Allocator.TempJob); var genJob = job.Schedule(); m_ScatterSystem.GenerateTileAsync(tile, scatterSingleton, job.Instances, genJob); // Unload var unloadCounter = (counter + (maxDim * maxDim / 2) + 7) % (maxDim * maxDim); var unloadTile = new int3((unloadCounter % maxDim), 0, (unloadCounter / maxDim)); m_ScatterSystem.UnloadTile(unloadTile); counter++; if (counter >= maxDim * maxDim) { counter = 0; } return(inputDeps); }