コード例 #1
0
ファイル: Door.cs プロジェクト: Notterox/SS3D
        /**
         * <summary>Spawns a wall cap facing a direction, with appropriate position & settings</summary>
         * <param name="direction">Direction from the centre of the door</param>
         */
        private GameObject SpawnWallCap(Direction direction)
        {
            var wallCap = EditorAndRuntime.InstantiatePrefab(wallCapPrefab, transform);

            Direction cardinalDirectionInput = TileHelper.GetRelativeDirection(direction, doorDirection);
            var       cardinal = TileHelper.ToCardinalVector(cardinalDirectionInput);
            var       rotation = TileHelper.AngleBetween(direction, doorDirection);


            wallCap.transform.localRotation = Quaternion.Euler(0, rotation, 0);
            wallCap.transform.localPosition = new Vector3(cardinal.Item1 * WALL_CAP_DISTANCE_FROM_CENTRE, 0, cardinal.Item2 * WALL_CAP_DISTANCE_FROM_CENTRE);

            return(wallCap);
        }
コード例 #2
0
ファイル: SimpleAdjacency.cs プロジェクト: Liam-Harrison/SS3D
        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
            });
        }
コード例 #3
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyBitmap adjacents)
        {
            // Count number of connections along cardinal (which is all that we use atm)
            var cardinalInfo = adjacents.GetCardinalInfo();

            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            if (cardinalInfo.IsO())
            {
                mesh = o;
            }
            else if (cardinalInfo.IsU())
            {
                mesh     = u;
                rotation = TileHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive());
            }
            else if (cardinalInfo.IsI())
            {
                mesh     = i;
                rotation = TileHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation());
            }
            else if (cardinalInfo.IsL())
            {
                mesh     = l;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, cardinalInfo.GetCornerDirection());
            }
            else if (cardinalInfo.IsT())
            {
                mesh     = t;
                rotation = TileHelper.AngleBetween(Direction.South, cardinalInfo.GetOnlyNegative());
            }
            else // Must be X
            {
                mesh = x;
            }

            return(new MeshDirectionInfo {
                mesh = mesh, rotation = rotation
            });
        }
コード例 #4
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
            });
        }
コード例 #5
0
ファイル: OffsetAdjacency.cs プロジェクト: Liam-Harrison/SS3D
        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
            });
        }
コード例 #6
0
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyBitmap adjacents)
        {
            // Count number of connections along cardinal (which is all that we use atm)
            var cardinalInfo = adjacents.GetCardinalInfo();

            // Determine rotation and mesh specially for every single case.
            float rotation = 0.0f;
            Mesh  mesh;

            if (cardinalInfo.IsO())
            {
                mesh        = o;
                orientation = OffsetOrientation.o;
            }
            else if (cardinalInfo.IsU())
            {
                if (cardinalInfo.north > 0 || cardinalInfo.east > 0)
                {
                    mesh        = uNorth;
                    orientation = OffsetOrientation.uNorth;
                }
                else
                {
                    mesh        = uSouth;
                    orientation = OffsetOrientation.uSouth;
                }
                rotation = TileHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive());
            }
            else if (cardinalInfo.IsI())
            {
                mesh        = i;
                orientation = OffsetOrientation.i;
                rotation    = TileHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation());
            }
            else if (cardinalInfo.IsL())
            {
                Direction sides = cardinalInfo.GetCornerDirection();
                mesh = sides == Direction.NorthEast ? lNE
                    : sides == Direction.SouthEast ? lSE
                    : sides == Direction.SouthWest ? lSW
                    : lNW;

                orientation = sides == Direction.NorthEast ? OffsetOrientation.lNE
                    : sides == Direction.SouthEast ? OffsetOrientation.lSE
                    : sides == Direction.SouthWest ? OffsetOrientation.lSW
                    : OffsetOrientation.lNW;

                rotation = 90;
            }
            else if (cardinalInfo.IsT())
            {
                Direction notside = cardinalInfo.GetOnlyNegative();
                mesh = notside == Direction.North ? tSWE
                    : notside == Direction.East ? tNSW
                    : notside == Direction.South ? tNEW
                    : tNSE;

                orientation = notside == Direction.North ? OffsetOrientation.tSWE
                    : notside == Direction.East ? OffsetOrientation.tNSW
                    : notside == Direction.South ? OffsetOrientation.tNEW
                    : OffsetOrientation.tNSE;

                rotation = 90;
            }
            else // Must be X
            {
                mesh        = x;
                orientation = OffsetOrientation.x;

                rotation = 90;
            }

            return(new MeshDirectionInfo {
                mesh = mesh, rotation = rotation
            });
        }
コード例 #7
0
ファイル: AdvancedAdjacency.cs プロジェクト: Notterox/SS3D
        public MeshDirectionInfo GetMeshAndDirection(AdjacencyBitmap adjacents)
        {
            var cardinalInfo = adjacents.GetCardinalInfo();

            float rotation = 0.0f;
            Mesh  mesh;

            if (cardinalInfo.IsO())
            {
                mesh = o;
            }
            else if (cardinalInfo.IsU())
            {
                mesh     = u;
                rotation = TileHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive());

                if (opaque)
                {
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(false);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(false);
                }
            }
            else if (cardinalInfo.IsI())
            {
                mesh     = i;
                rotation = TileHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation());

                if (opaque)
                {
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(false);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(true);
                }
            }
            else if (cardinalInfo.IsL())
            {
                // Determine lSolid or lCorner by finding whether the area between the two connections is filled
                // We check for if any of the following bitfields matches the connection bitfield
                // N+NE+E = 0/1/2, E+SE+S = 2/3/4, S+SW+W = 4/5/6, W+NW+N = 6/7/0
                bool isFilled = (adjacents.Connections & 0b00000111) == 0b00000111 || (adjacents.Connections & 0b00011100) == 0b00011100 || (adjacents.Connections & 0b01110000) == 0b01110000 || (adjacents.Connections & 0b11000001) == 0b11000001;
                mesh     = isFilled ? lSingle : lNone;
                rotation = TileHelper.AngleBetween(Direction.NorthEast, cardinalInfo.GetCornerDirection());

                if (opaque)
                {
                    viewObstacles[0].SetActive(false);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(false);
                }
            }
            else if (cardinalInfo.IsT())
            {
                // We make another bitfield (noticing a pattern?). 0x0 means no fills, 0x1 means right corner filled, 0x2 means left corner filled,
                // therefore both corners filled = 0x3.
                int corners = ((1 - cardinalInfo.north) * 2 | (1 - cardinalInfo.east)) * adjacents.Adjacent(Direction.SouthWest)
                              + ((1 - cardinalInfo.east) * 2 | (1 - cardinalInfo.south)) * adjacents.Adjacent(Direction.NorthWest)
                              + ((1 - cardinalInfo.south) * 2 | (1 - cardinalInfo.west)) * adjacents.Adjacent(Direction.NorthEast)
                              + ((1 - cardinalInfo.west) * 2 | (1 - cardinalInfo.north)) * adjacents.Adjacent(Direction.SouthEast);
                mesh = corners == 0 ? tNone
                    : corners == 1 ? tSingleLeft
                    : corners == 2 ? tSingleRight
                    : tDouble;

                rotation = TileHelper.AngleBetween(Direction.South, cardinalInfo.GetOnlyNegative());

                if (opaque)
                {
                    viewObstacles[0].SetActive(true);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(corners >= 3);
                }
            }
            else
            {
                // This sneaky piece of code uses the cardinal info to store diagonals by rotating everything -45 degrees
                // NE -> N, SW -> S, etc.
                var diagonals = new AdjacencyBitmap.CardinalInfo((byte)(adjacents.Connections >> 1));

                switch (diagonals.numConnections)
                {
                case 0:
                    mesh = xNone;
                    break;

                case 1:
                    mesh     = xSingle;
                    rotation = TileHelper.AngleBetween(Direction.South, diagonals.GetOnlyPositive());
                    break;

                case 2:
                    if (diagonals.north == diagonals.south)
                    {
                        mesh     = xOpposite;
                        rotation = TileHelper.AngleBetween(Orientation.Horizontal, diagonals.GetFirstOrientation());
                    }
                    else
                    {
                        mesh     = xSide;
                        rotation = TileHelper.AngleBetween(Direction.SouthEast, diagonals.GetCornerDirection());
                    }
                    break;

                case 3:
                    mesh     = xTriple;
                    rotation = TileHelper.AngleBetween(Direction.North, diagonals.GetOnlyNegative());
                    break;

                default:
                    mesh = xQuad;
                    break;
                }
                if (opaque)
                {
                    viewObstacles[0].SetActive(true);
                    viewObstacles[1].SetActive(true);
                    viewObstacles[2].SetActive(true);
                    viewObstacles[3].SetActive(true);
                }
            }

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