Exemplo n.º 1
0
 private Slider GetSliderOnTile(Tile tile, SideName side)
 {
     if (tile != null)
     {
         if (tile.GetType() == typeof(Slider))
         {
             Slider slider = (Slider)tile;
             //slider moves left/right if left side is not attachable, so it moves on this rail
             if (!RobuzzleUtilities.IsTileAttachableOnSide(slider, side))
             {
                 return(slider);
             }
         }
         else if (tile.GetType() == typeof(SliderRail))
         {
             SliderRail rail = (SliderRail)tile;
             if (RobuzzleUtilities.IsTileAttachableOnOppositeSide(rail, side))
             {
                 return(GetSliderOnTile(
                            grid.GetTileAtPosition(tile.Position + RobuzzleUtilities.GetSideVector(side)),
                            side));
             }
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        private void TryJoiningNeighbor(MovableTile tile, Tile neighbor, SideName side)
        {
            if (IsMovable(neighbor)) // the neighbor is attachable/movable
            {
                MovableTile neighborMovableTile = (MovableTile)neighbor;
                bool        neighborAttachableOnOppositeSide =
                    RobuzzleUtilities.IsTileAttachableOnOppositeSide(neighborMovableTile, side);

                if (neighborAttachableOnOppositeSide) //the tile and neighbor can join together
                {
                    //if the tile neighbor tile are not already attached
                    if (!AreAttached(tile, neighborMovableTile))
                    {
                        RigidbodyTile RBTile = GetRigidbodyTile(tile);
                        if (RBTile != null)//If neighbor already has a rigidbody, attach both rigidbodies
                        {
                            JoinNeighbor(RBTile, neighborMovableTile, side);
                        }
                        else//join simple movable tile with neighbors -> or can that be done somewhere else
                        {
                            RigidbodyTile RBNeighbor = GetRigidbodyTile(neighborMovableTile);
                            if (RBNeighbor != null)
                            {
                                JoinNeighbor(RBNeighbor, tile, RobuzzleUtilities.GetOppositeSide(side)); //this tile is on the left of neighbor
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void SetSliderBound(Slider slider, Tile tile, SideName side)
 {
     if (tile != null && tile.GetType() == typeof(SliderRail))
     {
         SliderRail rail = (SliderRail)tile;
         if (RobuzzleUtilities.IsTileAttachableOnOppositeSide(rail, side))
         {
             if (RobuzzleUtilities.IsPositiveSide(side))
             {
                 slider.MaxBound = GetExtremeBoundNIgnoreCollision(slider, rail, side);
             }
             else
             {
                 slider.MinBound = GetExtremeBoundNIgnoreCollision(slider, rail, side);
             }
         }
     }
 }
Exemplo n.º 4
0
        private Vector3Int GetExtremeBoundNIgnoreCollision(Slider slider, SliderRail rail, SideName side)
        {
            Physics.IgnoreCollision(slider.transform.GetChild(0).GetComponent <Collider>(), rail.transform.GetChild(0).GetComponent <Collider>(), true);
            grid.RemoveTile(rail);
            if (RobuzzleUtilities.IsTileAttachableOnSide(rail, side))
            {
                Tile tile = grid.GetTileAtPosition(rail.Position + RobuzzleUtilities.GetSideVector(side));
                if (tile != null && tile.GetType() == typeof(SliderRail))
                {
                    SliderRail rail2 = (SliderRail)tile;
                    if (RobuzzleUtilities.IsTileAttachableOnOppositeSide(rail2, side))
                    {
                        return(GetExtremeBoundNIgnoreCollision(slider, rail2, side));
                    }
                }
                return(rail.Position);
            }

            return(Vector3Int.zero);
        }