Example #1
0
    private void UpdateDragging(Vector3 currFramePosition)
    {
        // if we are over a ui element bail out
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        CleanupDragPreview();

        if (currentMode != MouseMode.BUILD)
        {
            return;
        }

        //Start Drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currFramePosition;
            isDragging        = true;
        }
        else if (isDragging == false)
        {
            dragStartPosition = currFramePosition;
        }

        if (Input.GetMouseButtonUp(1) || Input.GetKeyUp(KeyCode.Escape))
        {
            //The right mouse button was released so we cancel the dragging
            isDragging = false;
        }

        if (buildModeController.IsObjectDraggable() == false)
        {
            dragStartPosition = currFramePosition;
        }

        //Setup Y
        int startY = Mathf.FloorToInt(dragStartPosition.y + .5f);
        int endY   = Mathf.FloorToInt(currFramePosition.y + .5f);
        //Setup X
        int startX = Mathf.FloorToInt(dragStartPosition.x + .5f);
        int endX   = Mathf.FloorToInt(currFramePosition.x + .5f);

        //Check Drag Direction
        CheckDragDirection(ref startX, ref endX);
        CheckDragDirection(ref startY, ref endY);



        //Display Drag Area
        DisplayDragArea(startY, endY, startX, endX);

        //End Drag and Create The Floor
        EndDragAndCreateFloor(startY, endY, startX, endX);
    }
Example #2
0
    void UpdateDragging()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        //Clean old drag previews
        for (int i = 0; i < _dragPreviewGameObjects.Count; i++)
        {
            SimplePool.Despawn(_dragPreviewGameObjects[i]);
        }
        _dragPreviewGameObjects.Clear();

        if (_currentMode != MouseMode.BUILD)
        {
            return;
        }

        //Start mouse drag
        if (Input.GetMouseButtonDown(0))
        {
            _dragStartPosition = _currFramePosition;
            _isDragging        = true;
        }
        else if (!_isDragging)
        {
            _dragStartPosition = _currFramePosition;
        }

        if (Input.GetMouseButtonUp(1) || Input.GetKeyUp(KeyCode.Escape))
        {
            _isDragging = false;
        }

        if (!_buildModeController.IsObjectDraggable())
        {
            _dragStartPosition = _currFramePosition;
        }

        int start_x = Mathf.RoundToInt(_dragStartPosition.x);
        int end_x   = Mathf.RoundToInt(_currFramePosition.x);

        if (end_x < start_x)
        {
            int tmp = end_x;
            end_x   = start_x;
            start_x = tmp;
        }

        int start_y = Mathf.RoundToInt(_dragStartPosition.y);
        int end_y   = Mathf.RoundToInt(_currFramePosition.y);

        if (end_y < start_y)
        {
            int tmp = end_y;
            end_y   = start_y;
            start_y = tmp;
        }

        /*while (_dragPreviewGameObjects.Count > 0)
         * {
         *  GameObject go = _dragPreviewGameObjects[0];
         *  _dragPreviewGameObjects.RemoveAt(0);
         *  SimplePool.Despawn(go);
         * }*/

        /*if (_isDragging)
         * {*/
        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                Tile t = WorldController.Instance.World.GetTileAt(x, y);
                if (t != null)
                {
                    if (_buildModeController.BuildModeIsObject)
                    {
                        ShowInstalledObjectSpriteAtTile(_buildModeController.BuildModeObjectType, t);
                    }
                    else
                    {
                        GameObject go = SimplePool.Spawn(_circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(_cursorGameObjectsContainer, true);
                        _dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }
        /*}*/

        //End mouse drag
        if (_isDragging && Input.GetMouseButtonUp(0))
        {
            _isDragging = false;
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile tile = WorldController.Instance.World.GetTileAt(x, y);

                    if (tile != null)
                    {
                        _buildModeController.Build(tile);
                    }
                }
            }
        }
    }
Example #3
0
    void UpdateDragging()
    {
        // If we're over a UI element, then bail out from this.
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Clean up old drag previews
        while (dragPreviewGameObjects.Count > 0)
        {
            GameObject go = dragPreviewGameObjects[0];
            dragPreviewGameObjects.RemoveAt(0);
            SimplePool.Despawn(go);
        }

        if (currentMode != MouseMode.BUILD)
        {
            return;
        }

        // Start Drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currFramePosition;
            isDragging        = true;
        }
        else if (isDragging == false)
        {
            dragStartPosition = currFramePosition;
        }

        if (Input.GetMouseButtonUp(1) || Input.GetKeyUp(KeyCode.Escape))
        {
            // The RIGHT mouse button was released, so we
            // are cancelling any dragging/build mode.
            isDragging = false;
        }

        if (bmc.IsObjectDraggable() == false)
        {
            dragStartPosition = currFramePosition;
        }

        int start_x = Mathf.FloorToInt(dragStartPosition.x + 0.5f);
        int end_x   = Mathf.FloorToInt(currFramePosition.x + 0.5f);
        int start_y = Mathf.FloorToInt(dragStartPosition.y + 0.5f);
        int end_y   = Mathf.FloorToInt(currFramePosition.y + 0.5f);

        // We may be dragging in the "wrong" direction, so flip things if needed.
        if (end_x < start_x)
        {
            int tmp = end_x;
            end_x   = start_x;
            start_x = tmp;
        }
        if (end_y < start_y)
        {
            int tmp = end_y;
            end_y   = start_y;
            start_y = tmp;
        }

        //if( isDragging ) {
        // Display a preview of the drag area
        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                Tile t = WorldController.Instance.world.GetTileAt(x, y);
                if (t != null)
                {
                    // Display the building hint on top of this tile position

                    if (bmc.buildMode == BuildMode.FURNITURE)
                    {
                        ShowFurnitureSpriteAtTile(bmc.buildModeObjectType, t);
                    }
                    else
                    {
                        // show the generic dragging visuals
                        GameObject go = SimplePool.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        go.GetComponent <SpriteRenderer>().sprite = SpriteManager.current.GetSprite("UI", "CursorCircle");
                        dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }
        //}

        // End Drag
        if (isDragging && Input.GetMouseButtonUp(0))
        {
            isDragging = false;

            // Loop through all the tiles
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile t = WorldController.Instance.world.GetTileAt(x, y);

                    if (t != null)
                    {
                        // Call BuildModeController::DoBuild()
                        bmc.DoBuild(t);
                    }
                }
            }
        }
    }
Example #4
0
    /*
     * void updateCursor ()
     * {
     *      tileUnderMouse = WorldController.Instance.getTileAtWorldCoord (currFramePosition);
     *      if (tileUnderMouse != null) {
     *              cursor.SetActive (true);
     *              cursorPosition = new Vector3 (tileUnderMouse.X, tileUnderMouse.Y, 0);
     *              cursor.transform.position = cursorPosition;
     *      } else {
     *              cursor.SetActive (false);
     *      }
     * }
     */

    void updateDrag()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        while (dragCursors.Count > 0)
        {
            go = dragCursors [0];
            dragCursors.RemoveAt(0);
            SimplePool.despawn(go);
        }

        if (currentMode != MouseMode.BUILD)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currFramePosition;
            isDragging        = true;
        }
        else if (!isDragging)
        {
            dragStartPosition = currFramePosition;
        }

        if (Input.GetMouseButtonUp(1) || Input.GetKeyUp(KeyCode.Escape))
        {
            isDragging = false;
        }

        if (!buildModeController.IsObjectDraggable())
        {
            dragStartPosition = currFramePosition;
        }

        calculateAreaDrag();

        for (int x = start_x; x <= end_x; x++)
        {
            for (int y = start_y; y <= end_y; y++)
            {
                tile = WorldController.Instance.world.getTileAt(x, y);

                if (tile != null)
                {
                    if (buildModeController.buildMode == BuildMode.FURNITURE)
                    {
                        ShowFurnitureSpriteAtTile(buildModeController.objectType, tile);
                    }
                    else
                    {
                        go = SimplePool.spawn(cursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        dragCursors.Add(go);
                    }
                }
            }
        }

        if (isDragging && Input.GetMouseButtonUp(0))
        {
            calculateAreaDrag();
            isDragging = false;

            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    tile = WorldController.Instance.world.getTileAt(x, y);
                    if (tile != null)
                    {
                        buildModeController.doBuild(tile);
                    }
                }
            }
        }
    }
    void UpdateDragging()
    {
        // ---- Start Drag
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            isDragging        = true;
            dragStartPosition = currFramePosition;
        }

        if (Input.GetMouseButtonUp(1))
        {
            // If RIGHT mouse buttom is released we are
            // cancelling current action
            isDragging = false;
        }

        if (bmc.IsObjectDraggable() == false)
        {
            dragStartPosition = currFramePosition;
        }

        int start_x = Mathf.FloorToInt(dragStartPosition.x + 0.5f);
        int end_x   = Mathf.FloorToInt(currFramePosition.x + 0.5f);
        int start_y = Mathf.FloorToInt(dragStartPosition.y + 0.5f);
        int end_y   = Mathf.FloorToInt(currFramePosition.y + 0.5f);

        if (isDragging)
        {
            // Flip if draggin in the "wrong" direction
            if (end_x < start_x)
            {
                int tmp = end_x;
                end_x   = start_x;
                start_x = tmp;
            }
            if (end_y < start_y)
            {
                int tmp = end_y;
                end_y   = start_y;
                start_y = tmp;
            }
        }

        // Clean up old drag previews
        while (dragPreviewGameObjects.Count > 0)
        {
            GameObject go = dragPreviewGameObjects[0];
            dragPreviewGameObjects.RemoveAt(0);
            SimplePool.Despawn(go);
        }

        if (isDragging)
        {
            // ---- Keep Drag
            // Loop through all the selected tiles
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile t = WorldController.Instance.world.GetTileAt(x, y);
                    if (t != null)
                    {
                        // Display building semi transparent object
                        GameObject go = SimplePool.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        //go.GetComponent<SpriteRenderer>().sprite =
                        //   GameObject.FindObjectOfType<FurnitureSpriteController>().GetSpriteForFurniture(GameObject.FindObjectOfType<BuildModeController>().buildModeObjectType);
                        go.transform.SetParent(this.transform, true);
                        dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }

        // ---- End Drag
        if (Input.GetMouseButtonUp(0) && isDragging)
        {
            isDragging = false;
            // Loop through all the selected tiles
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile t = WorldController.Instance.world.GetTileAt(x, y);

                    if (t != null)
                    {
                        // Call BuildModeController::DoBuild()
                        bmc.DoBuild(t);
                    }
                }
            }
        }
    }