Пример #1
0
    private void Update()
    {
        if (!IsInvoking(nameof(GetRandomPositionAndBox)))
        {
            Invoke(nameof(GetRandomPositionAndBox), 15);
        }

        if (!IsInvoking(nameof(SpawnWeapons)))
        {
            Invoke(nameof(SpawnWeapons), 15);
        }
        try
        {
            PlayerHealth = MyPlayer.GetComponent <ApplyDamage>();
        }
        catch
        {
        }


        if (CountLife == 0)
        {
            PhotonNetwork.Destroy(MyPlayer);
        }


        if (PlayerHealth.isDied)
        {
            CountLife -= 1;
            print(CountLife);
            PhotonNetwork.Destroy(MyPlayer);
            Spawn();
            PlayerHealth.isDied = false;
        }
    }
Пример #2
0
    private GameObject AddBulletToPool()
    {
        /* Instantiate a pool of bullets. This prevents new objects constantly
         * being created and allocating memory. This is used to increase
         * game performance.
         */

        if (bulletProjectile)
        {
            // Instantiate a new bullet
            GameObject bullet = Instantiate(bulletProjectile) as GameObject;
            bullet.hideFlags = HideFlags.HideInHierarchy;
            bullet.SetActive(false);

            // Add despawn conditions
            bullet.GetComponent <DisableAfterSeconds> ().Delay = despawnAfter;

            // Add damage to the bullet
            ApplyDamage  dmgScript        = bullet.AddComponent <ApplyDamage> ();
            On_Collision collisionHandler = bullet.AddComponent <On_Collision> ();
            if (collisionHandler)
            {
                dmgScript.Damage = damage;
                collisionHandler.Actions.Add(dmgScript);
                dmgScript.dmgTagsMode = dmgTagsMode;
                collisionHandler.mode = dmgTagsMode;
                if (collisionHandler.mode == COLLISION_MODE.IgnoreSelected)
                {
                    collisionHandler.collisionTags.Add(transform.tag);
                    dmgScript.dmgTags.Add(transform.tag);
                }
                foreach (string str in dmgTags)
                {
                    collisionHandler.collisionTags.Add(str);
                    dmgScript.dmgTags.Add(str);
                }
            }
            bullet.GetComponent <ApplyDamage> ().Damage = damage;

            // Add hit effect
            bullet.GetComponent <EmitParticle> ().amount    = hitParticles;
            bullet.GetComponent <EmitParticle> ().particles = AddHitEffectToPool();

            // Set collision-ignore-tags
            bullet.GetComponent <On_Collision> ().collisionTags.Add(transform.tag);

            // Add bullet to the pool
            bulletPool.Add(bullet);

            return(bullet);
        }
        return(default(GameObject));
    }
Пример #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.TryGetComponent(out Character character))
     {
         damage = character.GetComponent <ApplyDamage>();
         if (damage.health <= damage.startingHealth - 20)
         {
             damage.health += 20;
         }
         gameObject.SetActive(false);
     }
 }
Пример #4
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        Settings settings;

        settings.CellRadius        = 16;
        settings.SeparationWeight  = 1;
        settings.AlignmentWeight   = 1;
        settings.TargetWeight      = 2;
        settings.MaxTargetDistance = 10000;
        //settings.ObstacleAversionDistance = 35;
        settings.MoveSpeed  = 25;
        settings.boidRadius = 0.5f;

        EntityManager.GetAllUniqueSharedComponentData(uniqueFactions);

        int healthCount = healthQuery.CalculateEntityCount();

        for (int i = 0; i < prevFrameHashmaps.Count; i++)
        {
            prevFrameHashmaps[i].Dispose();
        }
        prevFrameHashmaps.Clear();

        for (int index = 0; index < uniqueFactions.Count; index++)
        {
            boidQuery.SetFilter(uniqueFactions[index]);

            int boidCount = boidQuery.CalculateEntityCount();

            if (boidCount == 0)
            {
                continue;
            }

            var cellIndices          = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var hashMap              = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);
            var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var cellCount            = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var killTrigger          = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                         NativeArrayOptions.UninitializedMemory);
            var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                          NativeArrayOptions.UninitializedMemory);
            var boidsData = new NativeArray <Boid>(boidCount, Allocator.TempJob,
                                                   NativeArrayOptions.UninitializedMemory);
            var cellTargetPositions = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                               NativeArrayOptions.UninitializedMemory);
            var cellObstaclePositions = new NativeArray <float3>(boidCount, Allocator.TempJob,
                                                                 NativeArrayOptions.UninitializedMemory);
            var bulletSpawns = new NativeArray <BulletSpawn>(boidCount, Allocator.TempJob,
                                                             NativeArrayOptions.ClearMemory);

            var damageDict = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob);

            var initialCellAlignmentJob = new CopyHeadings {
                headings = cellAlignment
            };
            var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(boidQuery, inputDependencies);

            var initialCellSeparationJob = new CopyPositions {
                positions = cellSeparation
            };
            var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(boidQuery, inputDependencies);

            var initialBoidData = new CopyBoids {
                boids = boidsData
            };
            var initialBoidDataJobHandle = initialBoidData.Schedule(boidQuery, inputDependencies);

            // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet
            prevFrameHashmaps.Add(hashMap);

            var hashPositionsJob = new HashPositions {
                hashMap    = hashMap.AsParallelWriter(),
                cellRadius = settings.CellRadius
            };
            var hashPositionsJobHandle = hashPositionsJob.Schedule(boidQuery, inputDependencies);

            var initialCellCountJob = new MemsetNativeArray <int> {
                Source = cellCount,
                Value  = 1
            };
            var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDependencies);

            var killTriggerJob = new MemsetNativeArray <int> {
                Source = killTrigger,
                Value  = 0
            };
            var killTriggerJobHandle = killTriggerJob.Schedule(boidCount, 64, inputDependencies);

            var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle);
            var initialBoidBarrierJobHandle = JobHandle.CombineDependencies(initialBoidDataJobHandle, killTriggerJobHandle);
            var mergeCellsBarrierJobHandle  = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, initialBoidBarrierJobHandle);

            ref PhysicsWorld physicsWorld = ref Unity.Entities.World.Active.GetExistingSystem <BuildPhysicsWorld>().PhysicsWorld;

            var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();
            prevFrameHashmaps.Add(damageDict);

            var mergeCellsJob = new MergeCells {
                cellIndices           = cellIndices,
                cellObstaclePositions = cellObstaclePositions,
                cellTargetPositions   = cellTargetPositions,
                cellAlignment         = cellAlignment,
                cellSeparation        = cellSeparation,
                cellObstacleDistance  = cellObstacleDistance,
                cellCount             = cellCount,
                boidsData             = boidsData,
                killTrigger           = killTrigger,
                physicsWorld          = physicsWorld,
                damageDict            = damageDict.AsParallelWriter(),
                bulletSpawns          = bulletSpawns,
                commandBuffer         = commandBuffer,
                bulletPrefab          = BulletPrefabAuthoring.Prefab,
                //enemyEntityLook = Setup.enemyEntityLook,
                groupIndex = math.select(4u, 8u, uniqueFactions[index].Value == 0),
                time       = Time.time,
                settings   = settings,
            };
            var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle);

            m_Barrier.AddJobHandleForProducer(mergeCellsJobHandle);

            var applyBulletSpawnDataJob = new ApplyBulletSpawnData {
                bulletSpawns  = bulletSpawns,
                destroyAtTime = Time.time + 5,
                commandBuffer = commandBuffer,
                bulletPrefab  = BulletPrefabAuthoring.Prefab
            };
            var applyBulletSpawnDataJobHandle = applyBulletSpawnDataJob.Schedule(boidCount, 64, mergeCellsJobHandle);

            m_Barrier.AddJobHandleForProducer(applyBulletSpawnDataJobHandle);

            var updateBoidData = new UpdateBoidData {
                boidsData = boidsData
            };
            var updateBoidDataJobHandle = updateBoidData.Schedule(boidQuery, applyBulletSpawnDataJobHandle);

            var steerJob = new Steer {
                cellIndices          = cellIndices,
                settings             = settings,
                cellAlignment        = cellAlignment,
                cellSeparation       = cellSeparation,
                cellObstacleDistance = cellObstacleDistance,
                cellCount            = cellCount,
                targetPositions      = cellTargetPositions,
                obstaclePositions    = cellObstaclePositions,
                boidsData            = boidsData,
                dt = Time.deltaTime,
            };
            var steerJobHandle = steerJob.Schedule(boidQuery, updateBoidDataJobHandle);

            var killJob = new Kill {
                killTrigger   = killTrigger,
                commandBuffer = commandBuffer,
            };
            var killJobHandle = killJob.Schedule(boidQuery, steerJobHandle);

            m_Barrier.AddJobHandleForProducer(killJobHandle);

            var applyDamageJob = new ApplyDamage {
                damageDict = damageDict
            };
            var applyDamageJobHandle = applyDamageJob.Schedule(healthQuery, mergeCellsJobHandle);

            inputDependencies = JobHandle.CombineDependencies(killJobHandle, applyDamageJobHandle, applyBulletSpawnDataJobHandle);
            boidQuery.AddDependency(inputDependencies);
        }