Ejemplo n.º 1
0
    public virtual void Hit(Vector3 HitPosition, Vector3 HitDirection, float forceAmount = 0f)
    {
        if (IsDead)
        {
            return;
        }

        if (sendFurther && reciever)
        {
            reciever.Hit(HitPosition, HitDirection, forceAmount);
            return;
        }

        if (HitEffect)
        {
            int          layermask = 1 << gameObject.layer;
            RaycastHit2D hit       = Physics2D.RaycastAll(HitPosition - HitDirection, HitDirection, HitDirection.magnitude * 2f, layermask).FirstOrDefault(o => o.collider == collider2D);
            if (hit)
            {
                EntitySpawnManager.Spawn(HitEffectPoolName, HitPosition, Quaternion.FromToRotation(Vector3.back, hit.normal), countEntity: false, forceDirectSpawn: true);
                if (forceAmount != 0)
                {
                    Force(HitPosition, HitDirection.normalized, forceAmount);
                }
            }
        }
    }
Ejemplo n.º 2
0
 public static void Spawn(string poolName, Vector3 position, Quaternion rotation, EntityEvent callBack = null, bool queue = false, bool forceDirectSpawn = false, bool countEntity = true)
 {
     if (forceDirectSpawn || (!queue && GameManager.CanSpawnEntity))
     {
         Instance.Spawn(new SpawnQueueInfo()
         {
             poolName = poolName, position = position, rotation = rotation, callBack = callBack, countEntity = countEntity
         });
     }
     else
     {
         Instance.EntitySpawnQueue.Enqueue(new SpawnQueueInfo()
         {
             poolName = poolName, position = position, rotation = rotation, callBack = callBack, countEntity = countEntity
         });
     }
 }
Ejemplo n.º 3
0
    public void TrySpawning(string poolName, Vector3 position)
    {
        RaycastHit2D hit = Physics2D.Raycast(position + Vector3.up, Vector3.down, maxDistanceDown, GroundLayer);

        if (hit)
        {
            if (!Physics2D.OverlapCircle(hit.point, minSpace, BaseLayer))
            {
                EntitySpawnManager.Spawn(poolName, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
            }
        }
    }
Ejemplo n.º 4
0
    public virtual void Die()
    {
        for (int i = 0; i < Drops.Length; i++)
        {
            if (Drops[i].WantsToSpawn)
            {
                for (int a = 0; a < Drops[i].Amount; a++)
                {
                    EntitySpawnManager.Spawn(Drops[i].Next().poolName, transform.position, Quaternion.identity, queue: true);
                }
            }
        }

        EntitySpawnManager.Despawn(poolName, gameObject, true);
        GameEventHandler.TriggerEntityDied(this);
    }
Ejemplo n.º 5
0
    public void Explode()
    {
        HitAbleInfo[] HitAblesInRange = EntitySpawnManager.Instance.GetHitAbleInCircles(transform.position, HitAbleHitMask, ExplosionRange, true);
        //HitAbleInfo[] collider = EntitySpawnManager.Instance.GetHitAbleInCircles(transform.position, HitAbleHitMask, distance, true, false);
        for (int i = 0; i < HitAblesInRange.Length; i++)
        {
            HitAbleInfo item = HitAblesInRange[i];

            if (item == null || item.hitAble == null)
            {
                continue;
            }

            float distance = 0f;
            distance = item.distance;

            float damageMult = (ExplosionRange - distance);

            item.hitAble.Damage(new Damage()
            {
                type              = DamageType.EXPLOSION,
                amount            = damageMult * damage,
                DamageFromAPlayer = true,
                player            = player,
                other             = player.transform
            });
            item.hitAble.Hit(item.ColliderCenter, (item.ColliderCenter - transform.position), force);

            /*
             * Debug.Log("Distance: " + HitAblesInRange[i].distance);
             * HitAblesInRange[i].hitAble.Damage(new Damage()
             * {
             *  DamageFromAPlayer = true,
             *  player = player,
             *  amount = Mathf.Min(distance - HitAblesInRange[i].distance, 0.0f),
             *  type = DamageType.EXPLOSION,
             *  other = player.transform
             * });
             * HitAblesInRange[i].hitAble.Hit(HitAblesInRange[i].ColliderCenter, (HitAblesInRange[i].ColliderCenter - transform.position), force);
             * */
        }

        AudioEffectController.Instance.PlayOneShot(explosion, transform.position);
        EntitySpawnManager.Spawn(hitEffektPoolName, transform.position, Quaternion.identity, forceDirectSpawn: true, countEntity: false);

        EntitySpawnManager.Despawn(poolName, gameObject, false);
    }
Ejemplo n.º 6
0
    public void Spawn()
    {
        if (EntitySpawnManager.Instance.GetNearestPlayers(BaseTransform.position, false, Range) != null)
        {
            var rnd = Random.value;
            foreach (var item in spawnInfos)
            {
                if (rnd < item.weight)
                {
                    EntitySpawnManager.Spawn(item.poolName, BaseTransform.position, Quaternion.identity);

                    return;
                }
                rnd -= item.weight;
            }
        }
    }
Ejemplo n.º 7
0
 private void SpawnRocket(PlayerClass playerClass)
 {
     player = playerClass.playerControl;
     EntitySpawnManager.Spawn(RocketPoolName, playerClass.playerTransform.position + Vector3.up * 2f, Quaternion.FromToRotation(Vector3.up, Vector3.left), callBack: RocketSpawned, queue: true, countEntity: false);
 }