void Start()
 {
     PrefabPoolingSystem.Prespawn(_orcPrefab, 11);
     PrefabPoolingSystem.Prespawn(_trollPrefab, 8);
     PrefabPoolingSystem.Prespawn(_ogrePrefab, 5);
     PrefabPoolingSystem.Prespawn(_dragonPrefab, 1);
 }
示例#2
0
 public void BackToHome()
 {
     Time.timeScale         = 1;
     GameScore.LvlCompleted = false;
     PrefabPoolingSystem.Reset();
     StartCoroutine(LoadAsynchronously(0));
 }
 public static PoolablePrefabData Spawn(this PrefabData prefabData, Vector2 position, Quaternion rotation)
 {
     return(PrefabPoolingSystem.Spawn(
                prefabData.prefab,
                position,
                rotation));
 }
 public static List <PoolablePrefabData> Install(this PrefabData prefabData)
 {
     return(PrefabPoolingSystem.Prespawn(
                prefabData.prefab,
                prefabData.count,
                prefabData.parent));
 }
示例#5
0
    //// Public API
    public ProjectileSystem(Transform parent)
    {
        GameObject projectilePrefab = Resources.Load("Prefabs/Projectile") as GameObject;

        this._gameManager = GameManager.Instance;
        this._pool        = new PrefabPoolingSystem(projectilePrefab, _gameManager.ProjectilePoolSize, parent);
    }
    void SpawnObject(GameObject prefab, List <GameObject> list)
    {
        GameObject obj = PrefabPoolingSystem.Spawn(prefab,
                                                   5.0f * Random.insideUnitSphere,
                                                   Quaternion.identity);

        list.Add(obj);
    }
示例#7
0
    void Awake()
    {
        _prefabs = _gameSkin.enemyPrefabs;

        _resetMinSpawnTimePeriod = _minSpawnTimePeriod;
        _resetMaxSpawnTimePeriod = _maxSpawnTimePeriod;

        PrefabPoolingSystem.Prespawn(_prefabs, _mobileSpawnPoints[0].transform.position, _mobileSpawnPoints[0].transform.rotation, 3);
    }
示例#8
0
    internal override void Die()
    {
        base.Die();

        if (laserHitVFX)
        {
            PrefabPoolingSystem.Despawn(laserHitVFX);
        }
    }
示例#9
0
    //Needs to reset bonus in gameController
    //Needs to reset extra second counter in gameController
    private void OutOfScreenDestroy()
    {
        if (!_isFriendly)
        {
            GameController.Instance.ResetBonus();
        }

        PrefabPoolingSystem.Despawn(this.gameObject);
    }
示例#10
0
    public override void Update()
    {
        CountDownAndShoot();
        SetLaserPos();

        if (lazer.isVisible)
        {
            raycast = Physics2D.Raycast(transform.localPosition, Vector2.down, 20f, layerMask);

            if (raycast)
            {
                lazer.SetPosition(1, new Vector2(lazer.transform.position.x, player.transform.position.y - 0.05f));

                player.TakeDamage(currentLazerDamage);

                // SOUND
                if (!laserHitPlayer.isPlaying)
                {
                    laserHitPlayer.Play();
                }

                // VFX
                if (laserHitVFX == null)
                {
                    laserHitVFX = PrefabPoolingSystem.Spawn(laserHitVFXPrefab, player.transform.localPosition, Quaternion.identity);
                }
                else
                {
                    laserHitVFX.transform.localPosition = player.transform.localPosition;
                }
            }
            else
            {
                // SOUND
                if (laserHitPlayer.isPlaying)
                {
                    laserHitPlayer.Stop();
                }

                // VFX
                if (laserHitVFX != null)
                {
                    PrefabPoolingSystem.Despawn(laserHitVFX);
                    laserHitVFX = null;
                }
            }
        }
        else
        {
            if (laserHitVFX != null)
            {
                PrefabPoolingSystem.Despawn(laserHitVFX);
                laserHitVFX = null;
            }
        }
    }
示例#11
0
    private void DelayDestory()
    {
        if (_isFriendly)
        {
            GameController.Instance.TimePenalty(_timePenalty);
            GameController.Instance.ResetBonus();
        }

        PrefabPoolingSystem.Despawn(this.gameObject);
    }
示例#12
0
    private void Awake()
    {
        _instance = this;

        PrefabPoolingSystem.Reset();

        _resetBonusCntLimit = _bonusCntLimit;

        StartGame();
    }
示例#13
0
    internal virtual void Die()
    {
        PrefabPoolingSystem.Spawn(deathVFXPrefab, transform.localPosition, Quaternion.identity);

        AudioSource.PlayClipAtPoint(deathSound, mainCamera, deathSoundVolume);

        GameSession.instance.AddToScore(currentScore);

        PrefabPoolingSystem.Despawn(gameObject);
    }
示例#14
0
    /*
     * Called by UI button Button_Replay in Canvas_GameOver
     * OnClick() Unity Event
     */
    public void ReplayGame()
    {
        PrefabPoolingSystem.ClearAll();

        InitFields();

        UIManager.Instance.UpdateScore(GameScore.CurrentScore);

        _gameOverCanvas.gameObject.SetActive(false);
        _uiCanvas.gameObject.SetActive(true);
    }
示例#15
0
    //// Public API
    public ConstructionSystem(Transform constructionsParent)
    {
        GameObject towerPrefab = Resources.Load("Prefabs/Tower") as GameObject;
        GameObject wallPrefab  = Resources.Load("Prefabs/Wall") as GameObject;

        this._gameManager = GameManager.Instance;
        this._towerPool   = new PrefabPoolingSystem(towerPrefab, _gameManager.TowerPoolSize, constructionsParent);
        this._wallPool    = new PrefabPoolingSystem(wallPrefab, _gameManager.WallPoolSize, constructionsParent);

        _mode = _gameManager.Interaction;
    }
    void DespawnRandomObject(List <GameObject> list)
    {
        if (list.Count == 0)
        {
            return;
        }
        int i = Random.Range(0, list.Count);

        PrefabPoolingSystem.Despawn(list[i]);
        list.RemoveAt(i);
    }
示例#17
0
    public void ResetLength()
    {
        foreach (var segment in _ropeSegments)
        {
            PrefabPoolingSystem.Despawn(segment.gameObject);
        }

        _ropeSegments.Clear();

        isDecreasing = isIncreasing = false;
        InitializeRope();
    }
    private void RemoveHealth(Health health)
    {
        if (!_healthBars.TryGetValue(health, out HealthBar healthBar))
        {
#if UNITY_EDITOR
            Debug.LogError("Health not found in HealthBars dictionary!", this);
#endif
            return;
        }

        _healthBars.Remove(health);
        PrefabPoolingSystem.Despawn(healthBar.gameObject);
    }
示例#19
0
    private void TakeDamage(DamageDealer damageDealer, Collider2D collision)
    {
        currentHealth -= damageDealer.GetDamage();

        if (currentHealth <= 0)
        {
            Die();
        }
        else
        {
            AudioSource.PlayClipAtPoint(collision.GetComponent <Projectile>().GetImpactSound(),
                                        mainCamera, collision.GetComponent <Projectile>().GetImpactSoundVolume());


            PrefabPoolingSystem.Spawn(collision.GetComponent <Projectile>().GetImpactVFX(), transform.localPosition, Quaternion.identity);
        }
    }
示例#20
0
    private IEnumerator SpawnAllEnemies(WaveConfig waveConfig)
    {
        float      timeBtwnSpawns = waveConfig.GetTimeBtwnSpawns();
        GameObject enemyPrefab    = waveConfig.GetEnemyPrefab();
        Vector3    startPos       = waveConfig.GetWayPoints()[0].transform.localPosition;

        for (int i = 0; i < waveConfig.GetNumberOfEnemies(); i++)
        {
            GameObject enemy = PrefabPoolingSystem.Spawn(enemyPrefab, startPos, Quaternion.identity);

            enemy.GetComponent <EnemyPathing>().SetWaveConfig(waveConfig);

            enemy.GetComponent <Enemy>().IncreaseStats(statsFactor);

            yield return(new WaitForSeconds(timeBtwnSpawns));
        }
    }
示例#21
0
    //Async Enemy Spawn on predefined time delay
    IEnumerator SpawnEnemy()
    {
        while (true)
        {
            float bombProbability = Random.Range(0f, 1f);
            float prevRandomPoint = 0f;

            int enemyPrefabIndex;
            int prevEnemyPrefabIndex = 0;

            if (bombProbability < .93f)
            {
                enemyPrefabIndex = Random.Range(0, _prefabs.Length - 1);
            }
            else
            {
                enemyPrefabIndex = _prefabs.Length - 1;
            }


            float _spawnTimePeriod = Random.Range(_minSpawnTimePeriod, _maxSpawnTimePeriod);

            float randomPoint = Random.Range(-2f, 2f);

            if (Mathf.Abs(randomPoint - prevRandomPoint) < 0.5f && ((enemyPrefabIndex == _prefabs.Length - 1) || (prevEnemyPrefabIndex == _prefabs.Length - 1)))
            {
                if (randomPoint < 0)
                {
                    randomPoint += 1f;
                }
                else
                {
                    randomPoint -= 1f;
                }
            }

            prevRandomPoint      = randomPoint;
            prevEnemyPrefabIndex = enemyPrefabIndex;


            PrefabPoolingSystem.Spawn(_prefabs[enemyPrefabIndex], new Vector3(randomPoint, -6f, 0f), new Quaternion(0f, 0f, 0f, 0f));

            yield return(new WaitForSeconds(_spawnTimePeriod));
        }
    }
示例#22
0
    private void Awake()
    {
        GameObject playerProjectilesGO = new GameObject("Player Projectiles");

        playerProjectilesGO.transform.SetParent(gameObject.transform);

        GameObject enemiesProjectilesGO = new GameObject("Enemies Projectiles");

        enemiesProjectilesGO.transform.SetParent(gameObject.transform);

        GameObject VFXGO = new GameObject("VFX");

        VFXGO.transform.SetParent(gameObject.transform);

        GameObject enemiesGO = new GameObject("Enemies");

        enemiesGO.transform.SetParent(gameObject.transform);

        // Player Projectiles
        PrefabPoolingSystem.Prespawn(playerProjectiles[0], 6, playerProjectilesGO.transform);
        PrefabPoolingSystem.Prespawn(playerProjectiles[1], 12, playerProjectilesGO.transform);
        PrefabPoolingSystem.Prespawn(playerProjectiles[2], 4, playerProjectilesGO.transform);

        // Enemies Projectiles
        PrefabPoolingSystem.Prespawn(enemiesProjectiles[0], 20, enemiesProjectilesGO.transform);
        PrefabPoolingSystem.Prespawn(enemiesProjectiles[1], 20, enemiesProjectilesGO.transform);
        PrefabPoolingSystem.Prespawn(enemiesProjectiles[2], 20, enemiesProjectilesGO.transform);

        // VFX
        PrefabPoolingSystem.Prespawn(VFX[0], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[1], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[2], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[3], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[4], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[5], 10, VFXGO.transform);
        PrefabPoolingSystem.Prespawn(VFX[6], 10, VFXGO.transform);

        // Enemies
        PrefabPoolingSystem.Prespawn(enemies[0], 10, enemiesGO.transform);
        PrefabPoolingSystem.Prespawn(enemies[1], 10, enemiesGO.transform);
        PrefabPoolingSystem.Prespawn(enemies[2], 6, enemiesGO.transform);
        PrefabPoolingSystem.Prespawn(enemies[3], 6, enemiesGO.transform);
    }
示例#23
0
    IEnumerator LoadGameInBackground(int previousSceneIndex)
    {
        // Reset Static Vars
        PrefabPoolingSystem.Reset();
        gameSession.ResetGame();
        //-------------------------

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(1, LoadSceneMode.Additive);

        asyncLoad.allowSceneActivation = false;

        // Wait until the scene fully loads
        // (Stops at 0.9 due to allowSceneActivation = false)
        while (asyncLoad.progress < 0.9f)
        {
            yield return(null);
        }

        // Wait for Input
        // (the player press "Play")
        while (!startGame)
        {
            yield return(null);
        }

        // Wait a Frame until the Scene is Active
        yield return(asyncLoad.allowSceneActivation = true);

        // Optional
        //SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));

        // Wait a Frame until the previous Scene is Unloaded
        Scene previousScene = SceneManager.GetSceneByBuildIndex(previousSceneIndex);

        if (previousScene.isLoaded)
        {
            yield return(SceneManager.UnloadSceneAsync(previousSceneIndex));
        }

        musicPlayer.PlayGame();
        startGame = false;
    }
示例#24
0
    private void OnTapDestroy()
    {
        if (!System.Object.ReferenceEquals(_animator, null))
        {
            _animator.Play("Destroy");
            Invoke("DelayDestory", _animator.runtimeAnimatorController.animationClips[1].length);
        }
        else
        {
            if (_isFriendly)
            {
                GameController.Instance.TimePenalty(5f);
                GameController.Instance.ResetBonus();
            }

            PrefabPoolingSystem.Despawn(this.gameObject);
        }

        GameController.Instance.UpdateScore(_enemyScoreValue);
    }
示例#25
0
    private void Move()
    {
        if (waypointIndex < finalIndex)
        {
            movementThisFrame = moveSpeed * Time.deltaTime;

            transform.localPosition = Vector2.MoveTowards(transform.localPosition, targetPos, movementThisFrame);

            if (transform.localPosition == targetPos)
            {
                waypointIndex++;

                if (waypointIndex < finalIndex)
                {
                    targetPos = waypoints[waypointIndex].transform.localPosition;
                }
            }
        }
        else
        {
            PrefabPoolingSystem.Despawn(gameObject);
        }
    }
示例#26
0
 public void LoadLevel(int sceneIndex)
 {
     Time.timeScale = 1;
     PrefabPoolingSystem.Reset();
     StartCoroutine(LoadAsynchronously(sceneIndex));
 }
示例#27
0
 // Start is called before the first frame update
 void Start()
 {
     PrefabPoolingSystem.Prespawn(_orcPrefab, _numToSpawn);
 }
示例#28
0
 private void FireLvl1()
 {
     PrefabPoolingSystem.Spawn(projectile1Prefab, transform.localPosition + new Vector3(-0.5f, 0.3f, 0f), Quaternion.identity);
     PrefabPoolingSystem.Spawn(projectile1Prefab, transform.localPosition + new Vector3(0.5f, 0.3f, 0f), Quaternion.identity);
 }
示例#29
0
 private void FireLvl2()
 {
     PrefabPoolingSystem.Spawn(projectile2Prefab, transform.localPosition + new Vector3(0f, 0.7f, 0f), Quaternion.identity);
 }
示例#30
0
 private void OnTriggerEnter2D()
 {
     PrefabPoolingSystem.Despawn(gameObject);
 }