public static bool SignalOnBeforeSpawnNotification(ISpawner spawnPoint, GameObject prefab, IList <ISpawnerModifier> modifiers)
        {
            var beforeNotif = SpawnPointBeforeSpawnNotification.Create(spawnPoint, prefab);

            if (modifiers != null && modifiers.Count > 0)
            {
                for (int i = 0; i < modifiers.Count; i++)
                {
                    if (modifiers[i] != null)
                    {
                        modifiers[i].OnBeforeSpawnNotification(beforeNotif);
                    }
                }
            }
            Notification.PostNotification <SpawnPointBeforeSpawnNotification>(spawnPoint, beforeNotif, false);
            Notification.Release(beforeNotif);

            return(beforeNotif.Cancelled);
        }
        void ISpawnerModifier.OnBeforeSpawnNotification(SpawnPointBeforeSpawnNotification n)
        {
            var nodes = this.GetAllProxies().ToArray();

            if (nodes.Length == 0)
            {
                n.Cancelled = true;
                Debug.LogWarning("ProxySpawnPointManager is configured improperly, you must add child nodes.", this);
                return;
            }

            if (this.BlockSpawnIfAllBusy)
            {
                if (!nodes.Any((p) => !p.Busy))
                {
                    n.Cancelled = true;
                    return;
                }
            }
        }
Exemplo n.º 3
0
        void ISpawnerModifier.OnBeforeSpawnNotification(SpawnPointBeforeSpawnNotification n)
        {
            if (!this.IsActiveAndEnabled())
            {
                return;
            }

            if (n.SpawnPoint.TotalCount >= this._maxCount)
            {
                n.Cancelled = true;
            }
            else if (n.SpawnPoint.ActiveCount >= this._maxActiveCount)
            {
                n.Cancelled = true;
            }
            else if (_maxActiveReachedTriggered)
            {
                _maxActiveReachedTriggered = false;
            }
        }
Exemplo n.º 4
0
        public static SpawnPointBeforeSpawnNotification Create(ISpawner spawnPoint, GameObject prefab)
        {
            if (spawnPoint == null)
            {
                throw new System.ArgumentNullException("spawnPoint");
            }

            SpawnPointBeforeSpawnNotification n;

            if (Notification.TryGetCache <SpawnPointBeforeSpawnNotification>(out n))
            {
                n._spawnPoint = spawnPoint;
                n._prefab     = prefab;
            }
            else
            {
                n = new SpawnPointBeforeSpawnNotification(spawnPoint, prefab);
            }
            return(n);
        }
 void ISpawnerModifier.OnBeforeSpawnNotification(SpawnPointBeforeSpawnNotification n)
 {
 }
        public SpawnedObjectController SpawnAsController(GameObject prefab, Vector3 pos, Quaternion rot, Transform par = null, System.Action <GameObject> initializeProperties = null)
        {
            if (_spawnPoint == null)
            {
                throw new System.InvalidOperationException("SpawnerMechanism must be initialized before calling Spawn.");
            }
            if (!_active)
            {
                return(null);
            }
            if (prefab == null)
            {
                return(null);
            }

            /*
             * using (var modifiers = TempCollection.GetList<ISpawnerModifier>())
             * {
             *  SpawnPointHelper.GetSpawnModifiers(_spawnPoint, modifiers);
             *
             *  if(SpawnPointHelper.SignalOnBeforeSpawnNotification(_spawnPoint, prefab, modifiers))
             *  {
             *      return null;
             *  }
             *
             *  //perform actual spawn
             *  var controller = this.SpawnPool.SpawnAsController(prefab, pos, rot, par, initializeProperties, _spawnPoint);
             *  if (controller == null) return null;
             *  _spawnedObjects.Add(controller);
             *  _totalCount++;
             *  //end actual spawn
             *
             *  SpawnPointHelper.SignalOnSpawnedNotification(_spawnPoint, this.SpawnPool, controller.gameObject, modifiers);
             *
             *  return controller;
             * }
             */

            //on before spawn
            var beforeNotif = SpawnPointBeforeSpawnNotification.Create(_spawnPoint, prefab);

            if (_modifiers != null && _modifiers.Count > 0)
            {
                var e = _modifiers.GetEnumerator();
                while (e.MoveNext())
                {
                    e.Current.OnBeforeSpawnNotification(beforeNotif);
                }
            }
            Notification.PostNotification <SpawnPointBeforeSpawnNotification>(_spawnPoint, beforeNotif, false);
            Notification.Release(beforeNotif);

            if (beforeNotif.Cancelled)
            {
                return(null);
            }

            //perform actual spawn
            var controller = this.SpawnPool.SpawnAsController(prefab, pos, rot, par, initializeProperties, _spawnPoint);

            if (controller == null)
            {
                return(null);
            }
            _spawnedObjects.Add(controller);
            _totalCount++;
            //end actual spawn

            //on post spawn
            var spawnNotif = SpawnPointTriggeredNotification.Create(this.SpawnPool, controller.gameObject, _spawnPoint);

            if (_modifiers != null && _modifiers.Count > 0)
            {
                var e = _modifiers.GetEnumerator();
                while (e.MoveNext())
                {
                    e.Current.OnSpawnedNotification(spawnNotif);
                }
            }
            Notification.PostNotification <SpawnPointTriggeredNotification>(_spawnPoint, spawnNotif, false);
            Notification.Release(spawnNotif);

            return(controller);
        }