Пример #1
0
    public virtual void Inicialize(MazeCell cell, MazeCell otherCell, MazeDirecction direction)
    {
        this.cell      = cell;
        this.otherCell = otherCell;
        this.direction = direction;

        cell.SetEdge(direction, this);
        transform.parent        = cell.transform;
        transform.localPosition = Vector3.zero;
        transform.localRotation = direction.ToRotation();
    }
Пример #2
0
    private void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirecction direcction)
    {
        MazeWall wall = Instantiate(WallPrefabs[Random.Range(0, WallPrefabs.Length)]);

        wall.Inicialize(cell, otherCell, direcction);

        if (otherCell != null)
        {
            wall = Instantiate(WallPrefabs[Random.Range(0, WallPrefabs.Length)]);
            wall.Inicialize(otherCell, cell, direcction.GetOpposite());
        }
    }
Пример #3
0
 public override void Inicialize(MazeCell cell, MazeCell otherCell, MazeDirecction direction)
 {
     base.Inicialize(cell, otherCell, direction);
     if (otherSideofDoor != null)
     {
         #pragma warning disable 0219
         Hinge.localScale = new Vector3(-1f, 1f, 1f);
         Vector3 p = Hinge.localPosition;
         p.x = -p.x;
         Hinge.localPosition = p;
         #pragma warning restore 0219
     }
 }
Пример #4
0
    private void CreatePassageInSameRoom(MazeCell cell, MazeCell other, MazeDirecction direction)
    {
        MazePassage passage = Instantiate(PassagePrefab);

        passage.Inicialize(cell, other, direction);
        passage = Instantiate(PassagePrefab);
        passage.Inicialize(other, cell, direction.GetOpposite());

        if (cell.Room != other.Room)
        {
            MazeRoom roomToAssimilate = other.Room;
            cell.Room.Assimilate(roomToAssimilate);
            rooms.Remove(roomToAssimilate);
            Destroy(roomToAssimilate);
        }
    }
Пример #5
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirecction direcction)
    {
        MazePassage prefab  = Random.value < DoorProbability ? DoorPrefab : PassagePrefab;
        MazePassage passage = Instantiate(prefab);

        passage.Inicialize(cell, otherCell, direcction);
        passage = Instantiate(prefab);
        if (passage is MazeDoor)
        {
            otherCell.Initialized(CreateRoom(cell.Room.SettingsIndex));
        }
        else
        {
            otherCell.Initialized(cell.Room);
        }
        passage.Inicialize(otherCell, cell, direcction.GetOpposite());
    }
Пример #6
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        int      currentIndex = activeCells.Count - 1;
        MazeCell currentCell  = activeCells[currentIndex];

        if (currentCell.IsFullyInitialized)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }
        MazeDirecction direcction  = currentCell.RandomUnitializedDirection;
        IntVector2     coordinates = currentCell.Coordinates + direcction.ToIntVector2();

        if (ContainsCoordinates(coordinates))
        {
            MazeCell neighbour = GetCell(coordinates);
            if (neighbour == null)
            {
                neighbour = CreateCell(coordinates);
                CreatePassage(currentCell, neighbour, direcction);
                activeCells.Add(neighbour);
            }
            else if (currentCell.Room.SettingsIndex == neighbour.Room.SettingsIndex)
            {
                CreatePassageInSameRoom(currentCell, neighbour, direcction);
            }
            else
            {
                CreateWall(currentCell, neighbour, direcction);
            }
        }
        else
        {
            CreateWall(currentCell, null, direcction);
        }
    }
Пример #7
0
 public override void Inicialize(MazeCell cell, MazeCell otherCell, MazeDirecction direction)
 {
     base.Inicialize(cell, otherCell, direction);
     transform.GetChild(0).GetComponent <Renderer>().material = cell.Room.Settings.wallMaterial;
 }
Пример #8
0
 public void SetEdge(MazeDirecction direction, MazeCellEdge edge)
 {
     edges[(int)direction] = edge;
     initializedEdgeCount += 1;
 }
Пример #9
0
 public MazeCellEdge GetEdge(MazeDirecction direction)
 {
     return(edges[(int)direction]);
 }
Пример #10
0
 public static Quaternion ToRotation(this MazeDirecction direcction)
 {
     return(rotations[(int)direcction]);
 }
Пример #11
0
 public static IntVector2 ToIntVector2(this MazeDirecction direcction)
 {
     return(Vectors[(int)direcction]);
 }
Пример #12
0
 public static MazeDirecction GetOpposite(this MazeDirecction direcction)
 {
     return(opposites[(int)direcction]);
 }