예제 #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);
        }
예제 #2
0
        public static DeSpawnNotification Create(SpawnedObjectController controller)
        {
            if (controller == null)
            {
                throw new System.ArgumentNullException("controller");
            }

            DeSpawnNotification n;

            if (Notification.TryGetCache <DeSpawnNotification>(out n))
            {
                n._controller    = controller;
                n._spawnedObject = controller.gameObject;
            }
            else
            {
                n = new DeSpawnNotification(controller);
            }
            return(n);
        }