void ISpawnerModifier.OnSpawnedNotification(SpawnPointTriggeredNotification n)
 {
     if (this.WaitToSpawnIfAllBusy)
     {
         var nodes = this.GetAllProxies().ToArray();
         var node  = (from p in nodes where !p.Busy select p).PickRandom();
         if (node != null)
         {
             node.PlaceOnSpawn(n.SpawnPoint, n.SpawnFactory, n.SpawnedObject);
         }
         else
         {
             n.SpawnedObject.SetActive(false);
             _delayedQueue.Enqueue(n);
             _onReleaseBusyStatusPool.AddRange(nodes);
         }
     }
     else
     {
         var node = this.GetAllProxies().PickRandom();
         if (node != null)
         {
             node.PlaceOnSpawn(n.SpawnPoint, n.SpawnFactory, n.SpawnedObject);
         }
         else
         {
             Debug.LogWarning("ProxySpawnPointManager is configured improperly, you must add child nodes.", this);
         }
     }
 }
Пример #2
0
        public new static SpawnPointTriggeredNotification Create(ISpawnFactory factory, GameObject spawnedObject, ISpawner spawnPoint)
        {
            if (factory == null)
            {
                throw new System.ArgumentNullException("factory");
            }
            if (spawnedObject == null)
            {
                throw new System.ArgumentNullException("spawnedObject");
            }

            SpawnPointTriggeredNotification n;

            if (Notification.TryGetCache <SpawnPointTriggeredNotification>(out n))
            {
                n._factory       = factory;
                n._spawnedObject = spawnedObject;
                n._spawnPoint    = spawnPoint;
            }
            else
            {
                n = new SpawnPointTriggeredNotification(factory, spawnedObject, spawnPoint);
            }
            return(n);
        }
        public static void SignalOnSpawnedNotification(ISpawner spawnPoint, ISpawnFactory factory, GameObject spawnedObject, IList <ISpawnerModifier> modifiers)
        {
            var spawnNotif = SpawnPointTriggeredNotification.Create(factory, spawnedObject, spawnPoint);

            if (modifiers != null && modifiers.Count > 0)
            {
                for (int i = 0; i < modifiers.Count; i++)
                {
                    if (modifiers[i] != null)
                    {
                        modifiers[i].OnSpawnedNotification(spawnNotif);
                    }
                }
            }
            Notification.PostNotification <SpawnPointTriggeredNotification>(spawnPoint, spawnNotif, false);
            Notification.Release(spawnNotif);
        }
Пример #4
0
        void ISpawnerModifier.OnSpawnedNotification(SpawnPointTriggeredNotification n)
        {
            if (!this.IsActiveAndEnabled())
            {
                return;
            }

            if (!_maxActiveReachedTriggered && n.SpawnPoint.ActiveCount == this._maxActiveCount)
            {
                _maxActiveReachedTriggered = true;
                _onMaxActiveCountReached.ActivateTrigger(this, null);
            }
            if (!_maxCountReachedTriggered && n.SpawnPoint.TotalCount == this._maxCount)
            {
                _maxCountReachedTriggered = true;
                _onMaxCountReached.ActivateTrigger(this, null);
            }
        }
Пример #5
0
        internal void PlaceOnSpawn(ISpawner spawnPoint, ISpawnFactory spawnPool, GameObject spawnedObject)
        {
            if (_busy)
            {
                return;
            }
            if (this.FlagBusyOnSpawn)
            {
                _busy = true;
            }

            spawnedObject.transform.position = this.transform.position;
            spawnedObject.transform.rotation = this.transform.rotation;

            var n = SpawnPointTriggeredNotification.Create(spawnPool, spawnedObject, spawnPoint);

            Notification.PostNotification <SpawnPointTriggeredNotification>(this, n, false);
            Notification.Release(n);
        }
        void ISpawnerModifier.OnSpawnedNotification(SpawnPointTriggeredNotification n)
        {
            var go = n.SpawnedObject;

            switch (this.TranslationInheritance)
            {
            case TransformInheritance.Relative:
                go.transform.position = this.transform.TransformPoint(this.Translation);
                break;

            case TransformInheritance.Local:
                go.transform.localPosition = this.Translation;
                break;

            case TransformInheritance.Global:
                go.transform.position = this.Translation;
                break;

            case TransformInheritance.Additive:
                go.transform.position += this.Translation;
                break;
            }

            switch (this.RotationInheritance)
            {
            case TransformInheritance.Relative:
                go.transform.rotation = this.transform.TransformRotation(this.Rotation);
                break;

            case TransformInheritance.Local:
                go.transform.localRotation = this.Rotation;
                break;

            case TransformInheritance.Global:
                go.transform.rotation = this.Rotation;
                break;

            case TransformInheritance.Additive:
                go.transform.rotation *= this.Rotation;
                break;
            }

            switch (this.ScaleInheritance)
            {
            case TransformInheritance.Relative:
                go.transform.localScale = this.Scale;
                break;

            case TransformInheritance.Local:
                go.transform.localScale = this.Scale;
                break;

            case TransformInheritance.Global:
                go.transform.localScale = this.Scale;
                break;

            case TransformInheritance.Additive:
                go.transform.localScale += this.Scale;
                break;
            }
        }
        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);
        }