Exemplo n.º 1
0
    private void CacheArray(List <GameObject> gameObjects)
    {
        foreach (GameObject prefabObject in gameObjects)
        {
            if (prefabObject == null)
            {
                continue;
            }
            timings.Add(prefabObject, 0f);
        }

        foreach (GameObject prefabObject in gameObjects)
        {
            if (prefabObject == null)
            {
                continue;
            }
            AbstractSpawnable spawnable = prefabObject.GetComponent <AbstractSpawnable>();
            if (spawnable == null)
            {
                Debug.LogError("\nSpawnObject not founded in" + prefabObject.name);
                continue;
            }
            spawnables.Add(prefabObject, spawnable);
        }
    }
Exemplo n.º 2
0
    private Vector3 GetRandomPositionForSpawn(AbstractSpawnable spawnable)
    {
        Vector3 spawnPoint = Lib.RandomPointOnUnitCircle(spawnable.GetSpawnRange()) + Lib.Vector3ToVector2(targetTransform.position);

        spawnPoint = new Vector3(spawnPoint.x, spawnPoint.y, spawnable.GetZPosition());
        return(spawnPoint);
    }
Exemplo n.º 3
0
 private void DespawnObjects(List <GameObject> gameObjects)
 {
     foreach (GameObject currentGameObject in gameObjects)
     {
         AbstractSpawnable abstractSpawnable = GetSpawnObject(currentGameObject);
         ClearCache(currentGameObject);
         abstractSpawnable.Despawn();
     }
 }
Exemplo n.º 4
0
    private void SpawnAndCheckObjects(List <GameObject> gameObjects)
    {
        ShufflePrefabList(gameObjects);
        foreach (GameObject prefabObject in gameObjects)
        {
            try
            {
                if (prefabObject == null)
                {
                    continue;
                }
                if (CheckDelay(prefabObject) && CheckCount(prefabObject) && CheckWeight(prefabObject) && CheckDifficult(prefabObject))
                {
                    AbstractSpawnable spawnable = GetSpawnObject(prefabObject);
                    if (spawnable != null)
                    {
                        GameObject        spawnedGameObject     = Instantiate(prefabObject);
                        AbstractSpawnable spawnableInGameObject = spawnedGameObject.GetComponent <AbstractSpawnable>();
                        spawnableInGameObject.OnSpawn(GetRandomPositionForSpawn(spawnableInGameObject));
                        sumSpawnedObjectWeight += spawnableInGameObject.GetSpawnWeight();
                        spawnedObjects.Add(spawnedGameObject, prefabObject);
                        spawnables.Add(spawnedGameObject, spawnedGameObject.GetComponent <AbstractSpawnable>());
                        SetTimeSpawnForPrefab(prefabObject);
                    }
                    else
                    {
                        Debug.LogError("\nSpawnObject not founded in" + prefabObject.name);
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.Log(exception.Message);
            }
        }
        List <GameObject> gameObjectsForDespawn = new List <GameObject>();

        foreach (KeyValuePair <GameObject, GameObject> spawnedGameObject in spawnedObjects)
        {
            try
            {
                if (CheckRange(spawnedGameObject.Key))
                {
                }
                else
                {
                    gameObjectsForDespawn.Add(spawnedGameObject.Key);
                }
            }
            catch (Exception exception)
            {
                Debug.Log(exception.Message);
            }
        }
        DespawnObjects(gameObjectsForDespawn);
    }
Exemplo n.º 5
0
    private bool CheckRange(GameObject targerObject)
    {
        AbstractSpawnable spawnable = GetSpawnObject(targerObject);

        if ((Lib.Vector3ToVector2(targetTransform.position) - Lib.Vector3ToVector2(targerObject.transform.position)).magnitude > spawnable.GetDespawnRange())
        {
            return(false);
        }
        return(true);
    }
Exemplo n.º 6
0
    private bool CheckWeight(GameObject targetObject)
    {
        AbstractSpawnable spawnable = GetSpawnObject(targetObject);

        if (sumSpawnedObjectWeight + spawnable.GetSpawnWeight() <= GetCurrentMaxEntitySpawn())
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 7
0
    private bool CheckCount(GameObject targetObject)
    {
        int count = GetCountSpawnedObjects(targetObject);
        AbstractSpawnable spawnable = GetSpawnObject(targetObject);

        if (count < spawnable.GetMaxCount())
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 8
0
    private bool CheckDelay(GameObject targetObject)
    {
        float             timeFromSpawn = GetTimeFromSpawn(targetObject);
        AbstractSpawnable spawnable     = GetSpawnObject(targetObject);

        if (spawnable != null)
        {
            if (Time.time - timeFromSpawn >= (spawnable.GetSpawnDelay() / Mathf.Sqrt(GetCurrentDifficult())))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 9
0
    private bool CheckDifficult(GameObject targetObject)
    {
        AbstractSpawnable spawnable        = GetSpawnObject(targetObject);
        float             currentDifficult = GetCurrentDifficult();
        float             maxDiff          = spawnable.GetMaximumDiffucultToSpawn();
        float             minDiff          = spawnable.GetMinimalDifficultToSpawn();

        if (spawnable != null)
        {
            if ((maxDiff <= 0 || maxDiff > currentDifficult) && (minDiff < currentDifficult))
            {
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 10
0
        /// <summary>
        /// Spawning coroutine
        /// </summary>
        /// <returns>waiting time in seconds</returns>
        protected IEnumerator Spawn()
        {
            while (true)
            {
                Vector2           randomPoint   = Random.insideUnitCircle * _radius;
                Vector3           randomPoint3D = new Vector3(randomPoint.x, 0, randomPoint.y);
                AbstractSpawnable item          = ItemPrefabs[Random.Range(0, ItemPrefabs.Count)];
                if (GameManager.GetInstance().NetworkController.IsServer)
                {
                    Network.Instantiate(item, transform.position + randomPoint3D, item.transform.rotation, 0);
                }
                else
                {
                    Instantiate(item, transform.position + randomPoint3D, item.transform.rotation);
                }

                yield return(new WaitForSeconds(Random.Range(30f, 80f)));
            }
        }
Exemplo n.º 11
0
 private void EntityDead(GameObject targerObject)
 {
     if (targerObject.transform == targetTransform)
     {
         targetTransform = null;
     }
     if (spawnedObjects.Any(go => go.Key == targerObject))
     {
         AbstractSpawnable killedSpawnable = targerObject.GetComponent <AbstractSpawnable>();
         if (killedSpawnable != null)
         {
             sumKilledWeight += killedSpawnable.GetSpawnWeight();
             if (!isBossSpawned)
             {
                 if (TryToSpawnBoss())
                 {
                     return;
                 }
             }
         }
         ClearCache(targerObject);
     }
 }