private void ResetSelection() { if (_selectionList.IsEmpty) { return; } JobHandle unselectJob = new SetSelectionJob { selectionList = _selectionList, select = false, parallelWriter = _ecbSystem.CreateCommandBuffer() .AsParallelWriter() }.Schedule(_selectionList, 1); JobHandle clearSelectionJob = new ClearSelectionJob { selectionList = _selectionList }.Schedule(unselectJob); _selectionJobHandle = JobHandle.CombineDependencies( Dependency, unselectJob, clearSelectionJob ); }
private void OnWideSelection(float3 startPos, float3 endPos) { var upperBound = new float3( math.max(startPos.x, endPos.x), 0f, math.min(startPos.z, endPos.z) ); var lowerBound = new float3( math.min(startPos.x, endPos.x), 0f, math.max(startPos.z, endPos.z) ); BlobAssetReference <Collider> collider = RaycastUtils.GetBoxCollider( upperBound, lowerBound, new CollisionFilter { BelongsTo = ~0u, CollidesWith = (uint)CollisionLayer.Grid, GroupIndex = 0 } ); var maxNewElements = _selectionList.Length * 2 + 1; var hits = new NativeList <ColliderCastHit>(Allocator.TempJob); var hitEntities = new NativeList <Entity>(Allocator.TempJob); var entitiesToAdd = new NativeList <Entity>(maxNewElements, Allocator.TempJob) { Length = maxNewElements }; var entitiesToRemove = new NativeList <Entity>(maxNewElements, Allocator.TempJob) { Length = maxNewElements }; var totalEntities = new NativeList <Entity>(Allocator.TempJob); JobHandle boxCastJob = new RaycastUtils.ColliderCastJob { physicsWorld = _physicsWorld, hits = hits, origin = upperBound / 2f + lowerBound / 2f, collider = collider }.Schedule(_physicsSystem.GetOutputDependency()); var boxCastDep = JobHandle.CombineDependencies( Dependency, _physicsSystem.GetOutputDependency(), boxCastJob ); JobHandle convertJob = new ConvertHitsToEntitiesJob { hits = hits, hitEntities = hitEntities, selectionList = _selectionList, totalEntities = totalEntities }.Schedule(boxCastDep); var convertDep = JobHandle.CombineDependencies(boxCastDep, convertJob); hits.Dispose(convertDep); JobHandle getSelectionDiffJob = new GetSelectionDiffJob { totalEntities = totalEntities, selectionList = _selectionList, hitEntities = hitEntities, entitiesToAdd = entitiesToAdd, entitiesToRemove = entitiesToRemove }.Schedule(totalEntities, 1, convertDep); var getSelectionDiffDep = JobHandle.CombineDependencies( convertDep, getSelectionDiffJob ); hitEntities.Dispose(getSelectionDiffDep); totalEntities.Dispose(getSelectionDiffDep); JobHandle selectJob = new SetSelectionJob { selectionList = entitiesToAdd, select = true, parallelWriter = _ecbSystem.CreateCommandBuffer() .AsParallelWriter() }.Schedule(entitiesToAdd, 1, getSelectionDiffDep); JobHandle unselectJob = new SetSelectionJob { selectionList = entitiesToRemove, select = false, parallelWriter = _ecbSystem.CreateCommandBuffer() .AsParallelWriter() }.Schedule(entitiesToRemove, 1, getSelectionDiffDep); var selectionJobDep = JobHandle.CombineDependencies( getSelectionDiffDep, selectJob, unselectJob ); JobHandle updateSelectionJob = new UpdateSelectionJob { selectionList = _selectionList, entitiesToAdd = entitiesToAdd, entitiesToRemove = entitiesToRemove }.Schedule(selectionJobDep); var updateSelectionDep = JobHandle.CombineDependencies( selectionJobDep, updateSelectionJob ); entitiesToAdd.Dispose(updateSelectionDep); entitiesToRemove.Dispose(updateSelectionDep); _selectionJobHandle = updateSelectionDep; }