void OnUpdate(SceneView sceneView)
    {
        Vector2 screenpos = Event.current.mousePosition;
        screenpos.y = sceneView.camera.pixelHeight - screenpos.y;
        MousePos = sceneView.camera.ScreenPointToRay(screenpos).origin;
        bool withinGrid = MousePos.isWithinGrid();
        if (withinGrid)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.button == 2)
            {
                Active = !Active;
                Event.current.Use(); //keeping this line causes one bug, removing it causes another.
            }
        }
        if (Active)
        {
            UpdateIndicator(withinGrid);
        }
        if(Active && withinGrid)
        {
            if (Event.current.type == EventType.layout)
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
            Selection.activeObject = null;
            RightClick = isRightPressed(RightClick);
            LeftClick = isLeftPressed(LeftClick);
            Vector2 ScrollVect = getScroll();

            int scroll = Math.Sign(ScrollVect.y);
            if (scroll != 0)
            {
                int nextPiece = (int)selectedIndex + scroll;
                if (nextPiece >= 0 && nextPiece < PieceTypeList.Count)
                {
                    selectedIndex = nextPiece;
                    SetIndicator();
                }
            }
            if (selectedPiece == typeof(Wall))
            {
                Side side;
                Orientation or;
                Vector2 target = Utils.WorldToWallPos(MousePos, out side, out or);
                if (Indicator)
                {
                    Indicator.transform.position = target;
                    Wall wall = Indicator.GetComponent<Wall>();
                    wall.orientation = or;
                }
                if (LeftDown())
                {
                    SpawnWall(target, or, side);

                    sceneView.Update();
                    sceneView.Repaint();
                }
                else if (RightDown())
                {
                    RoomManager.roomManager.RemoveWall(MousePos);
                    sceneView.Update();
                    sceneView.Repaint();
                }

            }
            else if (selectedPiece == typeof(Player))
            {
                Cell target = Cell.GetFromWorldPos(MousePos);
                if (target != null)
                {
                    Indicator.transform.position = target.WorldPos();
                    if (LeftDown())
                    {
                        //SpawnPiece(selectedPiece, target);
                        SpawnPlayer(target);
                        sceneView.Update();
                        sceneView.Repaint();
                    }
                    else if (RightDown())
                    {
                        RoomManager.roomManager.RemoveTopPiece(target);
                        sceneView.Update();
                        sceneView.Repaint();
                    }
                }
            }
            else if (selectedIndex != 0)//spawn any other piece (other than wall)
            {
                Cell target = Cell.GetFromWorldPos(MousePos);
                if (target!=null) {
                    if (Indicator != null) Indicator.transform.position = target.WorldPos();
                    if (LeftDown())
                    {
                        SpawnPiece(selectedPiece, target);
                        sceneView.Update();
                        sceneView.Repaint();
                    }
                    else if (RightDown())
                    {
                        RoomManager.roomManager.RemoveTopPiece(target);
                        sceneView.Update();
                        sceneView.Repaint();
                    }
                }
            }
            Event.current.Use();
        }
    }