protected void Play(AudioPlayer ap) { if (poller != null && (!ap.Player || !ap.Player.gameObject.activeSelf)) { if (ap.PlayFrom) { ap.Player.transform.SetParent(ap.PlayFrom); ap.Player.transform.localPosition = Vector3.zero; } Debug.Log(("AudioService: Playing Clip - " + ap.Clip.name).Colored(Colors.magenta)); ap.Player = poller.Pop(); ap.Player.Play(); } }
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); } } } }