protected override void OnUpdate() { var query = GetEntityQuery(typeof(SquadTagSharedComponentData), typeof(SquadComponentData), typeof(LerpShootTargetProvederComponentData), typeof(ArcherTargetPositionComponentData)); var chunkCount = query.CalculateChunkCount(); var sharedIndicesMap = new NativeHashMap <int, int>(chunkCount, Allocator.TempJob); var indicesJobH = new SharedIndicesJob() { indices = sharedIndicesMap.AsParallelWriter(), squadTagType = GetArchetypeChunkSharedComponentType <SquadTagSharedComponentData>() }.Schedule(query); var sharedData = new NativeHashMap <int, SquadFormationData>(chunkCount, Allocator.TempJob); indicesJobH.Complete(); var indices = sharedIndicesMap.GetKeyArray(Allocator.TempJob); for (int i = 0; i < indices.Length; i++) { var data = EntityManager.GetSharedComponentData <SquadTagSharedComponentData>(indices[i]); sharedData.TryAdd(indices[i], new SquadFormationData() { yUnitCount = data.data.heightUnitsCount, xUnitCount = data.unitCount.value / data.data.heightUnitsCount + (data.unitCount.value % data.data.heightUnitsCount == 0 ? 0 : 1), bot2top = data.data.directionBottomToTop, left2right = data.data.directionLeftToRight }); } var setTargetJobH = new SetTargetJob() { sharedData = sharedData, squadTagType = GetArchetypeChunkSharedComponentType <SquadTagSharedComponentData>(), squadType = GetArchetypeChunkComponentType <SquadComponentData>(true), targetProviderType = GetArchetypeChunkComponentType <LerpShootTargetProvederComponentData>(true), targetTypr = GetArchetypeChunkComponentType <ArcherTargetPositionComponentData>(false), rnd = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(0, int.MaxValue)) }.Schedule(query); setTargetJobH.Complete(); indices.Dispose(); sharedData.Dispose(); sharedIndicesMap.Dispose(); }
protected override void OnUpdate() { var query = GetEntityQuery( typeof(ArcherTagComponentData), typeof(SquadProjectileLaunchDataSharedComponentData), typeof(Translation), typeof(Scale), typeof(ActionOnAnimationFrameComponentData), typeof(ArcherTargetPositionComponentData) ); var sharedIndices = new NativeHashMap <int, int>(query.CalculateChunkCount(), Allocator.TempJob); var detectedActions = new NativeMultiHashMap <int, ShootData>(query.CalculateEntityCount(), Allocator.TempJob); var sharedIndicesJH = new SharedIndicesJob() { launchType = GetArchetypeChunkSharedComponentType <SquadProjectileLaunchDataSharedComponentData>(), sharedIndices = sharedIndices.AsParallelWriter() }.Schedule(query); var detectActionsJH = new DetectActionSquadJob() { detectedActions = detectedActions.AsParallelWriter(), launchType = GetArchetypeChunkSharedComponentType <SquadProjectileLaunchDataSharedComponentData>(), actionType = GetArchetypeChunkComponentType <ActionOnAnimationFrameComponentData>(true), scaleType = GetArchetypeChunkComponentType <Scale>(true), targetType = GetArchetypeChunkComponentType <ArcherTargetPositionComponentData>(true), translationType = GetArchetypeChunkComponentType <Translation>(true) }.Schedule(query); sharedIndicesJH.Complete(); var indices = sharedIndices.GetKeyArray(Allocator.TempJob); detectActionsJH.Complete(); for (int i = 0; i < indices.Length; i++) { var sharedData = EntityManager.GetSharedComponentData <SquadProjectileLaunchDataSharedComponentData>(indices[i]).data; if (sharedData == null) { throw new ArgumentNullException($"null data of SquadProjectileLaunchDataSharedComponentData"); } var sprite = sharedData.spriteData; var animation = sharedData.animaionData; var collision = sharedData.collisionData; var render = sharedData.renderData; var scale = sharedData.renderScaleData; detectedActions.IterateForKey(indices[i], (detect) => { var launch = sharedData.launchData; launch.targetPosition = detect.targetPosition; launch.targetWidth *= detect.ownerScale; LaunchProjectileSystem.Instance.LaunchArrow( detect.ownerPosition, detect.ownerScale, launch, animation, sprite, render, collision, scale, sharedData.castShadows, sharedData.shadowSettings, sharedData.calcShadowsShifts ); }); } indices.Dispose(); sharedIndices.Dispose(); detectedActions.Dispose(); }