public void AddJob(Vector3 location, float effectIncrement, float radiusOfEffect, float duration, float falloff) { TerrainJob newJob = new TerrainJob(location, effectIncrement, radiusOfEffect, duration, falloff); newJob.timeAtCreation = Time.time; jobs.Add(newJob); }
JobHandle CreateTerrain(int xOffset, int yOffset, int width, int height, float seaLevel, TerrainDisplayMode terrainDisplayMode) { vertices = new NativeArray <Vector3>((width + 1) * (height + 1), Allocator.TempJob); colors = new NativeArray <Color>((width + 1) * (height + 1), Allocator.TempJob); TerrainJob terrainJob = new TerrainJob() { width = width + 1, height = height + 1, xOffset = xOffset, zOffset = yOffset, masterScale = masterScale, precipitationScale = precipitationScale, temperatureScale = temperatureScale, seaLevel = seaLevel, blending = blending, terrainDisplayMode = terrainDisplayMode, vertices = vertices, colors = colors }; JobHandle jobHandle = terrainJob.Schedule(vertices.Length, 32); return(jobHandle); }
void UpdateJobs() { int numJobs = jobs.Count; if (numJobs > 0) { if (numJobs == 1) { TerrainJob thisJob = jobs[0]; float jobLifetime = (Time.time - thisJob.timeAtCreation); if (jobLifetime >= thisJob.Duration) { jobs.Remove(thisJob); } else { thisJob.lifeTime = jobLifetime; ProcessJob(thisJob); } } // Round robin method handles jobs one-at-a-time else if (jobIndex <= (numJobs - 1)) { TerrainJob thisJob = jobs[jobIndex]; float jobLifetime = (Time.time - thisJob.timeAtCreation); if (jobLifetime >= thisJob.Duration) { jobs.Remove(thisJob); } else { thisJob.lifeTime = jobLifetime; ProcessJob(thisJob); } jobIndex++; if (jobIndex >= numJobs) { jobIndex = 0; } } } }
public TerrainData(Vector3 centerPoint, Arm.Annotations.CAM.CAMTrack track, TerrainController parent) { completed = false; deleted = false; this.track = track; this.channel = parent.terrainControllerChannel; obj = new GameObject(); obj.name = "Terrain " + centerPoint.ToString(); obj.AddComponent <MeshFilter>(); MeshRenderer mr = obj.AddComponent <MeshRenderer>(); mr.sharedMaterials = parent.sharedMaterials; Mesh m = new Mesh(); m.subMeshCount = 3; obj.GetComponent <MeshFilter>().mesh = m; job = new TerrainJob(centerPoint, parent); jobHandle = job.Schedule(); }
void ProcessJob(TerrainJob job) { if (bOffBeat) { rayBeam = job.Location - rayOrigin; hits = Physics.RaycastAll(rayOrigin, rayBeam); effectStrength = job.EffectIncrement; int numHits = hits.Length; if (numHits > 0) { for (int i = 0; i < numHits; i++) { if (hits[i].transform.CompareTag("Land")) { RaiseMesh(hits[i].point, effectStrength * Time.smoothDeltaTime, job.radius, job.RadiusFalloff); } } } } bOffBeat = !bOffBeat; }