Example #1
0
        /// <summary>
        /// Return an object to the pool.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>Returns true if the object was returned to the pool, false if destroyed.</returns>
        internal bool Despawn(SpawnedObjectController obj)
        {
            if (Object.ReferenceEquals(obj, null))
            {
                throw new System.ArgumentNullException("obj");
            }

            obj.BroadcastMessage(SPSpawnConstants.MSG_ONDESPAWN, SendMessageOptions.DontRequireReceiver);
            var n = DeSpawnNotification.Create(obj);

            Notification.PostNotification <DeSpawnNotification>(obj, n, false);
            Notification.PostNotification <DeSpawnNotification>(this, n, false);
            Notification.Release(n);

            var e = _registeredPrefabs.GetEnumerator();

            while (e.MoveNext())
            {
                if (e.Current.Contains(obj))
                {
                    e.Current.Despawn(obj);
                    return(true);
                }
            }

            //if we reached here, it's not managed by this pool... destroy
            GameObject.Destroy(obj.gameObject);
            return(false);
        }
Example #2
0
 public SpawnPoolPurgedNotification(SpawnedObjectController controller)
 {
     if (controller == null)
     {
         throw new System.ArgumentNullException("controller");
     }
     _controller    = controller;
     _spawnedObject = controller.gameObject;
 }
Example #3
0
 internal void Purge(SpawnedObjectController obj)
 {
     if (_activeInstances.Contains(obj))
     {
         _activeInstances.Remove(obj);
     }
     if (_instances.Contains(obj))
     {
         _instances.Remove(obj);
     }
 }
Example #4
0
            internal bool Purge(SpawnedObjectController cntrl)
            {
                if (_activeInstances.Remove(cntrl))
                {
                    return(true);
                }
                if (_instances.Remove(cntrl))
                {
                    return(true);
                }

                return(false);
            }
Example #5
0
        private void SignalSpawned(SpawnedObjectController obj, ISpawner spawnPoint)
        {
            if (obj == null)
            {
                return;
            }


            var n = SpawnNotification.Create(this, obj.gameObject, spawnPoint);

            obj.gameObject.BroadcastMessage(SPSpawnConstants.MSG_ONSPAWN, n, SendMessageOptions.DontRequireReceiver);
            Notification.PostNotification(obj, n, false);
            Notification.PostNotification(this, n, false);
            Notification.Release(n);
        }
Example #6
0
            internal bool Despawn(SpawnedObjectController cntrl)
            {
                if (!_activeInstances.Remove(cntrl))
                {
                    return(false);
                }

                cntrl.SetDespawned();
                cntrl.transform.parent        = _owner.transform;
                cntrl.transform.localPosition = Vector3.zero;
                cntrl.transform.rotation      = Quaternion.identity;

                _instances.Add(cntrl);
                return(true);
            }
Example #7
0
            internal void Despawn(SpawnedObjectController obj)
            {
                if (!_activeInstances.Contains(obj))
                {
                    return;
                }

                _activeInstances.Remove(obj);

                obj.SetDespawned();
                obj.transform.parent        = _owner.transform;
                obj.transform.localPosition = Vector3.zero;
                obj.transform.rotation      = Quaternion.identity;

                _instances.Add(obj);
            }
Example #8
0
        public bool Purge(SpawnedObjectController cntrl)
        {
            if (object.ReferenceEquals(cntrl, null))
            {
                throw new System.ArgumentNullException("cntrl");
            }

            PrefabCache cache;

            if (!_prefabToCache.TryGetValue(cntrl.PrefabID, out cache) || !cache.Contains(cntrl))
            {
                return(false);
            }

            return(cache.Purge(cntrl));
        }
Example #9
0
        internal bool Despawn(SpawnedObjectController cntrl)
        {
            if (Object.ReferenceEquals(cntrl, null))
            {
                throw new System.ArgumentNullException("cntrl");
            }

            PrefabCache cache;

            if (!_prefabToCache.TryGetValue(cntrl.PrefabID, out cache) || !cache.ContainsActive(cntrl))
            {
                return(false);
            }

            this.gameObject.Broadcast <IOnDespawnHandler, SpawnedObjectController>(cntrl, (o, c) => o.OnDespawn(c));
            cntrl.gameObject.Broadcast <IOnDespawnHandler, SpawnedObjectController>(cntrl, (o, c) => o.OnDespawn(c));
            return(cache.Despawn(cntrl));
        }
Example #10
0
        public static SpawnPoolPurgedNotification Create(SpawnedObjectController controller)
        {
            if (controller == null)
            {
                throw new System.ArgumentNullException("controller");
            }

            SpawnPoolPurgedNotification n;

            if (Notification.TryGetCache <SpawnPoolPurgedNotification>(out n))
            {
                n._controller    = controller;
                n._spawnedObject = controller.gameObject;
            }
            else
            {
                n = new SpawnPoolPurgedNotification(controller);
            }
            return(n);
        }
Example #11
0
        /// <summary>
        /// If a GameObject is being destroyed, this method will purge it from the SpawnPool.
        /// </summary>
        /// <param name="obj"></param>
        internal void Purge(SpawnedObjectController obj)
        {
            if (Object.ReferenceEquals(obj, null))
            {
                throw new System.ArgumentNullException("obj");
            }

            var n = SpawnPoolPurgedNotification.Create(obj);

            Notification.PostNotification <SpawnPoolPurgedNotification>(obj, n, false);
            Notification.PostNotification <SpawnPoolPurgedNotification>(this, n, false);
            Notification.Release(n);

            var e = _registeredPrefabs.GetEnumerator();

            while (e.MoveNext())
            {
                if (e.Current.Contains(obj))
                {
                    e.Current.Purge(obj);
                    return;
                }
            }
        }
Example #12
0
 public bool Contains(SpawnedObjectController obj)
 {
     return(_instances.Contains(obj) || _activeInstances.Contains(obj));
 }
Example #13
0
 internal bool ContainsActive(SpawnedObjectController cntrl)
 {
     return(_activeInstances.Contains(cntrl));
 }
Example #14
0
 private void SignalSpawned(SpawnedObjectController cntrl)
 {
     this.gameObject.Broadcast <IOnSpawnHandler, SpawnedObjectController>(cntrl, (o, c) => o.OnSpawn(c));
     cntrl.gameObject.Broadcast <IOnSpawnHandler, SpawnedObjectController>(cntrl, (o, c) => o.OnSpawn(c));
 }