protected override JobHandle OnUpdate(JobHandle inputDeps) { // Animate the head and tail var headJob = new HeadJob() { positions = SpineSystem.Instance.positions, rotations = SpineSystem.Instance.rotations, speeds = BoidJobSystem.Instance.speeds, dT = Time.deltaTime * bootstrap.speed, amplitude = bootstrap.headAmplitude, frequency = bootstrap.animationFrequency, size = bootstrap.size }; var headHandle = headJob.Schedule(this, inputDeps);// Animate the head and tail var tailJob = new TailJob() { positions = SpineSystem.Instance.positions, rotations = SpineSystem.Instance.rotations, speeds = BoidJobSystem.Instance.speeds, dT = Time.deltaTime * bootstrap.speed, amplitude = bootstrap.tailAmplitude, frequency = bootstrap.animationFrequency, size = bootstrap.size }; return(tailJob.Schedule(this, headHandle)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { // Copy entities to the native arrays var ctj = new CopyTransformsToJob() { positions = this.positions, rotations = this.rotations }; var ctjHandle = ctj.Schedule(this, inputDeps); // Count Neigthbours var cnj = new CountNeighboursJob() { positions = this.positions, rotations = this.rotations, neighbours = this.neighbours, maxNeighbours = this.maxNeighbours, neighbourDistance = bootstrap.neighbourDistance }; var cnjHandle = cnj.Schedule(this, ctjHandle); var seperationJob = new SeperationJob() { positions = this.positions, maxNeighbours = this.maxNeighbours, neighbours = this.neighbours, weight = bootstrap.seperationWeight }; var sjHandle = seperationJob.Schedule(this, cnjHandle); var alignmentJob = new AlignmentJob() { positions = this.positions, rotations = this.rotations, maxNeighbours = this.maxNeighbours, neighbours = this.neighbours, weight = bootstrap.alignmentWeight }; var ajHandle = alignmentJob.Schedule(this, sjHandle); var cohesionJob = new CohesionJob() { positions = this.positions, maxNeighbours = this.maxNeighbours, neighbours = this.neighbours, weight = bootstrap.cohesionWeight }; var cjHandle = cohesionJob.Schedule(this, ajHandle); var ran = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(1, 100000)); var wanderJob = new WanderJob() { dT = Time.deltaTime * bootstrap.speed, random = ran, weight = bootstrap.wanderWeight }; var wjHandle = wanderJob.Schedule(this, cjHandle); var constrainJob = new ConstrainJob() { positions = this.positions, centre = bootstrap.transform.position, radius = bootstrap.radius, weight = bootstrap.constrainWeight }; var constrainHandle = constrainJob.Schedule(this, wjHandle); var fleeJob = new FleeJob() { positions = this.positions, enemyPos = Camera.main.transform.position, distance = bootstrap.fleeDistance, weight = bootstrap.fleeWeight }; var fleeHandle = fleeJob.Schedule(this, constrainHandle); // Integrate the forces var boidJob = new BoidJob() { positions = this.positions, rotations = this.rotations, speeds = this.speeds, dT = Time.deltaTime * bootstrap.speed, damping = 0.01f, banking = 0.00f }; var boidHandle = boidJob.Schedule(this, fleeHandle); // Animate the head and tail var headJob = new HeadJob() { positions = this.positions, rotations = this.rotations, speeds = this.speeds, dT = Time.deltaTime * bootstrap.speed, amplitude = bootstrap.headAmplitude, frequency = bootstrap.animationFrequency, size = bootstrap.size }; var headHandle = headJob.Schedule(this, boidHandle);// Animate the head and tail var tailJob = new TailJob() { positions = this.positions, rotations = this.rotations, speeds = this.speeds, dT = Time.deltaTime * bootstrap.speed, amplitude = bootstrap.tailAmplitude, frequency = bootstrap.animationFrequency, size = bootstrap.size }; var tailHandle = tailJob.Schedule(this, headHandle); // Copy back to the entities var cfj = new CopyTransformsFromJob() { positions = this.positions, rotations = this.rotations }; return(cfj.Schedule(this, tailHandle)); }