예제 #1
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap)
        {
            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            AdjacencyShape shape = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap);

            switch (shape)
            {
            case AdjacencyShape.O:
                mesh = o;
                break;

            case AdjacencyShape.U:
                mesh     = u;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection());
                break;

            case AdjacencyShape.I:
                mesh     = i;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East);
                break;

            case AdjacencyShape.L:
                mesh     = l;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections());
                break;

            case AdjacencyShape.T:
                mesh     = t;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.X:
                mesh = x;
                break;

            default:
                Debug.LogError($"Received unexpected shape from simple shape resolver: {shape}");
                mesh = o;
                break;
            }

            return(new MeshDirectionInfo {
                Mesh = mesh, Rotation = rotation
            });
        }
예제 #2
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap)
        {
            float rotation = 0.0f;
            Mesh  mesh;

            AdjacencyShape shape = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap);

            switch (shape)
            {
            case AdjacencyShape.O:
                mesh = o;
                break;

            case AdjacencyShape.U:
                mesh     = u;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection());
                break;

            case AdjacencyShape.I:
                mesh     = i;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East);
                break;

            case AdjacencyShape.LNone:
                mesh     = lNone;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections());
                break;

            case AdjacencyShape.LSingle:
                mesh     = lSingle;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections());
                break;

            case AdjacencyShape.TNone:
                mesh     = tNone;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.TSingleLeft:
                mesh     = tSingleLeft;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.TSingleRight:
                mesh     = tSingleRight;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.TDouble:
                mesh     = tDouble;
                rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.XNone:
                mesh = xNone;
                break;

            case AdjacencyShape.XSingle:
                mesh = xSingle;
                Direction connectingDiagonal = adjacencyMap.GetSingleConnection(false);
                rotation = connectingDiagonal == Direction.NorthEast ? 0f :
                           connectingDiagonal == Direction.SouthEast ? 90f :
                           connectingDiagonal == Direction.SouthWest ? 180f : -90f;
                break;

            case AdjacencyShape.XOpposite:
                mesh     = xOpposite;
                rotation = adjacencyMap.HasConnection(Direction.NorthEast) ? 0f : 90f;
                break;

            case AdjacencyShape.XSide:
                mesh     = xSide;
                rotation = TileHelper.AngleBetween(Direction.NorthWest, adjacencyMap.GetDirectionBetweenTwoConnections(false)) - 45f;
                break;

            case AdjacencyShape.XTriple:
                mesh = xTriple;
                Direction nonConnectingDiagonal = adjacencyMap.GetSingleNonConnection(false);
                rotation = nonConnectingDiagonal == Direction.NorthEast ? -90f :
                           nonConnectingDiagonal == Direction.SouthEast ? 0f :
                           nonConnectingDiagonal == Direction.SouthWest ? 90f : 180f;
                break;

            case AdjacencyShape.XQuad:
                mesh = xQuad;
                break;

            default:
                Debug.LogError($"Received unexpected shape from advanced shape resolver: {shape}");
                mesh = o;
                break;
            }

            //If someone knows of a more elegant way to do the same without switching the same variable twice, I'd like to hear it :)
            if (opaque)
            {
                switch (shape)
                {
                case AdjacencyShape.U:
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(false);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(false);
                    break;

                case AdjacencyShape.I:
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(false);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(true);
                    break;

                case AdjacencyShape.LNone:
                case AdjacencyShape.LSingle:
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(false);
                    break;

                case AdjacencyShape.TNone:
                case AdjacencyShape.TSingleLeft:
                case AdjacencyShape.TSingleRight:
                    viewObstacles[0].SetActive(true);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(false);
                    viewObstacles[3].SetActive(true);
                    break;

                case AdjacencyShape.TDouble:
                case AdjacencyShape.XNone:
                case AdjacencyShape.XSingle:
                case AdjacencyShape.XOpposite:
                case AdjacencyShape.XSide:
                case AdjacencyShape.XTriple:
                case AdjacencyShape.XQuad:
                    viewObstacles[0].SetActive(true);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(true);
                    break;
                }
            }

            return(new MeshDirectionInfo {
                Mesh = mesh, Rotation = rotation
            });
        }
예제 #3
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap)
        {
            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            AdjacencyShape shape = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap);

            switch (shape)
            {
            case AdjacencyShape.O:
                mesh        = o;
                orientation = OffsetOrientation.o;
                break;

            case AdjacencyShape.UNorth:
                mesh        = uNorth;
                orientation = OffsetOrientation.uNorth;
                rotation    = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection());
                break;

            case AdjacencyShape.USouth:
                mesh        = uSouth;
                orientation = OffsetOrientation.uSouth;
                rotation    = TileHelper.AngleBetween(Direction.South, adjacencyMap.GetSingleNonConnection());
                break;

            case AdjacencyShape.I:
                mesh        = i;
                orientation = OffsetOrientation.i;
                rotation    = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East);
                break;

            case AdjacencyShape.LNorthWest:
                mesh        = lNW;
                orientation = OffsetOrientation.lNW;
                rotation    = 90;
                break;

            case AdjacencyShape.LNorthEast:
                mesh        = lNE;
                orientation = OffsetOrientation.lSE;
                rotation    = 90;
                break;

            case AdjacencyShape.LSouthEast:
                mesh        = lSE;
                orientation = OffsetOrientation.lSW;
                rotation    = 90;
                break;

            case AdjacencyShape.LSouthWest:
                mesh        = lSW;
                orientation = OffsetOrientation.lNW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthSouthEast:
                mesh        = tNSE;
                orientation = OffsetOrientation.tSWE;
                rotation    = 90;
                break;

            case AdjacencyShape.TSouthWestEast:
                mesh        = tSWE;
                orientation = OffsetOrientation.tNSW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthSouthWest:
                mesh        = tNSW;
                orientation = OffsetOrientation.tNEW;
                rotation    = 90;
                break;

            case AdjacencyShape.TNorthEastWest:
                mesh        = tNEW;
                orientation = OffsetOrientation.tNSE;
                rotation    = 90;
                break;

            case AdjacencyShape.X:
                mesh        = x;
                orientation = OffsetOrientation.x;
                rotation    = 90;
                break;

            default:
                Debug.LogError($"Received unexpected shape from offset shape resolver: {shape}");
                mesh = o;
                break;
            }

            return(new MeshDirectionInfo {
                Mesh = mesh, Rotation = rotation
            });
        }