Esempio n. 1
0
 private IEnumerator MainLoop()
 {
     _isRunning = true;
     if (autoStartOn != AutoStartOn.Never)
     {
         yield return(new WaitForSeconds(startDelay));
     }
     if (started)
     {
         onStart?.Invoke();
     }
     while (config.CanSpawn())
     {
         while (_isPaused)
         {
             yield return(null);
         }
         config.Spawn();
         yield return(Cooldown());
     }
     if (completed)
     {
         onComplete?.Invoke();
     }
     if (despawnOnComplete)
     {
         Despawn();
     }
     _isRunning = false;
 }
Esempio n. 2
0
        protected GameObject Instantiate(GameObject thingToSpawn, Vector3 position, Quaternion rotation)
        {
            ++spawnCount;
            GameObject spawned = UnityEngine.Object.Instantiate(thingToSpawn, position, rotation, parent.transform);

            OnSpawn?.Invoke(spawned);
            return(spawned);
        }
Esempio n. 3
0
 public void ResumeSpawning()
 {
     _isPaused = false;
     if (resumed)
     {
         onResume?.Invoke();
     }
 }
Esempio n. 4
0
 public void PauseSpawning()
 {
     _isPaused = true;
     if (paused)
     {
         onPause?.Invoke();
     }
 }
        private void Spawning()
        {
            GameObject spawningObject = Instantiate(objectToSpawn);

            spawningObject.transform.position = transform.position;
            spawningObject.transform.rotation = transform.rotation;

            SpawnEvent?.Invoke(spawningObject.transform);
        }
Esempio n. 6
0
 public void StopSpawning()
 {
     _isPaused  = false;
     _isRunning = false;
     if (_mainloop != null)
     {
         StopCoroutine(_mainloop);
     }
     if (stopped)
     {
         onStop?.Invoke();
     }
 }
Esempio n. 7
0
        private IEnumerator SpawnDamage()
        {
            while (true)
            {
                var time = Random.Range(_settings.MaxDamageSpawnFrequency, _settings.MaxDamageSpawnFrequency);
                yield return(new WaitForSeconds(time));

                var pos        = RandPos();
                var damageView = _enemyPool.Pop(Enemy.Damage, pos, Quaternion.identity);
                _activeEnemies.Add(damageView);
                damageView.DieEvent += DieEventHandler;
                _asyncProcessor.StartCoroutine(Die(damageView));
                SetSize(damageView);
                SpawnEvent?.Invoke(damageView);
            }
        }
Esempio n. 8
0
        public bool Update(float left, TRight right)
        {
            var lastNode = _objects.Last;

            if (!SpawnRight(right))
            {
                return(false);                    // side effects!
            }
            // invoke event for each newly added item
            while (lastNode?.Next != null)
            {
                lastNode = lastNode.Next;
                SpawnEvent?.Invoke(lastNode.Value, left, right);
            }

            DespawnLeft(left, right);
            return(true);
        }
Esempio n. 9
0
        internal void OnSpawn(SpawnMessage msg)
        {
            if (msg.assetId == Guid.Empty && msg.sceneId == 0)
            {
                throw new InvalidOperationException("OnObjSpawn netId: " + msg.netId + " has invalid asset Id");
            }
            if (logger.LogEnabled())
            {
                logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}");
            }

            bool spawned = false;

            // was the object already spawned?
            NetworkIdentity identity = GetExistingObject(msg.netId);

            if (identity == null)
            {
                //is the object on the prefab or scene object lists?
                identity = msg.sceneId == 0 ? SpawnPrefab(msg) : SpawnSceneObject(msg);
                spawned  = true;
            }

            if (identity == null)
            {
                //object could not be found.
                throw new InvalidOperationException($"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}");
            }

            ApplySpawnPayload(identity, msg);

            if (spawned)
            {
                Spawned.Invoke(identity);
            }
        }
Esempio n. 10
0
 public void EventSpawn()
 {
     spawnEvent.Invoke();
 }
Esempio n. 11
0
 public void SpawnEnemies()
 {
     OnSpawnTimer?.Invoke(levelSet.Items[currentLevel]);
     isGamePlayStarted.Value = true;
 }