void Update() { float deltaTime = Time.fixedDeltaTime; float3 deltaGravity = deltaTime * GRAVITY; float damping = .98f; int batchSize = (int)Mathf.Pow(2, JOB_SIZE_POWER_OF_TWO); int count = atoms.Length; copyPositionFromTransformJob = new CopyPositionFromTransform { positions = positions }; applyExternalForcesJob = new ApplyExternalForces { damping = damping, deltaGravity = deltaGravity, velocities = velocities }; estimatePositionJob = new EstimatePosition { deltaTime = deltaTime, velocities = velocities, positions = positions, predicteds = predicteds }; runSolverJob = new RunSolver { iterationCount = ITERATION_COUNT, restPositions = restPositions, predicteds = predicteds, positionConstraints = positionConstraints, distanceConstraints = distanceConstraints, shapeConstraints = shapeConstraints }; updateVelocityJob = new UpdateVelocity { deltaTime = deltaTime, velocities = velocities, positions = positions, predicted = predicteds }; updatePositionJob = new UpdatePosition { deltaTime = deltaTime, positions = positions, predicteds = predicteds }; copyPositionToTransformJob = new CopyPositionToTransform { positions = positions }; copyPositionFromTransformJobHandle = copyPositionFromTransformJob.Schedule(transformAccessArray); applyExternalForcesJobHandle = applyExternalForcesJob.Schedule(count, batchSize); estimatePositionJobHandle = estimatePositionJob.Schedule(count, batchSize, JobHandle.CombineDependencies(applyExternalForcesJobHandle, copyPositionFromTransformJobHandle)); runSolverJobHandle = runSolverJob.Schedule(estimatePositionJobHandle); updateVelocityJobHandle = updateVelocityJob.Schedule(count, batchSize, runSolverJobHandle); updatePositionJobHandle = updatePositionJob.Schedule(count, batchSize, updateVelocityJobHandle); copyPositionToTransformJobHandle = copyPositionToTransformJob.Schedule(transformAccessArray, updatePositionJobHandle); }
void LateUpdate() { handle.Complete(); // Raycastの開始点と位置を設定 for (int i = 0; i < transformArray.length; i++) { var targetPosition = transformArray[i].position; var direction = Vector3.down; var command = new RaycastCommand(targetPosition, direction); commands[i] = command; } // 移動のコマンドを設定 var updatePositionJob = new UpdateVelocity() { velocitys = velocity }; var applyPosition = new ApplyPosition() { velocitys = velocity }; // 並列処理を実行(即完了待ち) // 終わったらコマンドに使ったバッファは不要なので破棄 handle = RaycastCommand.ScheduleBatch(commands, results, 20); handle = hitCheckJob.Schedule(transformArray.length, 20, handle); handle = new ReflectionJob { velocitys = velocity, result = hitQueue }.Schedule(handle); handle = updatePositionJob.Schedule(transformArray.length, 20, handle); handle = applyPosition.Schedule(transformArray, handle); handle.Complete(); }