public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(launchType); var translations = chunk.GetNativeArray(translationType); var scales = chunk.GetNativeArray(scaleType); var actions = chunk.GetNativeArray(actionType); var targets = chunk.GetNativeArray(targetType); for (int i = 0; i < chunk.Count; i++) { var action = actions[i]; if (!action.out_ActionFlag) { continue; } var shootData = new ShootData() { ownerPosition = translations[i].Value, ownerScale = scales[i].Value, targetPosition = targets[i].value, }; detectedActions.Add(index, shootData); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(squadTagType); var datas = chunk.GetNativeArray(squadDataType); var notSetIndicesCount = 0; for (int i = 0; i < chunk.Count; i++) { if (datas[i].indexOlreadySet) { indicesInSquadBySharedIndices.Add( index, datas[i].indexInSquad ); } else { notSetIndicesCount++; } } chunkCountDataBySharedIndex.Add( index, new ChunkSquadCountData() { chunkIndex = chunkIndex, entityCount = chunk.Count, sharedIndex = index, notSetIndicesCount = notSetIndicesCount } ); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var sharedComponentIndex = chunk.GetSharedComponentIndex(ChunkSharedComponentType); for (var i = 0; i < chunk.Count; ++i) { Indices[firstEntityIndex + i] = sharedComponentIndex; } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { int squadIndex = chunk.GetSharedComponentIndex(squadTagType); var es = chunk.GetNativeArray(entityType); for (int i = 0; i < es.Length; i++) { entities.Add(squadIndex, es[i]); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(squadTagType); SquadFormationData formationData; if (!squadTagMap.TryGetValue(index, out formationData)) { return; } var squadDatas = chunk.GetNativeArray(squadType); var moveDatas = chunk.GetNativeArray(moveType); var scaleDatas = new NativeArray <Scale>(); var hasScale = chunk.Has(scaleType); if (hasScale) { scaleDatas = chunk.GetNativeArray(scaleType); } for (int i = 0; i < chunk.Count; i++) { var move = moveDatas[i]; var scale = 1f; if (hasScale) { scale = scaleDatas[i].Value; } var squadData = squadDatas[i]; var rot = new float2( math.cos(math.radians(formationData.mainData.rotationDegrees)), math.sin(math.radians(formationData.mainData.rotationDegrees)) ); var shiftSC = new float2( math.cos(math.radians(formationData.mainData.horisontalShift * 2 + 90)), math.sin(math.radians(formationData.mainData.verticalShift * 2)) ); float2 indexPosInSquad; move.positionToMove = GetPositionInSquad( out indexPosInSquad, ref formationData, squadData.indexInSquad, scale, ref rnd, rot, shiftSC ); squadData.indexPositionInSquad = indexPosInSquad; squadDatas[i] = squadData; moveDatas[i] = move; } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(squadTagType); var animators = chunk.GetNativeArray(animatorType); var animations = chunk.GetNativeArray(animationType); for (int i = 0; i < chunk.Count; i++) { if (animators[i].shooting) { squadsPauses.Add(index, animations[i].pause); } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var sharedindex = chunk.GetSharedComponentIndex(squadTagType); SquadSortData sortData; if (!setIndicesDataByChunkIndex.TryGetValue(chunkIndex, out sortData)) { return; } var squadDatas = chunk.GetNativeArray(squadDataType); int addedCount = 0; int currentMapPosition = 0; NativeMultiHashMapIterator <int> iterator; int currentValue; if (!newIndicesBySharedIndex.TryGetFirstValue(sharedindex, out currentValue, out iterator)) { return; } while (currentMapPosition < sortData.startIndexInCourceArray && newIndicesBySharedIndex.TryGetNextValue(out currentValue, ref iterator)) { currentMapPosition++; } for (int i = 0; i < chunk.Count; i++) { var data = squadDatas[i]; if (data.indexOlreadySet) { continue; } data.indexInSquad = currentValue; data.indexOlreadySet = true; squadDatas[i] = data; addedCount++; if (addedCount < sortData.cntToAdd && newIndicesBySharedIndex.TryGetNextValue(out currentValue, ref iterator)) { currentMapPosition++; } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var random = new Unity.Mathematics.Random(RandomSeed); var index = chunk.GetSharedComponentIndex(SpriteAnimationChunkType); var spriteAnimation = UniqueSpriteAnimations[index]; var entities = chunk.GetNativeArray(EntityChunkType); var states = chunk.GetNativeArray(SpriteAnimationStateChunkType).GetUnsafePtr(); var randomizers = chunk.GetNativeArray(SpriteAnimationRandomizerChunkType); for (var i = 0; i < chunk.Count; ++i) { spriteAnimation.ClipIndex = random.NextInt(0, spriteAnimation.ClipCount); SpriteAnimationMap.TryAdd(entities[i], spriteAnimation); UnsafeUtilityEx.ArrayElementAsRef <SpriteAnimationState>(states, i).Speed = random.NextFloat(randomizers[i].RandomSpeedStart, randomizers[i].RandomSpeedEnd); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(squadTagType); if (!toResumeSquadsIndices.ContainsKey(index)) { return; } var pauses = chunk.GetNativeArray(pauseType); for (int i = 0; i < chunk.Count; i++) { var pause = pauses[i]; pause.needResume = true; pauses[i] = pause; } }
// [ReadOnly] public ArchetypeChunkEntityType EntityType; public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(BlackboardDataQueryType); if (index != BlackboardDataQueryIndex) { return; } // var entities = chunk.GetNativeArray(EntityType); var nodeBlobs = chunk.GetNativeArray(NodeBlobRefType); for (var i = 0; i < chunk.Count; i++) { Blackboard.Chunk = chunk; Blackboard.Index = i; // Blackboard.Entity = entities[i]; VirtualMachine.Tick(nodeBlobs[i], Blackboard); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkCount = chunk.Count; var chunkPositions = chunk.GetNativeArray(positions); var chunkSpeeds = chunk.GetNativeArray(speeds); var chunkUpdateOrderSharedIndex = chunk.GetSharedComponentIndex(updateOrderACSCT); var updateOrderData = updateOrdersNativeArray[chunkUpdateOrderSharedIndex]; if (updateOrderData.Value == updateOrder) { for (int i = 0; i < chunkCount; i++) { float3 prevPosition = chunkPositions[i].Value; float3 speed = chunkSpeeds[i].Value; chunkPositions[i] = new Translation { Value = prevPosition + new float3(0, 1, 0) * speed * dt * updateFrequency }; } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var sharedIndex = chunk.GetSharedComponentIndex(squadTagType); SquadFormationData data; if (!sharedData.TryGetValue(sharedIndex, out data)) { return; } if (data.xUnitCount == 0) { data.xUnitCount = 1; } if (data.yUnitCount == 0) { data.yUnitCount = 1; } data.xUnitCount += 2; data.yUnitCount += 2; var indices = chunk.GetNativeArray(squadType); var providers = chunk.GetNativeArray(targetProviderType); var targets = chunk.GetNativeArray(targetTypr); for (int i = 0; i < chunk.Count; i++) { var index = indices[i].indexPositionInSquad; index.x++; index.y++; var target = targets[i]; target.value = providers[i].EvaluateShootTarget(index.x / data.xUnitCount, index.y / data.yUnitCount, data.left2right, data.bot2top); target.value += rnd.NextFloat2(new float2(1, 1) * -providers[i].randomSpread, new float2(1, 1) * providers[i].randomSpread); targets[i] = target; } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkVelocities = chunk.GetNativeArray(VelocityType); var chunkTranslations = chunk.GetNativeArray(TranslationType); var chunkRotations = chunk.GetNativeArray(RotationType); var chunkMovementData = chunk.GetNativeArray(MovementType); var chunkEnemyData = chunk.GetNativeArray(EnemyStateType); int index = chunk.GetSharedComponentIndex(MovementStateInfoType); MovementStateInfo movementInfo = MovementInfo[index / 2]; quaternion rot90 = quaternion.Euler(0, math.PI / 2, 0); for (int i = 0; i < chunk.Count; i++) { var enemyState = chunkEnemyData[i]; if (enemyState.CurrAIState != EnemyAIState.Dead) { var movementState = chunkMovementData[i]; var translation = chunkTranslations[i]; var velocity = chunkVelocities[i]; var rotation = chunkRotations[i]; float3 toTarget = movementState.Target - translation.Value; float3 toPlayer = enemyState.PlayerPosition - translation.Value; toPlayer.y = 0; toTarget.y = 0; float3 fromTargetToPlayer = movementState.Target - enemyState.PlayerPosition; fromTargetToPlayer.y = 0; if (enemyState.LookAtPlayer) { //rotation = new Rotation() //{ // Value = quaternion.identity //}; rotation = new Rotation() { Value = quaternion.LookRotationSafe(toPlayer, new float3(0, 1, 0)) }; } if (enemyState.CurrAIState != EnemyAIState.Idle) { float maxDist = enemyState.DesiredDistance + enemyState.DesiredDistanceLeeway; float minDist = enemyState.DesiredDistance - enemyState.DesiredDistanceLeeway; float currDistFromTargetToPlayer = math.lengthsq(fromTargetToPlayer); if (currDistFromTargetToPlayer > maxDist * maxDist || currDistFromTargetToPlayer < minDist * minDist) { SetNewTarget(ref movementState, ref enemyState, ref translation, out toTarget, out fromTargetToPlayer, ref Random); } float3 fTTPNorm = math.normalizesafe(fromTargetToPlayer); float3 tPNorm = math.normalizesafe(toPlayer); float3 tTNorm = math.normalizesafe(toTarget); //chunkTranslations[i] = new Translation() //{ // Value = translation.Value + tTNorm * movementInfo.Speed * DeltaTime //}; if (math.dot(fTTPNorm, tPNorm) > 0) { velocity.Linear = tTNorm * movementInfo.Speed;// * math.min(1, math.length(toTarget)); } else { bool tooFar = math.lengthsq(toPlayer) > maxDist * maxDist; bool tooClose = math.lengthsq(toPlayer) < minDist * minDist; if (tooFar || tooClose) { velocity.Linear = math.normalizesafe(toPlayer * math.select(1, -1, tooClose)) * movementInfo.Speed; } else { velocity.Linear = math.normalizesafe(math.mul(rot90, tPNorm * math.select(-1, 1, math.dot(math.mul(rot90, -tPNorm), fTTPNorm) < math.dot(math.mul(rot90, tPNorm), fTTPNorm)))) * movementInfo.Speed; } } } velocity.Linear.y = -1; chunkMovementData[i] = movementState; chunkEnemyData[i] = enemyState; chunkVelocities[i] = velocity; chunkRotations[i] = rotation; } //chunkVelocities[i].Linear = // chunkTranslations[i] = new Translation() // { // Value = chunkTranslations[i].Value + math.mul(chunkRotations[i].Value, new float3(0, 0, DeltaTime * MovementInfo[chunkIndex + 1].Speed)) // }; } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var index = chunk.GetSharedComponentIndex(squadTagType); indices.TryAdd(index, index); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) => sharedIndexesInChunk[chunkIndex] = chunk.GetSharedComponentIndex(sharedType);
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var positions = chunk.GetNativeArray(translationType); var sprites = chunk.GetNativeArray(spriteType); var renderScales = new NativeArray <RenderScaleComponentdata>(); var hasRenderScale = chunk.Has(renderScaleType); if (hasRenderScale) { renderScales = chunk.GetNativeArray(renderScaleType); } var scales = new NativeArray <Scale>(); var hasScale = chunk.Has(scaleType); if (hasScale) { scales = chunk.GetNativeArray(scaleType); } var rotations = new NativeArray <Rotation>(); var hasRotation = chunk.Has(rotationType); if (hasRotation) { rotations = chunk.GetNativeArray(rotationType); } var cnt = chunk.Count; var tints = new NativeArray <SpriteTintComponentData>(); var hasTint = chunk.Has(spriteTintType); if (hasTint) { tints = chunk.GetNativeArray(spriteTintType); } var cracks = new NativeArray <SpriteCracksComponentData>(); var hasCracks = chunk.Has(spriteCracksType); if (hasCracks) { cracks = chunk.GetNativeArray(spriteCracksType); } var shadows = new NativeArray <CastSpritesShadowComponentData>(); var hasShadows = chunk.Has(shadowType); if (hasShadows) { shadows = chunk.GetNativeArray(shadowType); } var culling = !chunk.Has(disableCullingTagType); var sharedIndex = chunk.GetSharedComponentIndex(renderDataType); for (int i = 0; i < cnt; i++) { var pos = positions[i].Value; if (culling) { if (pos.x < minX || pos.x > maxX || pos.y < minY || pos.y > maxY) { continue; } } var sprite = sprites[i]; var renderScale = float2.zero; if (hasRenderScale) { renderScale = renderScales[i].value; } else { renderScale = new float2(1, 1); } var scale = 1f; if (hasScale) { scale = scales[i].Value; } var rotation = quaternion.identity; if (hasRotation) { rotation = rotations[i].Value; } var color = Vector4.one; if (hasTint) { color = tints[i].color; } if (color.w == 0) { continue; } var crackAmount = 0f; if (hasCracks) { crackAmount = cracks[i].cracksAmount; } var actualRenderScale = new Vector3(renderScale.x, renderScale.y, 1) * scale; if (actualRenderScale.x == 0 || actualRenderScale.y == 0) { continue; } var actualPivot = sprite.pivot; if (!sprite.usePivot) { actualPivot = Vector2.one / 2; } actualPivot -= Vector2.one / 2; var actualPosition = pos; var pivotedPosition = pos; pivotedPosition.x = -actualPivot.x * actualRenderScale.x; pivotedPosition.y = -actualPivot.y * actualRenderScale.y; var translateMatrix = Matrix4x4.Translate(actualPosition); var rorateMatrix = Matrix4x4.Rotate(rotation); var pivotedTranslateMatrix = Matrix4x4.Translate(pivotedPosition); var scaleMatrix = Matrix4x4.Scale(actualRenderScale); var rdata = new RenderData() { position = pos, uv = sprite.uv, color = color, matrix = translateMatrix * rorateMatrix * pivotedTranslateMatrix * scaleMatrix, cracksAmount = crackAmount }; chunkDataMap.Add(sharedIndex, rdata); if (hasShadows) { var shadowData = shadows[i]; if (shadowData.disableCastShadow || shadowData.scale.x == 0 || shadowData.scale.y == 0 || shadowData.color.a == 0) { continue; } var shadowOffsettedPosition = actualPosition + shadowData.positionPercentOffset * actualRenderScale + shadowData.positionUnitsOffset; var shadowScale = actualRenderScale; shadowScale.x *= shadowData.scale.x; shadowScale.y *= shadowData.scale.y; var shadowColor = color * shadowData.color; var shadowRotation = rotation; if (shadowData.flipRotationByX) { Quaternion q = shadowRotation; var angles = q.eulerAngles; angles.z = 180 - angles.z; shadowRotation = Quaternion.Euler(angles); } if (shadowData.flipRotationByY) { Quaternion q = shadowRotation; var angles = q.eulerAngles; angles.z = 360 - angles.z; shadowRotation = Quaternion.Euler(angles); } var shadowTranslateMatrix = Matrix4x4.Translate(shadowOffsettedPosition); var shadowScaleMatrix = Matrix4x4.Scale(shadowScale); var shadowRotateMatrix = Matrix4x4.Rotate(shadowRotation); var rshadowrdata = new RenderData() { position = shadowOffsettedPosition, uv = sprite.uv, color = shadowColor, matrix = shadowTranslateMatrix * shadowRotateMatrix * pivotedTranslateMatrix * shadowScaleMatrix }; chunkDataMap.Add(sharedIndex, rshadowrdata); } } }