Ejemplo n.º 1
0
        /// <summary>
        ///     Binds the lifetime of the pool to the <see cref="GameObject" />.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static AddressablesPool BindTo(this AddressablesPool self, GameObject gameObject)
        {
            if (gameObject == null)
            {
                self.Dispose();
                throw new ArgumentNullException(nameof(gameObject));
            }

            if (!gameObject.TryGetComponent(out MonoBehaviourDestroyedEventDispatcher eventDispatcher))
            {
                eventDispatcher = gameObject.AddComponent <MonoBehaviourDestroyedEventDispatcher>();
            }

            return(self.BindTo(eventDispatcher));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Binds the lifetime of the pool to the <see cref="eventDispatcher" />.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="eventDispatcher"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static AddressablesPool BindTo(this AddressablesPool self, IEventDispatcher eventDispatcher)
        {
            if (eventDispatcher == null)
            {
                self.Dispose();
                throw new ArgumentNullException(nameof(eventDispatcher));
            }

            void OnDispatch()
            {
                if (!self.IsDisposed)
                {
                    self.Dispose();
                }

                eventDispatcher.OnDispatch -= OnDispatch;
            }

            eventDispatcher.OnDispatch += OnDispatch;
            return(self);
        }