void GenerateHallForward(FloorTile refTile, bool hasExitTrigger = true)
    {
        FloorTile anchor = refTile;

        TilesPattern randomPattern = hallPatterns[Random.Range(0, hallPatterns.Count)];

        for (int i = 0; i < randomPattern.pattern.Count; i++)
        {
            GenerateRelativeToTileAt(anchor, TileDirection.Up, randomPattern.pattern[i].col2);
            lastTileGenerated.lifetime = baseDecay + (i * rowDecay) + Random.Range(-0.2f, 0.2f);
            lastTileGenerated.Setup();
            anchor = lastTileGenerated;

            GenerateRelativeToTileAt(anchor, TileDirection.Left, randomPattern.pattern[i].col1);
            lastTileGenerated.lifetime = baseDecay + (i * rowDecay) + Random.Range(-0.2f, 0.2f);
            if (lastLeftGenerated != null)
            {
                lastLeftGenerated.upTile = lastTileGenerated;
            }
            lastTileGenerated.downTile = lastLeftGenerated;
            lastTileGenerated.Setup();
            lastLeftGenerated = lastTileGenerated;

            GenerateRelativeToTileAt(anchor, TileDirection.Right, randomPattern.pattern[i].col3);
            lastTileGenerated.lifetime = baseDecay + (i * rowDecay) + Random.Range(-0.2f, 0.2f);
            if (lastRightGenerated != null)
            {
                lastRightGenerated.upTile = lastTileGenerated;
            }
            lastTileGenerated.downTile = lastRightGenerated;
            lastTileGenerated.Setup();
            lastRightGenerated = lastTileGenerated;
        }

        lastMiddleGenerated = anchor;

        FloorTile exit = GetEmptyHallEndTile();

        if (exit != null)
        {
            exit.isCheckpoint = hasExitTrigger;
            lastTileGenerated = exit;
        }
        else
        {
            Debug.Log("No empty tiles to exit hall into corridor!");
        }
    }
Пример #2
0
    private void PlaceObject(int width, int height, GameObject objectToInstanciate, Transform holder, Tiles type, Vector2 itemSize, bool fillWith, int marginSize, bool placeByCenter)
    {
        TilesPattern patern         = new TilesPattern(width, height, Tiles.Floor);
        Vector2?     paternPosition = room.FindRandomPattern(patern.pattern);

        if (paternPosition == null)
        {
            Debug.LogWarning("Pattern not found for " + objectToInstanciate.name);
            return;
        }

        //Possibilité de margin de 1 ou pas
        //Possibilité de fillwith ou pas
        //Différente tailles d'item

        //----------------------- Vérifications -----------------------

        if (itemSize.x <= 0 || itemSize.y <= 0)
        {
            //Verification que le itemSize est possible
            Debug.LogError("Erreur itemSize : item size < 1" + " for " + objectToInstanciate.name);
            return;
        }

        if (marginSize != 0)
        {
            if (!fillWith)
            {
                //Verification d'une margin autour du pattern.
                if (itemSize.x + marginSize * 2 != width)
                {
                    Debug.LogError("Erreur MarginSize ; La largeur de l'item est de " + itemSize.x + " alors que la largeur du pattern est de " + width + " for " + objectToInstanciate.name);
                    return;
                }
                if (itemSize.y + marginSize * 2 != height)
                {
                    Debug.LogError("Erreur MarginSize ; La hauteur de l'item est de " + itemSize.y + " alors que la hauteur du pattern est de " + height + " for " + objectToInstanciate.name);
                    return;
                }
            }
            else
            {
                if (itemSize.x + marginSize * 2 > width)
                {
                    Debug.LogError("Erreur MarginSize fillWith ; La largeur de l'item est de " + itemSize.x + " alors que la largeur du pattern est de " + width + " for " + objectToInstanciate.name);
                    return;
                }
                if (itemSize.y + marginSize * 2 > height)
                {
                    Debug.LogError("Erreur MarginSize fillWith ; La hauteur de l'item est de " + itemSize.y + " alors que la hauteur du pattern est de " + height + " for " + objectToInstanciate.name);
                    return;
                }
            }
        }

        //if (fillWith && itemSize == Vector2.one)
        //{
        //    //Verification que le fill width est possible
        //    Debug.LogError("Erreur FillWith : item size = 1" + " for " + objectToInstanciate.name);
        //    return;
        //}

        //----------------------- Instanciation -----------------------

        if (fillWith)
        {
            for (int i = 0 + marginSize; i < width - marginSize; i++)
            {
                for (int j = 0 + marginSize; j < height - marginSize; j++)
                {
                    //Attention on ne prend pas en compte l'item size WTF si il ne fait pas 1...
                    Vector2 anchor = new Vector3(paternPosition.Value.x + i, paternPosition.Value.y + j);
                    if (placeByCenter)
                    {
                        anchor = GameManager.instance.GetCurrentGrid().WorldPointFromNode(anchor);
                    }
                    GameObject o = Instantiate(objectToInstanciate, anchor, Quaternion.identity) as GameObject;
                    o.transform.parent = holder;
                    room.AddPatternToMap((int)anchor.x, (int)anchor.y, 1, 1, type);
                }
            }
        }

        if (!fillWith)
        {
            //Il n'y a qu'un seul objet à instancier.
            Vector2 anchor = new Vector3(paternPosition.Value.x + marginSize, paternPosition.Value.y + marginSize);
            if (placeByCenter)
            {
                anchor = GameManager.instance.GetCurrentGrid().WorldPointFromNode(anchor);
            }
            GameObject o = Instantiate(objectToInstanciate, anchor, Quaternion.identity) as GameObject;
            o.transform.parent = holder;
            room.AddPatternToMap((int)anchor.x, (int)anchor.y, (int)itemSize.x, (int)itemSize.y, type);
        }
    }