Exemple #1
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);
        }
Exemple #2
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;
                }
            }
        }