Exemple #1
0
    public void AddBrowserPlane(int pxWidth, int pxHeight, string defaultURL, WallSide sideToAdd)
    {
        if (pxWidth <= 0 || pxHeight <= 0)
        {
            return;
        }

        PlaneMesh newPlane = PlaneMeshFactory.GetPlane(pxWidth, pxHeight, "PlaneMesh", true, defaultURL);

        if (browserPlanes.Count == 0)
        {
            newPlane.go.transform.position = Vector3.zero;
            browserPlanes.AddFirst(newPlane);
            middleBrowserPlane = browserPlanes.First;
            return;
        }

        if (sideToAdd == WallSide.LEFT)
        {
            newPlane.go.transform.position = GetSidePos(WallSide.LEFT);
            browserPlanes.AddFirst(newPlane);
        }
        else // (sideToAdd == WallSide.RIGHT)
        {
            newPlane.go.transform.position = GetSidePos(WallSide.RIGHT);
            browserPlanes.AddLast(newPlane);
        }
    }
            public static Face GetFace(FaceArray faces, WallSide side)
            {
                double elevation     = 0;
                double tempElevation = 0;
                Mesh   mesh;
                Face   face = null;

                foreach (Face _face in faces)
                {
                    tempElevation = 0;
                    mesh          = _face.Triangulate();
                    foreach (XYZ xyz in mesh.Vertices)
                    {
                        tempElevation += xyz.Y;
                    }
                    tempElevation /= mesh.Vertices.Count;

                    if (side == WallSide.Exterior && (elevation < tempElevation || null == face))
                    {
                        face      = _face;
                        elevation = tempElevation;
                    }
                    else if (side == WallSide.Interior && (elevation > tempElevation || null == face))
                    {
                        face      = _face;
                        elevation = tempElevation;
                    }
                }

                return(face);
            }
            public static Face GetWallFace(Wall wall, View view, WallSide side)
            {
                Face      face  = null;
                FaceArray faces = new FaceArray();

                Options options = new Options();

                options.ComputeReferences = true;
                options.View = view;

                if (wall != null)
                {
                    IEnumerator <GeometryObject> objects = wall.get_Geometry(options).GetEnumerator();
                    while (objects.MoveNext())
                    {
                        var currentObject = objects.Current;
                        var solid         = currentObject as Solid;
                        if (solid != null)
                        {
                            faces = solid.Faces;
                        }
                    }

                    face = GetFace(faces, side);
                }

                return(face);
            }
Exemple #4
0
 public BrowserParams(int pxWidth_, int pxHeight_, string url_, WallSide side = WallSide.LEFT)
 {
     pxWidth  = pxWidth_;
     pxHeight = pxHeight_;
     url      = url_;
     wallSide = side;
 }
 private void OnCollisionExit2D(Collision2D collision)
 {
     // Reset Wall Detection
     attachedToWall = WallSide.NONE;
     // Increment Jump Count
     jumpCount++;
     // Disable Wall Jump
     canWallJump = false;
 }
Exemple #6
0
        } //end Method FillCylinderShadow

        /// <summary>
        ///     Get Side Color
        /// </summary>
        /// <param name="color"></param>
        /// <param name="side"></param>
        /// <returns>Color</returns>
        public static Color GetSideColor(Color color, WallSide side)
        {
            var bright = 1.0f;

            var a = color.A;
            var r = color.R;
            var g = color.G;
            var b = color.B;

            switch (side)
            {
            case WallSide.Back:
            {
                bright = 1.0f;
                break;
            }

            case WallSide.Front:
            {
                bright = 1.0f;
                break;
            }

            case WallSide.Left:
            {
                bright = 0.7f;
                break;
            }

            case WallSide.Right:
            {
                bright = 0.5f;
                break;
            }

            case WallSide.Top:
            {
                bright = 0.8f;
                break;
            }

            case WallSide.Bottom:
            {
                bright = 0.4f;
                break;
            }
            } //end swithc case

            r = (byte)(r / 2 + r * bright / 2);
            g = (byte)(g / 2 + g * bright / 2);
            b = (byte)(b / 2 + b * bright / 2);

            return(Color.FromArgb(a, r, g, b));
        }
Exemple #7
0
 public Wall(WallSide side)
 {
     Side              = side;
     Slots             = new Tile[5, 5];
     SlotConfiguration = new TileColor[5, 5] {
         { TileColor.Blue, TileColor.Yellow, TileColor.Red, TileColor.Black, TileColor.Turquoise },
         { TileColor.Turquoise, TileColor.Blue, TileColor.Yellow, TileColor.Red, TileColor.Black },
         { TileColor.Black, TileColor.Turquoise, TileColor.Blue, TileColor.Yellow, TileColor.Red },
         { TileColor.Red, TileColor.Black, TileColor.Turquoise, TileColor.Blue, TileColor.Yellow },
         { TileColor.Yellow, TileColor.Red, TileColor.Black, TileColor.Turquoise, TileColor.Blue }
     };
 }
Exemple #8
0
 public Board(WallSide side)
 {
     floorLine    = new List <Tile>(MAX_FLOORLINE_TILES);
     Wall         = new Wall(side);
     patternLines = new Dictionary <BoardRow, List <Tile> >(5)
     {
         { BoardRow.One, new List <Tile>(1) },
         { BoardRow.Two, new List <Tile>(2) },
         { BoardRow.Three, new List <Tile>(3) },
         { BoardRow.Four, new List <Tile>(4) },
         { BoardRow.Five, new List <Tile>(5) },
     };
 }
    private void CheckForWall()
    {
        isOnWall = false;
        RaycastHit hit;

        if (Physics.Raycast(transform.position, new Vector3(rb.velocity.x, 0, rb.velocity.z), out hit, 4))
        {
            if (hit.transform.tag == "Wall" && hit.transform.gameObject != prevWall)
            {
                Collider[] collidedObjects = Physics.OverlapSphere(rangeCollider.transform.position, rangeCollider.radius);
                for (int i = 0; i < collidedObjects.Length; i++)
                {
                    if (collidedObjects[i] == hit.collider)
                    {
                        if (Vector2.Angle(new Vector2(rb.velocity.x, rb.velocity.z), new Vector2(hit.normal.x, hit.normal.z)) <= 150 && Vector2.Angle(new Vector2(rb.velocity.x, rb.velocity.z), new Vector2(hit.normal.x, hit.normal.z)) > 90)
                        {
                            isOnWall            = true;
                            currentWall         = hit.transform.gameObject;
                            runIntoWallVelocity = rb.velocity;
                            SwitchState(MovementState.WallRun);

                            if (Vector2.Angle(new Vector2(transform.right.x, transform.right.z), new Vector2(hit.normal.x, hit.normal.z)) >= 90)
                            {
                                myWallSide = WallSide.Right;
                                camManager.Rotate(20, rb, -hit.normal);
                            }
                            else
                            {
                                myWallSide = WallSide.Left;
                                camManager.Rotate(-20, rb, hit.normal);
                            }
                            isCameraTilted = true;
                        }
                        else if (Vector2.Angle(new Vector2(rb.velocity.x, rb.velocity.z), new Vector2(hit.normal.x, hit.normal.z)) <= 180)
                        {
                            isOnWall            = true;
                            currentWall         = hit.transform.gameObject;
                            runIntoWallVelocity = rb.velocity;
                            myWallSide          = WallSide.Front;
                            SwitchState(MovementState.WallClimb);
                            //Wall climb
                        }
                        break;
                    }
                }
            }
        }
    }
    private void OnCollisionStay2D(Collision2D collision)
    {
        if (collision.collider.gameObject.layer == 12)
        {
            return;
        }

        // Get Points of Contact
        ContactPoint2D[] contactPoints = new ContactPoint2D[collision.contactCount];
        collision.GetContacts(contactPoints);

        // Iterate over contact points
        foreach (ContactPoint2D cp in contactPoints)
        {
            // Convert contact point to local space
            Vector2 point = transform.InverseTransformPoint(cp.point);

            // If point is low enough
            if (point.y <= -0.10f)
            {
                // Reset jump count
                jumpCount = 0;
                // Enable Jumping
                canJump = true;
            }
            else
            {
                // If this isn't a jump-through platform
                if (!collision.collider.GetComponent <PlatformEffector2D>())
                {
                    // Check direction and set wall detection
                    if (point.x < -0.07f)
                    {
                        attachedToWall = WallSide.LEFT;
                    }
                    if (point.x > 0.07f)
                    {
                        attachedToWall = WallSide.RIGHT;
                    }
                }
            }
        }
    }
Exemple #11
0
 private void Start()
 {
     if (transform.parent.name.Equals("Top Spawners"))
     {
         wallSide = WallSide.Top;
     }
     else if (transform.parent.name.Equals("Right Spawners"))
     {
         wallSide = WallSide.Right;
     }
     else if (transform.parent.name.Equals("Bottom Spawners"))
     {
         wallSide = WallSide.Bottom;
     }
     else if (transform.parent.name.Equals("Left Spawners"))
     {
         wallSide = WallSide.Left;
     }
 }
Exemple #12
0
 // Use this for initialization
 void Start()
 {
     if (gameObject.name == "Top")
     {
         side = WallSide.Top;
     }
     if (gameObject.name == "Right")
     {
         side = WallSide.Right;
     }
     if (gameObject.name == "Bottom")
     {
         side = WallSide.Bottom;
     }
     if (gameObject.name == "Left")
     {
         side = WallSide.Left;
     }
 }
    public void Jump(float magnitude = 1, float angle = 0)
    {
        // Check for valid value
        if (jumpHeight <= 0)
        {
            return;
        }

        // Get a target hight based on magnitude
        float targetHeight = jumpHeight * magnitude;

        // Get velocity based on target height
        float velocity = Mathf.Sqrt(-2.0f * Physics2D.gravity.y * targetHeight);

        // Create Vector
        Vector2 jumpVector = Vector2.up * (float.IsNaN(velocity) ? 0 : velocity);

        // If angle is specified
        if (angle != 0)
        {
            // Rotate vector
            float rad = angle * Mathf.Deg2Rad;
            float cos = Mathf.Cos(rad);
            float sin = Mathf.Sin(rad);
            jumpVector = new Vector2((jumpVector.x * cos) - (jumpVector.y * sin), (jumpVector.y * cos) - (jumpVector.x * sin));
        }

        // Apply velocity
        rb.velocity = new Vector2(rb.velocity.x + jumpVector.x, jumpVector.y);

        // Increment Jump Count
        jumpCount++;
        // If jump count reaches max disable jump
        if (jumpCount >= maxJumpCount)
        {
            canJump = false;
        }
        // Reset Wall Detection
        attachedToWall = WallSide.NONE;
        // Disable Wall Jump
        canWallJump = false;
    }
        Transform GetNewWall(WallSide wallSide, float verticalPosition)
        {
            Transform  _wall = null;
            GameObject _wallPoolToIterate = wallSide == WallSide.Left ? leftWallsPool : rightWallsPool;

            //if its the first walls to be instantiated, they must start on screen
            foreach (Transform wall in _wallPoolToIterate.transform)
            {
                if (!wall.gameObject.active)
                {
                    wall.gameObject.SetActive(true);


                    wall.transform.localPosition = new Vector3(wall.transform.localPosition.x, verticalPosition, -10);
                    _wall = wall;
                    break;
                }
            }

            return(_wall);
        }
Exemple #15
0
    //Tells the corrent rooms that they now have doors on them and gives them a
    //reference so they can be opened easily when that room is now empty
    private void MarkHasDoor(GameObject room, GameObject door, WallSide wallSide)
    {
        room.GetComponent <DngnRoomInfo>().HasDoor(door, wallSide);

        switch (wallSide)
        {
        case (WallSide.North):
            GameObject north = GetNorth(room);
            if (north != null)
            {
                north.GetComponent <DngnRoomInfo>().HasDoor(door, WallSide.South);
            }
            return;

        case (WallSide.East):
            GameObject east = GetEast(room);
            if (east != null)
            {
                east.GetComponent <DngnRoomInfo>().HasDoor(door, WallSide.West);
            }
            return;

        case (WallSide.South):
            GameObject south = GetSouth(room);
            if (south != null)
            {
                south.GetComponent <DngnRoomInfo>().HasDoor(door, WallSide.North);
            }
            return;

        case (WallSide.West):
            GameObject west = GetWest(room);
            if (west != null)
            {
                west.GetComponent <DngnRoomInfo>().HasDoor(door, WallSide.East);
            }
            return;
        }
    }
Exemple #16
0
    Vector3 GetSidePos(WallSide side)
    {
        DebugUtils.Assert((side == WallSide.LEFT || side == WallSide.RIGHT));
        if (browserPlanes.Count == 0)
        {
            return(Vector3.zero);
        }

        Transform neighborTransform;
        float     rtDirection = 1.0f;

        if (side == WallSide.LEFT)
        {
            neighborTransform = browserPlanes.First.Value.go.transform;
        }
        else // side == WallSide.RIGHT
        {
            neighborTransform = browserPlanes.Last.Value.go.transform;
            rtDirection       = -1.0f;
        }
        Vector3 rtAdjustment = browserPlanes.First.Value.worldWidth * neighborTransform.right;

        return(neighborTransform.position + rtDirection * rtAdjustment);
    }
Exemple #17
0
 public Player(WallSide side)
 {
     Board        = new Board(side);
     pendingTiles = new List <Tile>();
 }
Exemple #18
0
    private void PlaceDoor(GameObject target, WallSide wallSide)
    {
        DngnRoomInfo RoomInfo = target.GetComponent <DngnRoomInfo>();

        //Do not connect to empty rooms
        if (RoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            return;
        }
        //If there is already a wall in the direction we are trying to place
        //then we want to break out of the function
        //While were at it, get the position we are going to place the door if
        //we get that far, just so we dont need a second switch statement later on
        Vector3    DoorPos      = target.transform.position;
        GameObject AdjacentRoom = null;

        switch (wallSide)
        {
        case (WallSide.North):
            if (RoomInfo.m_hasNorthWall)
            {
                return;
            }
            AdjacentRoom = GetNorth(target);
            DoorPos     += Vector3.forward * (m_floorSize * 0.5f);
            break;

        case (WallSide.East):
            if (RoomInfo.m_hasEastWall)
            {
                return;
            }
            AdjacentRoom = GetEast(target);
            DoorPos     += Vector3.right * (m_floorSize * 0.5f);
            break;

        case (WallSide.South):
            if (RoomInfo.m_hasSouthWall)
            {
                return;
            }
            AdjacentRoom = GetSouth(target);
            DoorPos     += (-Vector3.forward) * (m_floorSize * 0.5f);
            break;

        case (WallSide.West):
            if (RoomInfo.m_hasWestWall)
            {
                return;
            }
            AdjacentRoom = GetWest(target);
            DoorPos     += (-Vector3.right) * (m_floorSize * 0.5f);
            break;
        }
        //Get info from the room we are going to place a door at
        DngnRoomInfo AdjacentRoomInfo = AdjacentRoom.GetComponent <DngnRoomInfo>();

        //Make sure there is a valid room in the direction we are trying
        if (AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Normal ||
            AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Start ||
            AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Boss)
        {
            //Spawn a new door
            GameObject Door = GameObject.Instantiate(m_doorPrefab, DoorPos, Quaternion.identity) as GameObject;
            //Parent it
            Door.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Door.transform.LookAt(target.transform.position);
            //Note there is now a door here
            switch (wallSide)
            {
            case (WallSide.North):
                //Mark that this room has a north door
                RoomInfo.m_hasNorthWall = true;
                //Give the room a reference to its door so it can be removed later
                MarkHasDoor(target, Door, WallSide.North);
                //Also mark the north room has a south door (its the same door between the two rooms)
                GameObject north = GetNorth(target);
                if (north != null)
                {
                    north.GetComponent <DngnRoomInfo>().m_hasSouthWall = true;
                }
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                MarkHasDoor(target, Door, WallSide.East);
                GameObject east = GetEast(target);
                if (east != null)
                {
                    east.GetComponent <DngnRoomInfo>().m_hasWestWall = true;
                }
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                MarkHasDoor(target, Door, WallSide.South);
                GameObject south = GetSouth(target);
                if (south != null)
                {
                    south.GetComponent <DngnRoomInfo>().m_hasNorthWall = true;
                }
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                MarkHasDoor(target, Door, WallSide.West);
                GameObject west = GetWest(target);
                if (west != null)
                {
                    west.GetComponent <DngnRoomInfo>().m_hasEastWall = true;
                }
                break;
            }
        }
    }
Exemple #19
0
 public Wall(Texture2D texture, Vector2 position, WallSide side = WallSide.Left, float scale = 1.0f) : base(texture, position, scale)
 {
     this.Side = side;
 }
Exemple #20
0
        private Geometry GetGeometry(int i, int j, int xScreen, int yScreen, Labyrinth laby)
        {
            if (i == 0 && j == 0)
            {
                PathGeometry path = new PathGeometry();
                PathFigure   pf   = new PathFigure()
                {
                    IsClosed = true, IsFilled = true
                };
                path.Figures.Add(pf);
                pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT);
                pf.Segments.Add(new ArcSegment()
                {
                    Size           = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2),
                    Point          = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2),
                    SweepDirection = SweepDirection.Clockwise
                });
                pf.Segments.Add(new LineSegment()
                {
                    Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT)
                });
                return(path);
            }
            else
            {
                RectangleGeometry r;
                PathGeometry      corner;
                PathFigure        pf;
                int      OffsetX;
                int      OffsetY;
                WallSide side = GetSide(i, j, laby);
                switch (side)
                {
                case WallSide.InnerTopLeft:
                case WallSide.TopLeft:
                    OffsetX = side == WallSide.InnerTopLeft ? Constants.GRID_WIDTH_2 : 0;
                    OffsetY = side == WallSide.InnerTopLeft ? Constants.GRID_HEIGHT_2 : 0;
                    corner  = new PathGeometry();
                    pf      = new PathFigure()
                    {
                        IsClosed = true, IsFilled = true
                    };
                    corner.Figures.Add(pf);
                    pf.StartPoint = new Point(xScreen + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY);
                    pf.Segments.Add(new ArcSegment()
                    {
                        Size           = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2),
                        Point          = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + OffsetY),
                        SweepDirection = SweepDirection.Clockwise
                    });
                    if (side == WallSide.InnerTopLeft)
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT)
                        });
                    }
                    else
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT)
                        });
                    }
                    return(corner);

                case WallSide.InnerTopRight:
                case WallSide.TopRight:
                    OffsetX = side == WallSide.InnerTopRight ? -Constants.GRID_WIDTH_2 : 0;
                    OffsetY = side == WallSide.InnerTopRight ? Constants.GRID_HEIGHT_2 : 0;
                    corner  = new PathGeometry();
                    pf      = new PathFigure()
                    {
                        IsClosed = true, IsFilled = true
                    };
                    corner.Figures.Add(pf);
                    pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + OffsetY);
                    pf.Segments.Add(new ArcSegment()
                    {
                        Size           = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2),
                        Point          = new Point(xScreen + Constants.GRID_WIDTH + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY),
                        SweepDirection = SweepDirection.Clockwise
                    });
                    if (side == WallSide.InnerTopRight)
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT)
                        });
                    }
                    else
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen)
                        });
                    }
                    return(corner);

                case WallSide.InnerBottomRight:
                case WallSide.BottomRight:
                    OffsetX = side == WallSide.InnerBottomRight ? -Constants.GRID_WIDTH_2 : 0;
                    OffsetY = side == WallSide.InnerBottomRight ? -Constants.GRID_HEIGHT_2 : 0;
                    corner  = new PathGeometry();
                    pf      = new PathFigure()
                    {
                        IsClosed = true, IsFilled = true
                    };
                    corner.Figures.Add(pf);
                    pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY);
                    pf.Segments.Add(new ArcSegment()
                    {
                        Size           = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2),
                        Point          = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + Constants.GRID_HEIGHT + OffsetY),
                        SweepDirection = SweepDirection.Clockwise
                    });
                    if (side == WallSide.InnerBottomRight)
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen)
                        });
                    }
                    else
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen)
                        });
                    }
                    return(corner);

                case WallSide.InnerBottomLeft:
                case WallSide.BottomLeft:
                    OffsetX = side == WallSide.InnerBottomLeft ? Constants.GRID_WIDTH_2 : 0;
                    OffsetY = side == WallSide.InnerBottomLeft ? -Constants.GRID_HEIGHT_2 : 0;
                    corner  = new PathGeometry();
                    pf      = new PathFigure()
                    {
                        IsClosed = true, IsFilled = true
                    };
                    corner.Figures.Add(pf);
                    pf.StartPoint = new Point(xScreen + Constants.GRID_WIDTH_2 + OffsetX, yScreen + Constants.GRID_HEIGHT + OffsetY);
                    pf.Segments.Add(new ArcSegment()
                    {
                        Size           = new Size(Constants.GRID_WIDTH_2, Constants.GRID_WIDTH_2),
                        Point          = new Point(xScreen + OffsetX, yScreen + Constants.GRID_HEIGHT_2 + OffsetY),
                        SweepDirection = SweepDirection.Clockwise
                    });
                    if (side == WallSide.InnerBottomLeft)
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen)
                        });
                    }
                    else
                    {
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen, yScreen)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH_2, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT_2)
                        });
                        pf.Segments.Add(new LineSegment()
                        {
                            Point = new Point(xScreen + Constants.GRID_WIDTH, yScreen + Constants.GRID_HEIGHT)
                        });
                    }
                    return(corner);

                case WallSide.Left:
                    r      = new RectangleGeometry();
                    r.Rect = new Rect(xScreen, yScreen, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT);
                    return(r);

                case WallSide.Right:
                    r      = new RectangleGeometry();
                    r.Rect = new Rect(xScreen + Constants.GRID_WIDTH_2, yScreen, Constants.GRID_WIDTH_2, Constants.GRID_HEIGHT);
                    return(r);

                case WallSide.Top:
                    r      = new RectangleGeometry();
                    r.Rect = new Rect(xScreen, yScreen, Constants.GRID_WIDTH, Constants.GRID_HEIGHT_2);
                    return(r);

                case WallSide.Bottom:
                    r      = new RectangleGeometry();
                    r.Rect = new Rect(xScreen, yScreen + Constants.GRID_HEIGHT_2, Constants.GRID_WIDTH, Constants.GRID_HEIGHT_2);
                    return(r);

                default:
                    return(null);
                }
            }
        }
    // Update is called once per frame
    void Update()
    {
        switch (ConstructionStage)
        {
        case CONSTRUCTION_STAGE.NOT_CONSTRUCTING:

            if (!GameObject.Find("BuildMenu"))
            {
                break;
            }

            if (GameObject.Find("BuildMenu").GetComponent <BuildButtonBehavior>().GetMenuOpen())
            {
                ConstructionStage = CONSTRUCTION_STAGE.SELECTION_BUILDING;
            }

            break;

        case CONSTRUCTION_STAGE.SELECTION_BUILDING:

            d_Timer = 0.0;

            if (!GameObject.Find("BuildMenu").GetComponent <BuildButtonBehavior>().GetMenuOpen())
            {
                ConstructionStage = CONSTRUCTION_STAGE.NOT_CONSTRUCTING;
            }

            if (m_ObjectToConstruct != null)
            {
                ConstructionStage = CONSTRUCTION_STAGE.SELECTION_POSITION;
            }
            break;

        case CONSTRUCTION_STAGE.SELECTION_POSITION:

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            // Preview Building
            if (Physics.Raycast(ray, out hit))
            {
                // Check if the object is either a grid or wall
                if ((hit.collider.gameObject.name == "Grid(Clone)" || hit.collider.gameObject.name.Contains("Wall")))
                {
                    Vector2 checkPos  = theGridBehaviour.GetWithinGridPos(hit.collider.gameObject.transform.position);
                    string  checkName = "";
                    for (int i = 0; i < PersistentData.m_Instance.BuildingGridPos.Count; ++i)
                    {
                        if (PersistentData.m_Instance.BuildingGridPos[i].Equals(new SerializableVector2(checkPos)))
                        {
                            checkName = PersistentData.m_Instance.BuildingName[i];
                            break;
                        }
                    }

                    if (hit.collider.gameObject.tag.Contains("Wall"))
                    {
                        m_WallObject = hit.collider.gameObject;
                    }

                    // Check if the spot is already taken
                    if (!PersistentData.m_Instance.BuildingGridPos.Contains(new SerializableVector2(checkPos)))
                    {
                        // If spot is not taken, show preview building
                        // Switch m_ObjectToConstruct back to regular variant
                        if (!hit.collider.gameObject.name.Contains("Wall"))
                        {
                            if (m_ObjectToConstruct.name.Contains("Wall") && m_ObjectToConstruct.tag.Equals("Tower") ||
                                m_ObjectToConstruct.name.Contains("Wall") && !m_ObjectToConstruct.name.Equals("Wall") && top == "Top" && bottom == "Bot" && left == "Left" && right == "Right")
                            {
                                m_ObjectToConstruct = m_OldObjectToConstruct;
                            }
                        }
                    }
                    else if (hit.collider.gameObject.name.Contains("Wall") && !hit.collider.gameObject.name.Contains("Turret"))
                    {
                        if (m_PreviewObject != null)
                        {
                            Destroy(m_PreviewObject);
                            m_PreviewObject = null;
                        }

                        // If spot is taken by a wall, preview wall turret
                        // Switch m_ObjectToConstruct to wall variant
                        if (hit.collider.gameObject.name.Contains("Wall") && !(m_ObjectToConstruct.name.Contains("Wall")))
                        {
                            if (m_ObjectToConstruct.name.Contains("Standard"))
                            {
                                m_OldObjectToConstruct = m_ObjectToConstruct;
                                m_ObjectToConstruct    = WallStandardTurret;
                            }
                            else if (m_ObjectToConstruct.name.Contains("Sniper"))
                            {
                                m_OldObjectToConstruct = m_ObjectToConstruct;
                                m_ObjectToConstruct    = WallSniperTurret;
                            }
                            else if (m_ObjectToConstruct.name.Contains("Heavy"))
                            {
                                m_OldObjectToConstruct = m_ObjectToConstruct;
                                m_ObjectToConstruct    = WallHeavyTurret;
                            }
                        }
                    }
                    // Wall Check Code
                    Vector2 TopCheck   = theGridBehaviour.GetGridPos(hit.collider.gameObject.transform.position) + new Vector2(0, 1);
                    Vector2 BotCheck   = theGridBehaviour.GetGridPos(hit.collider.gameObject.transform.position) + new Vector2(0, -1);
                    Vector2 LeftCheck  = theGridBehaviour.GetGridPos(hit.collider.gameObject.transform.position) + new Vector2(-1, 0);
                    Vector2 RightCheck = theGridBehaviour.GetGridPos(hit.collider.gameObject.transform.position) + new Vector2(1, 0);
                    for (int idx = 0; idx < PersistentData.m_Instance.BuildingGridPos.Count; ++idx)
                    {
                        if (TopCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            top = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (BotCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            bottom = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (LeftCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            left = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (RightCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            right = PersistentData.m_Instance.BuildingName[idx];
                        }
                    }
                    //Switch to Wall Towers
                    if (top.Contains("Wall") && left.Contains("Wall") && m_ObjectToConstruct.name.Equals("Wall") ||
                        top.Contains("Wall") && right.Contains("Wall") && m_ObjectToConstruct.name.Equals("Wall") ||
                        bottom.Contains("Wall") && left.Contains("Wall") && m_ObjectToConstruct.name.Equals("Wall") ||
                        bottom.Contains("Wall") && right.Contains("Wall") && m_ObjectToConstruct.name.Equals("Wall"))
                    {
                        if (!top.Contains("WallTower") && !bottom.Contains("WallTower") && !right.Contains("WallTower") && !left.Contains("WallTower"))
                        {
                            m_OldObjectToConstruct = m_ObjectToConstruct;
                            m_ObjectToConstruct    = WallTower;
                            top    = "Top";
                            bottom = "Bot";
                            left   = "Left";
                            right  = "Right";
                        }
                    }
                    //Switch to Corner Walls
                    else if (top.Contains("WallTower") && Side == WallSide.Left ||
                             bottom.Contains("WallTower") && Side == WallSide.Right ||
                             right.Contains("WallTower") && Side == WallSide.Top ||
                             left.Contains("WallTower") && Side == WallSide.Bot)
                    {
                        m_OldObjectToConstruct = m_ObjectToConstruct;
                        m_ObjectToConstruct    = RightCWall;
                        top    = "Top";
                        bottom = "Bot";
                        left   = "Left";
                        right  = "Right";
                    }
                    else if (top.Contains("WallTower") && Side == WallSide.Right ||
                             bottom.Contains("WallTower") && Side == WallSide.Left ||
                             right.Contains("WallTower") && Side == WallSide.Bot ||
                             left.Contains("WallTower") && Side == WallSide.Top)
                    {
                        m_OldObjectToConstruct = m_ObjectToConstruct;
                        m_ObjectToConstruct    = LeftCWall;
                        top    = "Top";
                        bottom = "Bot";
                        left   = "Left";
                        right  = "Right";
                    }
                    //Switch to Side Walls
                    else if (top.Contains("Wall") && !top.Contains("WallTower") && Side == WallSide.Right ||
                             bottom.Contains("Wall") && !bottom.Contains("WallTower") && Side == WallSide.Left ||
                             right.Contains("Wall") && !right.Contains("WallTower") && Side == WallSide.Bot ||
                             left.Contains("Wall") && !left.Contains("WallTower") && Side == WallSide.Top)
                    {
                        m_OldObjectToConstruct = m_ObjectToConstruct;
                        m_ObjectToConstruct    = RightWall;
                        top    = "Top";
                        bottom = "Bot";
                        left   = "Left";
                        right  = "Right";
                    }
                    else if (top.Contains("Wall") && !top.Contains("WallTower") && Side == WallSide.Left ||
                             bottom.Contains("Wall") && !bottom.Contains("WallTower") && Side == WallSide.Right ||
                             right.Contains("Wall") && !right.Contains("WallTower") && Side == WallSide.Top ||
                             left.Contains("Wall") && !left.Contains("WallTower") && Side == WallSide.Bot)
                    {
                        m_OldObjectToConstruct = m_ObjectToConstruct;
                        m_ObjectToConstruct    = LeftWall;
                        top    = "Top";
                        bottom = "Bot";
                        left   = "Left";
                        right  = "Right";
                    }

                    if (m_ObjectToConstruct.tag.Contains("Building") && hit.collider.gameObject.tag.Contains("Wall"))
                    {
                        return;
                    }

                    if (hit.collider.gameObject.name.Contains("WallTower"))
                    {
                        return;
                    }

                    //if (hit.collider.gameObject.tag.Contains("Tower"))
                    //    return;

                    // Create Preview Building if one does not exist
                    if ((m_PreviewObject == null && m_ObjectToConstruct.tag.Contains("Tower")) || (m_PreviewObject == null && !PersistentData.m_Instance.BuildingGridPos.Contains(new SerializableVector2(checkPos))))
                    {
                        m_PreviewObject = Instantiate(m_ObjectToConstruct, hit.collider.gameObject.transform.position + new Vector3(0, 0.1f, 0), hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, -90, 0))) as GameObject;
                    }
                    // Move the preview building
                    else
                    {
                        m_oldPos = m_PreviewObject.transform.position;
                        m_PreviewObject.transform.position = hit.collider.gameObject.transform.position;     // + new Vector3(0, 0.1f, 0)
                        if (m_PreviewObject.name.Contains("Wall") && m_PreviewObject.tag.Contains("Tower"))
                        {
                            m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, -90, 0));
                        }
                        if (m_PreviewObject.tag.Equals("Wall") && !m_PreviewObject.name.Equals("WallTower(Clone)"))     //m_PreviewObject.name.Contains("Wall") &&
                        {
                            if (m_PreviewObject.transform.position.z < m_oldPos.z)
                            {
                                m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, -90, 0));
                                Side = WallSide.Bot;
                            }
                            if (m_PreviewObject.transform.position.z > m_oldPos.z)
                            {
                                m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, 90, 0));
                                Side = WallSide.Top;
                            }
                            if (m_PreviewObject.transform.position.x > m_oldPos.x)
                            {
                                m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, 180, 0));
                                Side = WallSide.Right;
                            }
                            if (m_PreviewObject.transform.position.x < m_oldPos.x)
                            {
                                m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, 0, 0));
                                Side = WallSide.Left;
                            }
                        }
                        else if (m_PreviewObject.name.Equals("WallTower(Clone)"))
                        {
                            m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, 0, 0));
                        }
                        else
                        {
                            m_PreviewObject.transform.rotation = hit.collider.gameObject.transform.rotation;
                        }
                    }
                }
            }
            else
            {
                if (m_PreviewObject != null)
                {
                    Destroy(m_PreviewObject);
                    m_PreviewObject = null;
                }
            }


            d_Timer += Time.deltaTime;
            if (Input.GetMouseButtonUp(0) && d_Timer > 0.1)
            {
                if (Physics.Raycast(ray, out hit))
                {
                    // Check if ray is hiting a grid or the preview itself
                    if ((hit.collider.gameObject.name == "Grid(Clone)" || hit.collider.gameObject.name.Contains("Wall")) || hit.collider.gameObject.Equals(m_PreviewObject))
                    {
                        // Check if the location is valid
                        Vector2 checkPos  = theGridBehaviour.GetWithinGridPos(hit.collider.gameObject.transform.position);
                        string  checkName = "";
                        for (int i = 0; i < PersistentData.m_Instance.BuildingGridPos.Count; ++i)
                        {
                            if (PersistentData.m_Instance.BuildingGridPos[i].Equals(new SerializableVector2(checkPos)))
                            {
                                checkName = PersistentData.m_Instance.BuildingName[i];
                                break;
                            }
                        }

                        if (!PersistentData.m_Instance.BuildingGridPos.Contains(new SerializableVector2(checkPos)) ||
                            PersistentData.m_Instance.BuildingGridPos.Contains(new SerializableVector2(checkPos)) && checkName.Contains("Wall") && !(checkName.Contains("Standard") || checkName.Contains("Sniper") || checkName.Contains("Heavy")) && m_ObjectToConstruct.tag.Contains("Tower"))
                        {
                            // Check if the player has enough resources
                            if (EnoughResource)
                            {
                                ConstructionStage = CONSTRUCTION_STAGE.CONSTRUCTION;
                                m_SpawnLocation   = hit.collider.gameObject.transform.position;

                                if (m_ObjectToConstruct.name.Contains("Wall") && m_ObjectToConstruct.tag.Equals("Tower"))
                                {
                                    m_SpawnRotation = hit.collider.gameObject.transform.rotation * Quaternion.Euler(new Vector3(0, -90, 0));
                                }
                                else
                                {
                                    m_SpawnRotation = hit.collider.gameObject.transform.rotation;
                                }
                            }
                        }
                    }
                    else
                    {
                        ConstructionStage   = CONSTRUCTION_STAGE.SELECTION_BUILDING;
                        m_ObjectToConstruct = null;
                    }
                }
                else
                {
                    ConstructionStage   = CONSTRUCTION_STAGE.SELECTION_BUILDING;
                    m_ObjectToConstruct = null;
                }
            }
            break;

        case CONSTRUCTION_STAGE.CONSTRUCTION:
            // Destroy the preview
            if (m_PreviewObject != null)
            {
                Destroy(m_PreviewObject);
                m_PreviewObject = null;
            }
            GameObject go;
            // Spawn the building
            //Adjust height for walls,
            if (m_ObjectToConstruct.name.Contains("Wall") && !m_ObjectToConstruct.name.Contains("WallTower"))
            {
                go = Instantiate(m_ObjectToConstruct, m_SpawnLocation + new Vector3(0, 0.05f, -0.025f), m_SpawnRotation /*m_ObjectToConstruct.transform.rotation*/) as GameObject;
            }
            //Wall Towers,
            else if (m_ObjectToConstruct.name.Contains("WallTower"))
            {
                go = Instantiate(m_ObjectToConstruct, m_SpawnLocation + new Vector3(0, 0.15f, -0.025f), m_SpawnRotation /*m_ObjectToConstruct.transform.rotation*/) as GameObject;
            }
            //And normal buildings
            else
            {
                go = Instantiate(m_ObjectToConstruct, m_SpawnLocation + new Vector3(0, 0.1f, -0.025f), m_SpawnRotation /*m_ObjectToConstruct.transform.rotation*/) as GameObject;
            }

            // Assign GridPos and Deduct cost
            if (!m_ObjectToConstruct.tag.Equals("Tower"))
            {
                go.GetComponent <BuildingAbstractBase>().GridPos   = theGridBehaviour.GetWithinGridPos(m_SpawnLocation);
                go.GetComponent <BuildingAbstractBase>().IsPreview = false;

                if (m_ObjectToConstruct.tag.Contains("Wall"))
                {
                    Vector2 TopCheck   = theGridBehaviour.GetGridPos(go.transform.position) + new Vector2(0, 1);
                    Vector2 BotCheck   = theGridBehaviour.GetGridPos(go.transform.position) + new Vector2(0, -1);
                    Vector2 LeftCheck  = theGridBehaviour.GetGridPos(go.transform.position) + new Vector2(-1, 0);
                    Vector2 RightCheck = theGridBehaviour.GetGridPos(go.transform.position) + new Vector2(1, 0);
                    for (int idx = 0; idx < PersistentData.m_Instance.BuildingGridPos.Count; ++idx)
                    {
                        if (TopCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            top = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (BotCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            bottom = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (LeftCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            left = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (RightCheck.Equals(PersistentData.m_Instance.BuildingGridPos[idx].GetVec2()))
                        {
                            right = PersistentData.m_Instance.BuildingName[idx];
                        }
                        if (top.Contains("Wall") && !top.Contains("Tower"))
                        {
                            go.transform.Rotate(0, 0, 0);
                        }
                        if (bottom.Contains("Wall") && !top.Contains("Tower"))
                        {
                            go.transform.Rotate(0, 90, 0);
                        }
                    }
                }

                if (m_ObjectToConstruct.name == ("Generator"))
                {
                    GeneratorBuilt = true;
                }
                if (m_ObjectToConstruct.name == ("Farm"))
                {
                    FarmBuilt = true;
                }
                if (m_ObjectToConstruct.name == ("Housing"))
                {
                    HouseBuilt = true;
                }
                if (m_ObjectToConstruct.name == ("DataGenerator"))
                {
                    DGeneratorBuilt = true;
                }
                if (m_ObjectToConstruct.name == ("CreditsGenerator"))
                {
                    EGeneratorBuilt = true;
                }
                if (DGeneratorBuilt && EGeneratorBuilt)
                {
                    DEGeneratorsBuilt = true;
                }

                PersistentData.m_Instance.CreditsAmount -= go.GetComponent <BuildingAbstractBase>().ECost;
                PersistentData.m_Instance.DataAmount    -= go.GetComponent <BuildingAbstractBase>().DCost;

                go.GetComponent <BoxCollider>().enabled = true;
            }
            else
            {
                go.GetComponent <BaseTurret>().GridPos   = theGridBehaviour.GetWithinGridPos(m_SpawnLocation);
                go.GetComponent <BaseTurret>().IsPreview = false;
                PersistentData.m_Instance.CreditsAmount -= m_ObjectToConstruct.GetComponent <BaseTurret>().ECost;
                PersistentData.m_Instance.DataAmount    -= m_ObjectToConstruct.GetComponent <BaseTurret>().DCost;

                if (m_ObjectToConstruct.name.Contains("Standard"))
                {
                    TurretBuilt = true;
                }

                go.GetComponent <BaseTurret>().TurretActive = true;
                go.GetComponent <BoxCollider>().enabled     = true;
            }

            // Set the grid behaviour to be the parent
            go.transform.parent = theGridBehaviour.transform;

            // Cause the building to switch from the preview material to its final one
            MaterialSwitch[] ComponentList = go.GetComponentsInChildren <MaterialSwitch>();
            foreach (MaterialSwitch ms in ComponentList)
            {
                ms.SwitchToSecondMaterial();
            }

            // Special case for Housing
            if (go.name.Contains("Housing"))
            {
                go.GetComponent <AddOnConstruction>().theConstructionManager = this;
                go.GetComponent <AddOnConstruction>().theHoverScript         = theAddOnPanel.GetComponent <UIHoverOver>();
            }

            // Send to RandomEventManager
            EventBase.TRIGGER_TYPE aTrigger = EventBase.TRIGGER_TYPE.BUILD_CREDIT;

            switch (m_ObjectToConstruct.name)
            {
            case "Generator": aTrigger = EventBase.TRIGGER_TYPE.BUILD_GENERATOR; break;

            case "DataGenerator": aTrigger = EventBase.TRIGGER_TYPE.BUILD_DATA; break;

            case "CreditsGenerator": aTrigger = EventBase.TRIGGER_TYPE.BUILD_CREDIT; break;

            case "Farm": aTrigger = EventBase.TRIGGER_TYPE.BUILD_FARM; break;

            case "Housing": aTrigger = EventBase.TRIGGER_TYPE.BUILD_HOUSING; break;

            case "Storage": aTrigger = EventBase.TRIGGER_TYPE.BUILD_STORAGE; break;
            }

            if (m_ObjectToConstruct.tag.Equals("Tower"))
            {
                aTrigger = EventBase.TRIGGER_TYPE.BUILD_TURRET;
            }

            GameObject.Find("RandomEventSystem").GetComponent <RandomEventManager>().RunRandomCheck(aTrigger);


            // Assign attached wall object
            if (m_ObjectToConstruct.name.Contains("Wall") && (m_ObjectToConstruct.name.Contains("Standard") || m_ObjectToConstruct.name.Contains("Sniper") || m_ObjectToConstruct.name.Contains("Heavy")))
            {
                go.GetComponent <BaseTurret>().AttachedWall = m_WallObject.GetComponent <BuildingAbstractBase>();
            }

            ConstructionStage   = CONSTRUCTION_STAGE.NOT_CONSTRUCTING;
            m_ObjectToConstruct = null;

            break;

        case CONSTRUCTION_STAGE.SELECTION_ADDON:
            if (m_AddOnToConstruct != ADD_ON_TYPE.NONE)
            {
                switch (m_AddOnToConstruct)
                {
                case ADD_ON_TYPE.POWER:
                    theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.transform.GetChild(1).gameObject.SetActive(true);
                    theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.GetComponent <Residential>().theAddOn = theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.transform.GetChild(1).gameObject.GetComponent <BuildingAddOn>();
                    break;

                case ADD_ON_TYPE.FOOD:
                    theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.transform.GetChild(2).gameObject.SetActive(true);
                    theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.GetComponent <Residential>().theAddOn = theAddOnPanel.GetComponent <UIHoverOver>().ObjectToHoverOver.transform.GetChild(2).gameObject.GetComponent <BuildingAddOn>();
                    break;
                }

                ConstructionStage  = CONSTRUCTION_STAGE.NOT_CONSTRUCTING;
                m_AddOnToConstruct = ADD_ON_TYPE.NONE;
                theAddOnPanel.SetActive(false);
            }
            else
            {
                if (Input.GetMouseButtonUp(0))
                {
                    ConstructionStage  = CONSTRUCTION_STAGE.NOT_CONSTRUCTING;
                    m_AddOnToConstruct = ADD_ON_TYPE.NONE;
                    theAddOnPanel.SetActive(false);
                }
            }
            break;
        }
    }
Exemple #22
0
 public Wall(GameManager gameManager, WallSide wallSide, Rect bounds)
     : base(gameManager, bounds, CollisionLayer.Wall)
 {
     this.wallSide = wallSide;
     SetSpriteSource();
 }
Exemple #23
0
    private void PlaceWall(GameObject target, WallSide wallSide)
    {
        DngnRoomInfo RoomInfo = target.GetComponent <DngnRoomInfo>();

        //Dont bother placing walls around empty rooms
        if (RoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            return;
        }
        Vector3    WallPos      = target.transform.position;
        GameObject AdjacentRoom = null;

        switch (wallSide)
        {
        case (WallSide.North):
            AdjacentRoom = GetNorth(target);
            WallPos     += Vector3.forward * (m_floorSize * 0.5f);
            break;

        case (WallSide.East):
            AdjacentRoom = GetEast(target);
            WallPos     += Vector3.right * (m_floorSize * 0.5f);
            break;

        case (WallSide.South):
            AdjacentRoom = GetSouth(target);
            WallPos     += (-Vector3.forward) * (m_floorSize * 0.5f);
            break;

        case (WallSide.West):
            AdjacentRoom = GetWest(target);
            WallPos     += (-Vector3.right) * (m_floorSize * 0.5f);
            break;
        }
        //If there is void to the north, place a wall there
        if (AdjacentRoom == null)
        {
            //Spawn a wall
            GameObject Wall = GameObject.Instantiate(m_wallPrefab, WallPos, Quaternion.identity) as GameObject;
            //Parent it
            Wall.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Wall.transform.LookAt(target.transform.position);
            //Mark there is now a wall here
            switch (wallSide)
            {
            case (WallSide.North):
                RoomInfo.m_hasNorthWall = true;
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                break;
            }
            return;
        }
        //If there is a room to the north, only place a wall if its empty
        DngnRoomInfo AdjacentRoomInfo = AdjacentRoom.GetComponent <DngnRoomInfo>();

        if (AdjacentRoomInfo.m_roomType == DngnRoomInfo.RoomType.Void)
        {
            //Spawn a wall
            GameObject Wall = GameObject.Instantiate(m_wallPrefab, WallPos, Quaternion.identity) as GameObject;
            //Parent it
            Wall.transform.parent = m_dungeonRoot.transform;
            //Rotate it
            Wall.transform.LookAt(target.transform.position);
            //Mark there is now a wall here
            switch (wallSide)
            {
            case (WallSide.North):
                RoomInfo.m_hasNorthWall = true;
                break;

            case (WallSide.East):
                RoomInfo.m_hasEastWall = true;
                break;

            case (WallSide.South):
                RoomInfo.m_hasSouthWall = true;
                break;

            case (WallSide.West):
                RoomInfo.m_hasWestWall = true;
                break;
            }
            return;
        }
    }
    void Update()
    {
        // Abort if no control object is found
        if (control == null)
        {
            return;
        }

        // Disable Wall Jump
        canWallJump = false;
        // Check if able to wall jump
        canWallJump = (attachedToWall == WallSide.LEFT) || (attachedToWall == WallSide.RIGHT);

        // Check if moving down
        if (rb.velocity.y < 0)
        {
            // Increase falling speed by multiplier of gravity
            rb.velocity += Vector2.up * Physics2D.gravity.y * (fallModifier - 1) * Time.deltaTime;
        }

        // If moving in the X
        if (Mathf.Abs(rb.velocity.x) > 0)
        {
            // Decrease velocity by 30%
            rb.velocity = new Vector2(rb.velocity.x * 0.7f, rb.velocity.y);
        }

        // Check if not stunned
        if (stunTime <= 0f)
        {
            // Update based on control object
            GetControlInput();
        }
        else
        {
            // Decrease stun time
            stunTime -= Time.deltaTime;
            // Reset dash cooldown
            dashTimer = 0;
        }

        // Reset wall detection
        attachedToWall = WallSide.NONE;
        // Update sprite display
        UpdateDisplay();

        // If too low, die
        if (transform.position.y < deathYLevel)
        {
            Kill();
        }


        // CHEATS
        if (Input.GetKeyDown($"{controllerNum}"))
        {
            if (IsAlive())
            {
                Kill();
            }
            else
            {
                alive = true;
                gameObject.SetActive(true);
            }
        }
        // END CHEATS
    }
 private void HandleInput()
 {
     if (myMovementState == MovementState.WallRun || myMovementState == MovementState.WallClimb)
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
             if (myWallSide == WallSide.Right)
             {
                 //rb.AddForce(new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z) * JumpFromWallStrength * Time.fixedDeltaTime);
                 if (Input.GetKey(KeyCode.A))
                 {
                     rb.AddForce(-transform.right * JumpFromWallStrength * Time.fixedDeltaTime);
                 }
                 rb.AddForce(transform.up * JumpFromWallStrength * Time.fixedDeltaTime);
                 camManager.ResetRotation(rb);
             }
             else if (myWallSide == WallSide.Left)
             {
                 //rb.AddForce(new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z) * JumpFromWallStrength * Time.fixedDeltaTime);
                 if (Input.GetKey(KeyCode.D))
                 {
                     rb.AddForce(transform.right * JumpFromWallStrength * Time.fixedDeltaTime);
                 }
                 rb.AddForce(transform.up * JumpFromWallStrength * Time.fixedDeltaTime);
                 camManager.ResetRotation(rb);
             }
             else if (myWallSide == WallSide.Front)
             {
                 RaycastHit hit;
                 Debug.DrawRay(new Vector3(transform.position.x, currentWall.transform.position.y, transform.position.z), new Vector3(currentWall.transform.position.x, transform.position.y, currentWall.transform.position.z) - transform.position, Color.green, 15);
                 if (Physics.Raycast(new Vector3(transform.position.x, currentWall.transform.position.y, transform.position.z), new Vector3(currentWall.transform.position.x, transform.position.y, currentWall.transform.position.z) - transform.position, out hit, 4))
                 {
                     if (hit.transform.gameObject == currentWall)
                     {
                         rb.AddForce(hit.normal * JumpFromWallStrength * Time.fixedDeltaTime);
                     }
                     else
                     {
                         rb.AddForce(-transform.forward * JumpFromWallStrength * Time.fixedDeltaTime);
                     }
                 }
                 else
                 {
                     rb.AddForce(-transform.forward * JumpFromWallStrength * Time.fixedDeltaTime);
                 }
                 // rb.AddForce(transform.right * JumpFromWallStrength / 2);
                 rb.AddForce(transform.up * JumpFromWallStrength * 1.5f * Time.fixedDeltaTime);
                 camManager.ResetRotation(rb);
                 //SWITCH: Turn camera around on wall jump
                 //camManager.TurnAround();
             }
             prevWall    = currentWall;
             currentWall = null;
             isOnWall    = false;
             SwitchState(MovementState.WallJump);
             myWallSide = WallSide.None;
         }
     }
     else if (isGrounded)
     {
         if (myMovementState != MovementState.Vault && myMovementState != MovementState.Slide)
         {
             rb.drag = groundDrag;
             if (Input.GetKey(KeyCode.W))
             {
                 //rb.velocity += transform.forward * MovementSpeed * Time.deltaTime;
                 rb.AddForce(transform.forward * MovementSpeed * Time.fixedDeltaTime);
             }
             if (Input.GetKey(KeyCode.A))
             {
                 rb.AddForce(-transform.right * MovementSpeed * Time.fixedDeltaTime);
                 //rb.velocity += -transform.right * MovementSpeed * Time.deltaTime;
             }
             if (Input.GetKey(KeyCode.S))
             {
                 rb.AddForce(-transform.forward * MovementSpeed * Time.fixedDeltaTime);
                 //rb.velocity += -transform.forward * MovementSpeed * Time.deltaTime;
             }
             if (Input.GetKey(KeyCode.D))
             {
                 rb.AddForce(transform.right * MovementSpeed * Time.fixedDeltaTime);
                 //rb.velocity += transform.right * MovementSpeed * Time.deltaTime;
             }
             if (new Vector3(rb.velocity.x, 0, rb.velocity.z).magnitude >= MaxSpeed)
             {
                 rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z).normalized *MaxSpeed + new Vector3(0, rb.velocity.y, 0);
             }
             if (Input.GetKeyDown(KeyCode.Space))
             {
                 activateInteractable(KeyCode.Space);
                 if ((myMovementState == MovementState.Idle || myMovementState == MovementState.Run) && isGrounded)
                 {
                     Jump();
                 }
             }
             if (Input.GetKeyDown(KeyCode.LeftShift))
             {
                 activateInteractable(KeyCode.LeftShift);
             }
             if (Input.GetKeyDown(KeyCode.E))
             {
                 activateInteractable(KeyCode.E);
             }
         }
     }
     else
     {
         rb.drag = airDrag;
         if (Input.GetKey(KeyCode.W))
         {
             //rb.velocity += transform.forward * MovementSpeed * Time.deltaTime * 0.003f;
             rb.AddForce(transform.forward * MovementSpeedInAir * Time.fixedDeltaTime);
         }
         if (Input.GetKey(KeyCode.A))
         {
             rb.AddForce(-transform.right * MovementSpeedInAir * Time.fixedDeltaTime);
             //rb.velocity += -transform.right * MovementSpeed * Time.deltaTime * 0.003f;
         }
         if (Input.GetKey(KeyCode.S))
         {
             rb.AddForce(-transform.forward * MovementSpeedInAir * Time.fixedDeltaTime);
             //rb.velocity += -transform.forward * MovementSpeed * Time.deltaTime * 0.003f;
         }
         if (Input.GetKey(KeyCode.D))
         {
             rb.AddForce(transform.right * MovementSpeedInAir * Time.fixedDeltaTime);
             //rb.velocity += transform.right * MovementSpeed * Time.deltaTime * 0.003f;
         }
         if (new Vector3(rb.velocity.x, 0, rb.velocity.z).magnitude >= MaxSpeed)
         {
             rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z).normalized *MaxSpeed + new Vector3(0, rb.velocity.y, 0);
         }
     }
 }