public override void Init() { Debug.Log("[TEST] GameManager.Init()"); inGameUI.SetActive(false); touchWidget.OnStartControl += HandleStartControl; touchWidget.OnEndControl += HandleEndControl; explosions = ObjectsPoolUtils.CreateBehavioursPool(() => { var explosion = Instantiate(explosionPrefab); explosion.OnComplete += () => explosions.Free(explosion); return(explosion); }, false); regularBombs = ObjectsPoolUtils.CreateBehavioursPool(() => { var bomb = Instantiate(regularBombPrefab); bomb.explosive.OnExplode += () => { var pos = bomb.transform.position; var explosion = explosions.Lock(); explosion.Explode(pos); soundManager.PlayExplosion(pos); regularBombs.Free(bomb); }; return(bomb); }, false); powerBombs = ObjectsPoolUtils.CreateBehavioursPool(() => { var bomb = Instantiate(powerBombPrefab); bomb.explosive.OnExplode += () => { var pos = bomb.transform.position; var explosion = explosions.Lock(); explosion.Explode(pos); soundManager.PlayExplosion(pos); powerBombs.Free(bomb); }; return(bomb); }, false); player = Instantiate(skins[0]); player.DORadius(testRadius, levelChangeDuration); cameraController.moveTarget = player.cameraAnchor; }
private IEnumerator PlayAudioCoroutine(Vector3 position, AudioClip clip) { var source = audioSources.Lock(); source.transform.position = position; source.clip = clip; source.Play(); yield return(new WaitForSeconds(clip.length)); audioSources.Free(source); }
public void Rebuild() { var len = 2 * Mathf.PI * radius; steps = Mathf.FloorToInt(len / segmentWidth); var count = _nodes.Count; if (count > steps) { // Если блоков в избытке - убираем for (int i = steps; i < count; i++) { _pool.Free(_nodes[i]); } _nodes.RemoveRange(steps, count - steps); } else if (count < steps) { // Если не хватает блоков - добавляем for (; count < steps; count++) { _nodes.Add(_pool.Lock()); } } Debug.Assert(_nodes.Count == steps); for (int i = 0; i < steps; i++) { var angle = 360f * i / steps; var item = _nodes[i]; item.localPosition = new Vector3( radius * Mathf.Cos(Mathf.Deg2Rad * angle), 0, radius * Mathf.Sin(Mathf.Deg2Rad * angle) ); item.localRotation = Quaternion.Euler(0, -angle + segmentAngle, 0); } }
private void LoadLevel(Level prefab) { if (_currentLevel != null) { var closure = _currentLevel; closure.DOMove(-levelSpawnHeight * Vector3.up * closure.radius, levelChangeDuration).OnComplete(() => { HierarchyUtils.SafeDestroy(closure.gameObject, 0.1f); }); } _currentLevel = Instantiate( prefab, levelSpawnHeight * Vector3.up * prefab.radius, Quaternion.identity, transform); _currentLevel.OnDestruct += HandleLevelSuccess; _currentLevel.DOMove(Vector3.zero, levelChangeDuration); var barrels = _currentLevel.GetComponentsInChildren <Barrel>(true); foreach (var barrel in barrels) { barrel.explosive.OnExplode += () => { var pos = barrel.transform.position; var explosion = explosions.Lock(); explosion.Explode(pos); soundManager.PlayExplosion(pos); }; } player.SetShootVelocity(_currentLevel.cannonBallStartVelocity); player.DORadius(prefab.radius, levelChangeDuration); }
private void HandleEndControl() { var bomb = regularBombs.Lock(); player.Shoot(bomb); }