Exemple #1
0
        protected void PushAudioSource(AudioPlayer ap)
        {
            if (ap.PlayFrom)
            {
                ap.Player.transform.SetParent(poller.PollerTransform);
                ap.Player.transform.localPosition = Vector3.zero;
            }

            poller.Push(ap.Player);
            ap.Player.clip = null;
            ap.Player      = null;
        }
        private async Task Spawner(float time, CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                //wait time
                await UniTask.Delay(TimeSpan.FromSeconds(time), cancellationToken : token);

                //get a ball from the pool
                var ball = _pooler.Pop();

                //not null?
                if (ball)
                {
                    //initialize ball
                    ball.Initialize();

                    //change position
                    ball.transform.position = _spawner.position;

                    //Subscribe to HasCollided ReactiveProperty
                    ball.HasCollided.Subscribe(collided =>
                    {
                        //if true send it back into the pool
                        if (collided)
                        {
                            _pooler.Push(ball);
                        }
                    });

                    if (_poolWidget)
                    {
                        _poolWidget.UpdateWidgetValue(_pooler.SizeLimit, _pooler.ActiveElements);
                    }
                }
            }
        }