예제 #1
0
    public GameObject SpawnIfPossible(GameObject touristPrefab)
    {
        touristSize tourist  = touristPrefab.GetComponent <touristSize>();
        int         rotation = TileMatching(TileGenerator.GetFreeTile(), tourist.takenSize, 0);

        if (rotation == -1)
        {
            return(null);
        }
        FillTouristTileComponent(tourist);
        Sprite  sprite     = gameObject.GetComponent <SpriteRenderer>().sprite;
        Vector2 SpriteSize = sprite.bounds.size;
        Vector3 position   = this.transform.position + new Vector3(SpriteSize.x * touristPrefab.GetComponent <touristSize>().GetTileOffset().x, SpriteSize.y * touristPrefab.GetComponent <touristSize>().GetTileOffset().y, 0);

        if (m_rotation == 1)
        {
            position = this.transform.position + new Vector3(SpriteSize.y * touristPrefab.GetComponent <touristSize>().GetTileOffset().y, SpriteSize.x * touristPrefab.GetComponent <touristSize>().GetTileOffset().x, 0);
        }

        GameObject touristSpawnGO = (GameObject)Instantiate(touristPrefab, position, Quaternion.identity);

        touristSpawnGO.transform.localEulerAngles = new Vector3(0, 0, (m_rotation == 1) ? 90 : 0);
        Debug.Log("SpawnPlayer in tile : " + (int)m_tileIndex.x + " " + (int)m_tileIndex.y);
        touristSpawnGO.GetComponent <touristSize>().SetOrderInLayer((int)m_tileIndex.x, (int)m_tileIndex.y);
        return(touristSpawnGO);
    }
    void ApplyTouristDebuf(touristSize touristSize)
    {
        float modifier = 1.0f;

        foreach (TouristModifier touristeModifier in m_modifier)
        {
            if (touristeModifier.touristeType == touristSize.m_Type)
            {
                modifier = touristeModifier.modifier;
            }
        }

        if (touristSize.BreakDownValue > 0)
        {
            CurrentBreakDownValue -= (int)((float)touristSize.BreakDownValue * modifier);
            BreakDownApply.Invoke(CurrentBreakDownValue);
            BreakText.text = "Break : " + CurrentBreakDownValue;
            if (CurrentBreakDownValue <= 0)
            {
                //gameOver
                GameStateManager.setGameState(GameState.GameOver);
                SceneManager.LoadSceneAsync(touristSize.GameOverSceneName);
            }
        }
    }
예제 #3
0
    void FillTouristTileComponent(touristSize tourist)
    {
        List <Vector2> returnList = new List <Vector2>();

        //playerSpawnPossibility.GetComponent<touristSize>().takenSize;
        Vector2[] touristSizesCopy = new Vector2[tourist.takenSize.Length];
        for (int i = 0; i < touristSizesCopy.Length; i++)
        {
            touristSizesCopy[i] = new Vector2(tourist.takenSize[i].x, tourist.takenSize[i].y);
        }

        foreach (Vector2 currentTouristSize in touristSizesCopy)
        {
            returnList.Add(m_tileIndex + currentTouristSize);
        }

        tourist.SetReservedTileIndex(returnList);
    }
    void ApplyNearTourist()
    {
        List <Vector2> nearPlayerTourist = TileGenerator.GetTouristTileNearPlayer(1);

        foreach (GameObject currentTouriste in TouristSpawnManager.m_instance.m_SpawnedPrefab)
        {
            if (currentTouriste != null)
            {
                touristSize    currentTouristSize = currentTouriste.GetComponent <touristSize>();
                List <Vector2> touristeTiles      = currentTouristSize.ReservedTileIndex;
                foreach (Vector2 currentTileNearPlayerTourist in nearPlayerTourist)
                {
                    if (touristeTiles.Contains(currentTileNearPlayerTourist))
                    {
                        ApplyTouristDebuf(currentTouristSize);
                        break;
                    }
                }
            }
        }
    }
예제 #5
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;
    }