void ClickedOnTile(Tile t)
 {
     if (t != null)
     {
         bmc.DoBuild(t);
     }
 }
Ejemplo n.º 2
0
    private void EndDragAndCreateFloor(int startY, int endY, int startX, int endX)
    {
        if (Input.GetMouseButtonUp(0) && isDragging)
        {
            isDragging = false;
            //Loop through the tiles
            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    Tile tile = WorldController.Instance.World.GetTileAt(x, y);

                    if (tile != null)
                    {
                        //CallBuildModeController DoBuild
                        buildModeController.DoBuild(tile);
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
    void UpdateDragging()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        //handle left mouse
        //start drag
        //for mobile have sense tapping, tap start tap end
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPos = currentFramePos;
        }

        int start_x = Mathf.FloorToInt(dragStartPos.x + 0.5f);
        int end_x   = Mathf.FloorToInt(currentFramePos.x + 0.5f);

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

        int start_y = Mathf.FloorToInt(dragStartPos.y + 0.5f);
        int end_y   = Mathf.FloorToInt(currentFramePos.y + 0.5f);

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

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

        if (Input.GetMouseButton(0))
        {
            //Display drag area preview
            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 hint at this position
                        GameObject go = SimplePool.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(transform, true);
                        dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }


        //end drag
        if (Input.GetMouseButtonUp(0))
        {
            //loop through 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
                        buildModeController.DoBuild(t);
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
    void updateDrag()
    {
        // If we're over a UI element, then bail out from this.
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Clear old selection
        foreach (GameObject cc in dragCircleCursorList)
        {
            ObjectPooler.Despawn(cc);
        }
        ;
        dragCircleCursorList.Clear();

        // Start drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currFramePostion;
        }

        // Set start and end points for x and y. Used during and at end of drag.
        int start_x = Mathf.FloorToInt(dragStartPosition.x);
        int end_x   = Mathf.FloorToInt(currFramePostion.x);
        int start_y = Mathf.FloorToInt(dragStartPosition.y);
        int end_y   = Mathf.FloorToInt(currFramePostion.y);

        // If we are dragging in the "wrong" direction, invert the start and end points.
        if (end_x < start_x)
        {
            int temp_x = end_x;
            end_x   = start_x;
            start_x = temp_x;
        }
        if (end_y < start_y)
        {
            int temp_y = end_y;
            end_y   = start_y;
            start_y = temp_y;
        }
        // While dragging
        if (Input.GetMouseButton(0))
        {
            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)
                    {
                        GameObject go = ObjectPooler.Spawn(circleCursor, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        dragCircleCursorList.Add(go);
                    }
                }
            }
        }

        // End drag
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController> ();

            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);
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
    void UpdateDragging()
    {
        // If we're over a UI element, then bail out from this.
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // Start Drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = CurrFramePosition;
        }

        int StartX = Mathf.FloorToInt(dragStartPosition.x);
        int EndX   = Mathf.FloorToInt(CurrFramePosition.x);
        int StartY = Mathf.FloorToInt(dragStartPosition.y);
        int EndY   = Mathf.FloorToInt(CurrFramePosition.y);

        // We may be dragging in the "wrong" direction, so flip things if needed.
        if (EndX < StartX)
        {
            int tmp = EndX;
            EndX   = StartX;
            StartX = tmp;
        }
        if (EndY < StartY)
        {
            int tmp = EndY;
            EndY   = StartY;
            StartY = tmp;
        }

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

        if (Input.GetMouseButton(0))
        {
            // Display a preview of the drag area
            for (int x = StartX; x <= EndX; x++)
            {
                for (int y = StartY; y <= EndY; y++)
                {
                    Tile t = WorldController.Instance.World.GetTileAt(x, y);
                    if (t != null)
                    {
                        // Display the building hint on top of this tile position
                        GameObject GO = SimplePool.Spawn(CircleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        GO.transform.SetParent(this.transform, true);
                        dragPreviewGameObjects.Add(GO);
                    }
                }
            }
        }

        // End Drag
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController BMC = GameObject.FindObjectOfType <BuildModeController>();

            // Loop through all the tiles
            for (int x = StartX; x <= EndX; x++)
            {
                for (int y = StartY; y <= EndY; y++)
                {
                    Tile t = WorldController.Instance.World.GetTileAt(x, y);

                    if (t != null)
                    {
                        // Call BuildModeController::DoBuild()
                        BMC.DoBuild(t);
                    }
                }
            }
        }
    }
Ejemplo n.º 6
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);
                    }
                }
            }
        }
    }
Ejemplo n.º 7
0
    void DraggingFunction()
    {
        if (Input.GetMouseButtonDown(1))
        {
            DragStartPosition = curr_frame_position;
        }

        int start_x = Mathf.FloorToInt(DragStartPosition.x);
        int end_x   = Mathf.FloorToInt(curr_frame_position.x);
        int start_y = Mathf.FloorToInt(DragStartPosition.y);
        int end_y   = Mathf.FloorToInt(curr_frame_position.y);


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


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


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


        if (Input.GetMouseButton(1))
        {
            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)
                    {
                        GameObject go = SimplePool.Spawn(Circle_Cursor_Prefab, new Vector3(x, y, 0), Quaternion.identity);
                        Highlight_Prefabs.Add(go);
                        go.transform.SetParent(this.transform, true);
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();
            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 BuildModeModeController. DoWork()
                        // Tiles are passed to the DoBuild Function which starts the building process of both floor tiles and installed objects
                        bmc.DoBuild(t);
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    void UpdateDragging()
    {
        // If we're over a UI element, then bail out from this.
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

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

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

        // 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;
        }

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

        if (Input.GetMouseButton(0))
        {
            // 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
                        GameObject go = Instantiate(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }

        // End Drag
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();

            // 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);
                    }
                }
            }
        }
    }
    private void UpdateDrag()
    {
        //RETURN OVER UI
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        //!Start of drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPos = currFramePos;
        }

        int startX = Mathf.FloorToInt(dragStartPos.x);
        int endX   = Mathf.FloorToInt(currFramePos.x);
        int startY = Mathf.FloorToInt(dragStartPos.y);
        int endY   = Mathf.FloorToInt(currFramePos.y);

        if (endX < startX)   // IF we are dragging from the left.
        {
            int temp = endX;
            endX   = startX;
            startX = temp;
        }

        if (endY < startY)   // IF we are dragging from the left.
        {
            int temp = endY;
            endY   = startY;
            startY = temp;
        }



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

        if (Input.GetMouseButton(0))
        {
            //Display a preview of drag area
            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    Tile t = WorldController.Instance.World.GetTileAt(x, y);
                    if (t != null)
                    {
                        //Display Building hint ontop of tile
                        GameObject go = SimplePool.Spawn(cursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        dragPreviewGO.Add(go);
                    }
                }
            }
        }

        //! end drag
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();

            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    Tile t = WorldController.Instance.World.GetTileAt(x, y);

                    if (t != null)
                    {
                        //Call build mode controller do build
                        bmc.DoBuild(t);
                    }
                }
            }
        }
    }
Ejemplo n.º 10
0
    private void UpdateDragging()
    {
        //If over UI element, break
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        //Start LMB drag
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currentMousePosition;
        }

        int start_x = Mathf.RoundToInt(dragStartPosition.x);
        int end_x   = Mathf.RoundToInt(currentMousePosition.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(currentMousePosition.y);

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

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

        //checks if LMB is currently dragging
        if (Input.GetMouseButton(0))
        {
            //display preview of drag area
            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile t = WorldController.World.GetTileAt(x, y);
                    if (t != null)
                    {
                        //display the building hint on this tile position
                        GameObject go = SimplePool.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);
                        go.transform.SetParent(this.transform, true);
                        dragPreviews.Add(go);
                    }
                }
            }
        }

        //end LMB drag
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController bmc = FindObjectOfType <BuildModeController>();

            for (int x = start_x; x <= end_x; x++)
            {
                for (int y = start_y; y <= end_y; y++)
                {
                    Tile t = WorldController.World.GetTileAt(x, y);

                    if (t != null)
                    {
                        bmc.DoBuild(t);
                    }
                }
            }
        }
    }
Ejemplo n.º 11
0
    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);
                    }
                }
            }
        }
    }
    void UpdateDragging()
    {
        //if we are over a UI element, bail out !!
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }


        //Start drag
        //down, ça veut dire que on a cliqué sur les frames précédentes
        if (Input.GetMouseButtonDown(0))
        {
            dragStartPosition = currFramePosition;
        }

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

        // on swappe si en drag & drop vers la gauche la "mauvaise" direction
        //perso je trouve ça sale

        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
        //tant que y'a un gameobject dans dragpreviewmescouilles, (si y'en a un avec l'entree [0] ) tu l'enlève et le delete
        while (dragPreviewGameObjects.Count > 0)
        {
            GameObject go = dragPreviewGameObjects[0];
            dragPreviewGameObjects.RemoveAt(0);
            //au lieu de le delete, on va le despawn du simplepool, comme ça ça évite de créer détruire à mort plein d'éléments
            //ça fait économiser des ressources
            SimplePool.Despawn(go);
        }

        //juste le getmousedbutton, ça veut dire qu'on viens JUSTE de clique, sur CETTE frame
        if (Input.GetMouseButton(0))
        {
            //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 positon
                        //Quaternion.identity c'est pour créer un vector sans rotation
                        // on créé un gameobject qui s'appelle go, et on l'ajoute (add) a la liste de gameobject dragpreviewmescouilles
                        //et on le créé avec le script en CC simplepool
                        GameObject go = SimplePool.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity);

                        //ça permet juste de faire en sorte que les novueaux objets go soient apparentés à mousecontroller
                        //c'est plus propre dans la hierarchy des objets créés
                        go.transform.SetParent(this.transform, true);

                        dragPreviewGameObjects.Add(go);
                    }
                }
            }
        }


        //end drag (drop)
        if (Input.GetMouseButtonUp(0))
        {
            BuildModeController bmc = GameObject.FindObjectOfType <BuildModeController>();

            //go on loope 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);
                    }
                }
            }
        }
    }