Exemplo n.º 1
0
    private void Health_Died(IHealth dead)
    {
        try
        {
            dead.Died -= Health_Died;

            var deadGameObject = AllSpawned.First(p => p.Value == dead).Key;
            if (DestroyIfDeath)
            {
                RemoveSpawned(deadGameObject);
                Destroy(deadGameObject);
            }
            else
            {
                var animMaganer = AnimationManagerBase.CreateOrGet(deadGameObject);
                animMaganer.SetState(AnimationState.Die);
            }

            if (dead is ILoot loot)
            {
                _player.CollectLoot(loot);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }
Exemplo n.º 2
0
        public void Spawn(List <SpawnPoint> spawnPoints)
        {
            if (spawnPoints.Count == 0)
            {
                Log.Error("Cannot spawn enemy as no spawn points exist.");
                return;
            }

            var rnd        = new Random().Next(0, spawnPoints.Count);
            var spawnPoint = spawnPoints[rnd];

            float time = 0f;

            for (int i = 0; i < Data.Amount; i++)
            {
                spawnDelayTimers.Add(new Timer(time, () => AddEnemy(spawnPoint)));
                time += delayBetweenSpawns;
            }

            if (Data.PostDelay.HasValue)
            {
                Log.Info("Waiting " + Data.PostDelay.Value + " seconds before spawning next group...");
                postSpawnDelay = new Timer(Data.PostDelay.Value, () => AllSpawned?.Invoke(this));
            }
            else
            {
                AllSpawned?.Invoke(this);
            }
        }
Exemplo n.º 3
0
    void Update()
    {
        _limiter.Do(() =>
        {
            var count = 0;
            foreach (var sp in _spawned)
            {
                if (AllSpawned.Any(p => p.Value == sp))
                {
                    count++;
                }
            }
            if (count >= Limit)
            {
                return;
            }

            if (SetPrefabInactive)
            {
                CloneSource.SetActive(true);
            }
            var clone = Instantiate(CloneSource, transform.position, transform.rotation);
            if (SetPrefabInactive)
            {
                CloneSource.SetActive(false);
            }

            if (SetParent)
            {
                clone.transform.SetParent(transform, false);
            }

            clone.transform.rotation = RandomRotation
                ? new Quaternion((float)Random.NextDouble(), (float)Random.NextDouble(), (float)Random.NextDouble(), (float)Random.NextDouble())
                : CloneSource.transform.rotation;

            Bounds bounds = gameObject.GetComponent <MeshRenderer>().bounds;
            var r         = GetRandomVector(bounds.extents) * Radius;
            var pos       = transform.position;
            pos           = new Vector3(pos.x + r.x, pos.y + HeightAtSpawner, pos.z + r.z);
            clone.transform.SetPositionAndRotation(pos, clone.transform.rotation);

            var spawned = CreateISpawned(CloneSource);
            AddSpawned(clone, spawned);
            _spawned.Add(spawned);

            if (spawned is IHealth health)
            {
                health.Died += Health_Died;
            }
        });
    }