Beispiel #1
0
    IEnumerator GenerateCoroutine(float Count)
    {
        yield return(new WaitForSeconds(Count));

        Shuffle(m_TouristPrefab);
        foreach (GameObject currentPrefab in m_TouristPrefab)
        {
            if (currentPrefab != null)
            {
                bool        CanGenerate = true;
                touristSize currentSize = currentPrefab.GetComponent <touristSize>();

                int currentNumberOfThisType = 0;
                //check if we can selectThisOne
                for (int i = 0; i < m_SpawnedPrefab.Count; i++)
                {
                    if (m_SpawnedPrefab[i] != null && m_SpawnedPrefab[i].GetComponent <touristSize>().destroy)
                    {
                        Destroy(m_SpawnedPrefab[i]);
                        continue;
                    }
                    if (m_SpawnedPrefab[i] != null && m_SpawnedPrefab[i].GetComponent <touristSize>().m_Type == currentSize.m_Type)
                    {
                        currentNumberOfThisType++;
                    }
                }

                foreach (TouristSpawningRule rule in m_TouristSpawningRules)
                {
                    if (rule.touristeType == currentSize.m_Type)
                    {
                        if (currentNumberOfThisType >= rule.MaxOccurence)
                        {
                            CanGenerate = false;
                        }
                        break;
                    }
                }
                //

                if (CanGenerate)
                {
                    List <TileComponent> tileArray = TileGenerator.GetFreeTileNearPlayer(minimumNearPlayer, maxNearPlayer);
                    Shuffle(tileArray);
                    foreach (TileComponent currentTileComponent in tileArray)
                    {
                        GameObject generatedGameObject = currentTileComponent.SpawnIfPossible(currentPrefab);
                        if (generatedGameObject != null)
                        {
                            m_SpawnedPrefab.Add(generatedGameObject);
                            yield break;
                        }
                    }

                    List <TileComponent> allTileArray = TileGenerator.GetFreeTileComponent();
                    Shuffle(allTileArray);

                    foreach (TileComponent currentTileComponent in allTileArray)
                    {
                        GameObject generatedGameObject = currentTileComponent.SpawnIfPossible(currentPrefab);
                        if (generatedGameObject != null)
                        {
                            m_SpawnedPrefab.Add(generatedGameObject);
                            yield break;
                        }
                    }
                }
            }
        }

        yield break;
    }