protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //ArchetypeChunkComponentType<AABBComponent> collisionTypeRW = GetArchetypeChunkComponentType<AABBComponent>();

        NativeArray <AABBComponent> _colliders      = query.ToComponentDataArray <AABBComponent>(Allocator.TempJob);
        NativeArray <Translation>   _positions      = query.ToComponentDataArray <Translation>(Allocator.TempJob);
        NativeArray <MoveComponent> _moveComponents = query.ToComponentDataArray <MoveComponent>(Allocator.TempJob);


        var collisionJob = new CollisionJob {
            //chunkComponentType = collisionTypeRW,
            colliders      = _colliders,
            positions      = _positions,
            moveComponents = _moveComponents,
            commandBuffer  = m_EndFrameBarrier.CreateCommandBuffer().ToConcurrent()
        };

        var collisionJobHandle = collisionJob.Schedule(query);

        collisionJobHandle.Complete();
        return(collisionJobHandle);
    }
Пример #2
0
        //=========================================================================================
        public override JobHandle SolverConstraint(float dtime, float updatePower, int iteration, JobHandle jobHandle)
        {
            if (Manager.Particle.ColliderCount <= 0)
            {
                return(jobHandle);
            }

            // コリジョン拘束
            var job1 = new CollisionJob()
            {
                flagList           = Manager.Particle.flagList.ToJobArray(),
                teamIdList         = Manager.Particle.teamIdList.ToJobArray(),
                radiusList         = Manager.Particle.radiusList.ToJobArray(),
                nextPosList        = Manager.Particle.InNextPosList.ToJobArray(),
                nextRotList        = Manager.Particle.InNextRotList.ToJobArray(),
                posList            = Manager.Particle.posList.ToJobArray(),
                rotList            = Manager.Particle.rotList.ToJobArray(),
                localPosList       = Manager.Particle.localPosList.ToJobArray(),
                basePosList        = Manager.Particle.basePosList.ToJobArray(),
                baseRotList        = Manager.Particle.baseRotList.ToJobArray(),
                transformIndexList = Manager.Particle.transformIndexList.ToJobArray(),

                colliderList = Manager.Team.colliderList.ToJobArray(),

                boneSclList = Manager.Bone.boneSclList.ToJobArray(),

                teamDataList = Manager.Team.teamDataList.ToJobArray(),

                outNextPosList = Manager.Particle.OutNextPosList.ToJobArray(),
                frictionList   = Manager.Particle.frictionList.ToJobArray(),
                //velocityList = Manager.Particle.velocityList.ToJobArray(),
            };

            jobHandle = job1.Schedule(Manager.Particle.Length, 64, jobHandle);
            Manager.Particle.SwitchingNextPosList();

            return(jobHandle);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var          translationType  = GetArchetypeChunkComponentType <Translation>(true);
        var          carComponentType = GetArchetypeChunkComponentType <CarComponent>(true);
        var          entityType       = GetArchetypeChunkEntityType();
        var          hero             = this.GetSingletonEntity <HeroComponent>();
        var          heroCarComponent = World.EntityManager.GetComponentData <CarComponent>(hero);
        var          chunks           = streetCarsGroup.CreateArchetypeChunkArray(Allocator.TempJob);
        CollisionJob collisionJob     = new CollisionJob
        {
            EntityCommandBuffer = entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            CarComponentType    = carComponentType,
            EntityType          = entityType,
            Chunks          = chunks,
            TranslationType = translationType,
            Hero            = heroCarComponent
        };

        var inputdeps = collisionJob.Schedule(this, inputDeps);

        entityCommandBufferSystem.AddJobHandleForProducer(inputdeps);
        return(inputdeps);
    }
Пример #4
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        var healthType      = GetArchetypeChunkComponentType <Health>(false);
        var translationType = GetArchetypeChunkComponentType <Translation>(true);
        var damageType      = GetArchetypeChunkComponentType <Damage>(true);

        float enemyRadius  = Settings.EnemyCollisionRadius;
        float playerRadius = Settings.PlayerCollisionRadius;

        var jobEvB = new CollisionJob()
        {
            radius             = enemyRadius * enemyRadius,
            healthType         = healthType,
            translationType    = translationType,
            damageType         = damageType,
            transToTestAgainst = bulletGroup.ToComponentDataArray <Translation>(Allocator.TempJob)
        };

        JobHandle jobHandle = jobEvB.Schedule(enemyGroup, inputDependencies);

        if (Settings.IsPlayerDead())
        {
            return(jobHandle);
        }

        var jobPvE = new CollisionJob()
        {
            radius             = playerRadius * playerRadius,
            healthType         = healthType,
            translationType    = translationType,
            damageType         = damageType,
            transToTestAgainst = enemyGroup.ToComponentDataArray <Translation>(Allocator.TempJob)
        };

        return(jobPvE.Schedule(playerGroup, jobHandle));
    }
Пример #5
0
    // OnUpdate do something (decide to do job or pass)
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        // get types
        var healthType      = GetArchetypeChunkComponentType <Health>(false);
        var translationType = GetArchetypeChunkComponentType <Translation>(true);

        // set detect radius
        float enemyRadius  = 1;
        float playerRadius = 0.8f;

        JobHandle jobHandle = new JobHandle();

        if (SceneManager.GetActiveScene().buildIndex != 2)         // if not stage 1
        {
            // change stage2 BOSS & player's Raduis
            if (Done_GameController_stage2.bossShow == true)
            {
                enemyRadius  *= 3f;
                playerRadius /= 1.5f;
            }

            // change stage3 BOSS & player's Raduis
            if (Done_GameController_stage3.bossShow == true)
            {
                enemyRadius  *= 1.5f;
                playerRadius /= 1.5f;
            }

            // deal with enemy collide with bullet
            var jobEvB = new CollisionJob()
            {
                radius             = enemyRadius * enemyRadius,
                healthType         = healthType,
                translationType    = translationType,
                transToTestAgainst = playerBulletGroup.ToComponentDataArray <Translation>(Allocator.TempJob)
            };

            jobHandle = jobEvB.Schedule(enemyGroup, inputDependencies);             // add in Job list

            // deal with bullet collide with enemy
            var jobBvE = new CollisionJob()
            {
                radius             = enemyRadius * enemyRadius,
                healthType         = healthType,
                translationType    = translationType,
                transToTestAgainst = enemyGroup.ToComponentDataArray <Translation>(Allocator.TempJob)
            };

            jobHandle = jobBvE.Schedule(playerBulletGroup, jobHandle);             // add in Job list
        }

        // deal with player collide with enemy or enemyBullet
        NativeArray <Translation> enemyBulletPosition;
        NativeArray <Translation> enemyPosition;
        bool gameOver = false;

        // get enemyBullet position & enemy position
        enemyBulletPosition = enemyBulletGroup.ToComponentDataArray <Translation>(Allocator.TempJob);
        enemyPosition       = enemyGroup.ToComponentDataArray <Translation>(Allocator.TempJob);

        // if stage 1 easier (player radius / 1.5f)
        if (SceneManager.GetActiveScene().buildIndex == 2)
        {
            playerRadius /= 1.5f;
        }

        // for all enemy bullet position
        for (int i = 0; i < enemyBulletPosition.Length; i++)
        {
            // calculate distance between player and enemy
            float dx, dz;
            if (SceneManager.GetActiveScene().buildIndex == 2)
            {
                dx = Done_PlayerController_stage1.playerPosition.x - enemyBulletPosition[i].Value.x;
                dz = Done_PlayerController_stage1.playerPosition.z - enemyBulletPosition[i].Value.z;
            }
            else
            {
                dx = Done_PlayerController_stage23.playerPosition.x - enemyBulletPosition[i].Value.x;
                dz = Done_PlayerController_stage23.playerPosition.z - enemyBulletPosition[i].Value.z;
            }

            if (dx * dx + dz * dz <= playerRadius)             // if collide
            {
                gameOver = true;
                if (SceneManager.GetActiveScene().buildIndex == 2)
                {
                    Done_GameController_stage1.gameOver = true;
                }
                else if (SceneManager.GetActiveScene().buildIndex == 4)
                {
                    Done_GameController_stage2.gameOver = true;
                }
                else
                {
                    Done_GameController_stage3.gameOver = true;
                }
            }
        }

        // if not stage 1 detect enemy player collision
        if (SceneManager.GetActiveScene().buildIndex != 2)
        {
            for (int i = 0; i < enemyPosition.Length; i++)
            {
                float dx, dz;
                if (SceneManager.GetActiveScene().buildIndex == 2)
                {
                    dx = Done_PlayerController_stage1.playerPosition.x - enemyPosition[i].Value.x;
                    dz = Done_PlayerController_stage1.playerPosition.z - enemyPosition[i].Value.z;
                }
                else
                {
                    dx = Done_PlayerController_stage23.playerPosition.x - enemyPosition[i].Value.x;
                    dz = Done_PlayerController_stage23.playerPosition.z - enemyPosition[i].Value.z;
                }

                if (dx * dx + dz * dz <= playerRadius + enemyRadius)                 // if collide
                {
                    gameOver = true;
                    if (SceneManager.GetActiveScene().buildIndex == 2)
                    {
                        Done_GameController_stage1.gameOver = true;
                    }
                    else if (SceneManager.GetActiveScene().buildIndex == 4)
                    {
                        Done_GameController_stage2.gameOver = true;
                    }
                    else
                    {
                        Done_GameController_stage3.gameOver = true;
                    }
                }
            }
        }

        // If GameOver delete gameObject
        if (gameOver)
        {
            Object.Destroy(GameObject.Find("Done_Player"));             // Delete Player
            if (SceneManager.GetActiveScene().buildIndex == 2)
            {
                Object.Destroy(GameObject.Find("Boy_stage1"));                 // Delete Boy
            }
        }

        enemyPosition.Dispose();
        enemyBulletPosition.Dispose();

        return(jobHandle);
    }
Пример #6
0
    protected override JobHandle OnUpdate(JobHandle handle)
    {
        bubCount = boublesQuery.CalculateEntityCount();
        var sm = GetSingleton <SpawnerRndAreaComp>();

        if (BoubleAuth._grad == 0 || bubCount == 0 || spawnSystem._prefabEntity == Entity.Null)
        {
            return(handle);
        }
        if (sizeToGrav == 0)
        {
            sizeToGrav = .5f / BoubleAuth._grad;
        }

        bubMap.Clear();
        dt = Time.DeltaTime;

        new InitBubs {
            bubs = bubList
        }.Schedule(this, handle).Complete();

        int workers     = 14;
        int countPerJob = bubCount / workers;

        if (gravWaitTime >= spawnSystem.sd.gravUpdateDelay)
        {
            new GravJob {
                t              = framesSinceLastGrav > 0 ? dt * framesSinceLastGrav : dt,
                bubsIn         = bubList,
                bubsOut        = bubList2,
                numOfBubs      = bubCount,
                gravMultiplier = bd.gravityMult,
                gravDivider    = bd.gravityDiv
            }.Schedule(bubCount, countPerJob, handle).Complete();
            gravWaitTime = 0;
            for (int i = 0; i < bubCount; i++)
            {
                var item = bubList2[i];
                bubMap.TryAdd(item.entity, item);
            }
            framesSinceLastGrav = 0;
        }
        else
        {
            gravWaitTime += Time.DeltaTime;
            framesSinceLastGrav++;
            for (int i = 0; i < bubCount; i++)
            {
                var item = bubList[i];
                bubMap.TryAdd(item.entity, item);
            }
        }

        new UpdateBubsJob {
            maxRad     = spawnSystem.sd.cylinderRadius + bd.boundryBuffer,
            maxHeight  = spawnSystem.sd.cylinderHeight + bd.boundryBuffer,
            sizeToGrav = sizeToGrav,
            bubMap     = bubMap,
            bounce     = bd.bounce,
            absorb     = bd.absorb,
            maxScale   = bd.maxScale
        }.Schedule(this, handle).Complete();

        new ChangeColors {
            sm = sm
        }.Schedule(this, handle).Complete();

        if (bd.absorb)
        {
            var cj = new CollisionJob {
                ecb               = _ecbs.CreateCommandBuffer().ToConcurrent(),
                bubs              = bubMap,
                prefabEntity      = spawnSystem._prefabEntity,
                scaleInc          = bd.scaleInc,
                explosionLifeTime = spawnSystem.sd.explosionLifeTime,
                explosionEndScale = spawnSystem.sd.explosionEndScale,
                explode           = spawnSystem.sd.explode
            };

            handle = cj.Schedule(this, handle);

            collisionSystem.AddDependingJobHandle(handle);

            _ecbs.AddJobHandleForProducer(handle);
        }

        return(handle);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        int count = m_Group.CalculateEntityCount();

        if (count == 0)
        {
            return(inputDeps);
        }

        if (!translations.IsCreated)
        {
            translations = new NativeArray <float3>(count, Allocator.Persistent);
        }
        else if (translations.Length != count)
        {
            translations.Dispose();
            translations = new NativeArray <float3>(count, Allocator.Persistent);
        }

        if (!velocities.IsCreated)
        {
            velocities = new NativeArray <float3>(count, Allocator.Persistent);
        }
        else if (velocities.Length != count)
        {
            velocities.Dispose();
            velocities = new NativeArray <float3>(count, Allocator.Persistent);
        }

        CopyTranslations copyTranslationsJob = new CopyTranslations
        {
            translations    = translations,
            translationType = GetComponentTypeHandle <Translation>()
        };

        CopyVelocities copyVelocitiesJob = new CopyVelocities
        {
            velocities   = velocities,
            velocityType = GetComponentTypeHandle <Velocity>()
        };

        JobHandle copyTranslationsJobHandle = copyTranslationsJob.Schedule(m_Group, inputDeps);
        JobHandle copyVelocitiesJobHandle   = copyVelocitiesJob.Schedule(m_Group, inputDeps);
        JobHandle copyJobsHandle            = JobHandle.CombineDependencies(copyTranslationsJobHandle, copyVelocitiesJobHandle);

        if (CollisionBuckets.IsCreated)
        {
            CollisionBuckets.Dispose();
        }
        CollisionBuckets = new NativeMultiHashMap <int, int>(count, Allocator.Persistent);

        PrepareBucketsJob prepareBucketsJob = new PrepareBucketsJob
        {
            positions = translations,
            buckets   = CollisionBuckets
        };

        JobHandle prepareBucketsHandle = prepareBucketsJob.Schedule(copyJobsHandle);

        CollisionJob collisionJob = new CollisionJob
        {
            dt             = Time.DeltaTime,
            positions      = translations,
            velocities     = velocities,
            buckets        = CollisionBuckets,
            maxIterations  = m_maxIterations,
            maxClosestDone = m_maxClosestDone,
            maxForce       = m_maxForce,
            damping        = m_damping,
            radiusSqr      = m_radiusSqr,
            maxVelocity    = m_maxVelocity,
            maxVelocitySqr = m_maxVelocitySqr,
            velocityType   = GetComponentTypeHandle <Velocity>()
        };

        return(collisionJob.Schedule(m_Group, prepareBucketsHandle));
    }