Exemplo n.º 1
0
    public void SplitMaterial(CutLine lineToRemove)
    {
        WoodToCut[currentPieceIndex].transform.rotation = Quaternion.identity;
        WoodMaterialObject woodBoard = WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>();

        LinesToCut.Remove(lineToRemove);
        List <GameObject> pieces = WoodManagerHelper.SplitBoard(lineToRemove.GetFirstBaseNode(),
                                                                lineToRemove.GetSecondBaseNode(),
                                                                woodBoard, lineToRemove);

        if (LinesToCut.Count > 0)
        {
            foreach (GameObject piece in pieces)
            {
                if (piece.tag == "Piece")
                {
                    WoodToCut.RemoveAt(currentPieceIndex);
                    Destroy(piece);
                    NextPiece();
                }
                else if (piece.tag == "Leftover")
                {
                }
                else
                {
                    Rigidbody physics = piece.GetComponent <Rigidbody>();
                    if (physics == null)
                    {
                        physics = piece.AddComponent <Rigidbody>();
                    }
                    physics.useGravity = true;
                    BandSawPieceController controller = piece.AddComponent <BandSawPieceController>();
                    controller.Moveable          = true;
                    WoodToCut[currentPieceIndex] = piece;
                    PlacePiece();
                }
            }
        }
        else
        {
            UI_Manager.InfoPanel.SetActive(true);
            UI_Manager.InfoText.text = "All of the lines are cut. \nOn to the next step.";
            UI_Manager.HideButton.gameObject.SetActive(false);
            UI_Manager.StartOverButton.gameObject.SetActive(false);
            UI_Manager.NextSceneButton.gameObject.SetActive(true);
            StillCutting = false;
            float percentage = cumulativeLineScore / numberOfCuts;
            Debug.Log(percentage);
            if (GameManager.instance != null)
            {
                GameManager.instance.scoreTracker.ApplyScore(percentage);
            }
        }
    }
Exemplo n.º 2
0
    public void SplitMaterial(CutLine lineToRemove)
    {
        WoodMaterialObject board = AvailableWoodMaterial[currentPieceIndex].GetComponent <WoodMaterialObject>();
        BoardController    previousBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();

        LinesToCut.Remove(lineToRemove);
        AvailableWoodMaterial.RemoveAt(currentPieceIndex);
        List <GameObject> pieces = WoodManagerHelper.SplitBoard(lineToRemove.GetFirstBaseNode(),
                                                                lineToRemove.GetSecondBaseNode(),
                                                                board, lineToRemove);

        bool pieceAdded = false;

        foreach (GameObject piece in pieces)
        {
            WoodMaterialObject boardPiece = piece.GetComponent <WoodMaterialObject>();
            if (boardPiece != null)
            {
                bool lineFound = false;
                for (int i = 0; i < LinesToCut.Count && !lineFound; i++)
                {
                    lineFound = boardPiece.ContainsLine(LinesToCut[i]);
                }
                if (lineFound)
                {
                    BoardController controller = piece.AddComponent <BoardController>();
                    controller.Moveable   = true;
                    controller.WoodObject = boardPiece;
                    controller.MaxLimit_X = previousBoardController.MaxLimit_X;
                    controller.MaxLimit_Z = previousBoardController.MaxLimit_Z;
                    controller.MinLimit_X = previousBoardController.MinLimit_X;
                    controller.MinLimit_Z = previousBoardController.MinLimit_Z;
                    AvailableWoodMaterial.Add(piece);
                    if (!pieceAdded)
                    {
                        pieceAdded = true;
                        int index = AvailableWoodMaterial.IndexOf(piece);
                        currentPieceIndex = index;
                        AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                        currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                    }
                    else
                    {
                        piece.SetActive(false);
                        piece.transform.position = Vector3.zero;
                        piece.transform.rotation = Quaternion.identity;
                    }
                }
                else
                {
                    Destroy(piece);
                }
            }
            else
            {
                Destroy(piece);
            }

            if (!pieceAdded && AvailableWoodMaterial.Count > 0)
            {
                currentPieceIndex = 0;
                AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                SetupForCutting();
                EnableCurrentBoardMovement(true);
                RestrictCurrentBoardMovement(false, false);
                AvailableWoodMaterial[currentPieceIndex].transform.position = currentSpawnPoint.position + new Vector3(0.0f, 0.0f, -1.0f);
                Vector3    directionToPiece = (AvailableWoodMaterial[currentPieceIndex].transform.position - currentSpawnPoint.position).normalized;
                Ray        ray = new Ray(currentSpawnPoint.position, directionToPiece);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                {
                    float distance = (hit.point - currentSpawnPoint.position).magnitude;
                    AvailableWoodMaterial[currentPieceIndex].transform.position += (distance * -directionToPiece);
                }
            }
            SawBlade.TurnOff();
            UI_Manager.ChangeSawButtons(false);
        }

        if (LinesToCut.Count > 0)
        {
            UI_Manager.UpdateSelectionButtons(currentPieceIndex, AvailableWoodMaterial.Count);
        }
        else
        {
            UI_Manager.InfoPanel.SetActive(true);
            UI_Manager.InfoText.text = "All of the lines are cut. \nOn to the next step.";
            UI_Manager.HideButton.gameObject.SetActive(false);
            UI_Manager.StartOverButton.gameObject.SetActive(false);
            UI_Manager.NextSceneButton.gameObject.SetActive(true);
            StillCutting = false;
            float percentage = cumulativeLineScore / numberOfCuts;
            if (GameManager.instance != null)
            {
                GameManager.instance.ApplyScore(percentage);
            }
            else
            {
                Debug.Log("Score Applied: " + percentage);
            }
        }
    }
    /// <summary>
    /// Handles what happens after a line is cut
    /// </summary>
    /// <param name="lineToRemove">The line that was cut</param>
    public void SplitMaterial(CutLine lineToRemove)
    {
        //Delete the cut line and get the split wood material
        WoodMaterialObject board = AvailableWoodMaterial[currentPieceIndex].GetComponent <WoodMaterialObject>();
        BoardController    previousBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();

        LinesToCut.Remove(lineToRemove);
        AvailableWoodMaterial.RemoveAt(currentPieceIndex);
        List <GameObject> pieces = WoodManagerHelper.SplitBoard(lineToRemove.GetFirstBaseNode(),
                                                                lineToRemove.GetSecondBaseNode(),
                                                                board, lineToRemove);

        bool pieceAdded = false;

        //This loop looks through the wood materials returned, assigns them a BoardController, and use the first piece found as the piece
        //to put on the table saw. All other pieces are hidden away until they are needed.
        foreach (GameObject piece in pieces)
        {
            WoodMaterialObject boardPiece = piece.GetComponent <WoodMaterialObject>();
            if (boardPiece != null)
            {
                bool lineFound = false;
                for (int i = 0; i < LinesToCut.Count && !lineFound; i++)
                {
                    lineFound = boardPiece.ContainsLine(LinesToCut[i]);
                }
                //If a line is found, then the piece is a wood material gameobject
                if (lineFound)
                {
                    BoardController controller = piece.AddComponent <BoardController>();
                    controller.Moveable   = true;
                    controller.WoodObject = boardPiece;
                    controller.MaxLimit_X = previousBoardController.MaxLimit_X;
                    controller.MaxLimit_Z = previousBoardController.MaxLimit_Z;
                    controller.MinLimit_X = previousBoardController.MinLimit_X;
                    controller.MinLimit_Z = previousBoardController.MinLimit_Z;
                    AvailableWoodMaterial.Add(piece);
                    if (!pieceAdded)
                    {
                        pieceAdded = true;
                        int index = AvailableWoodMaterial.IndexOf(piece);
                        currentPieceIndex = index;
                        AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                        currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                    }
                    else
                    {
                        piece.SetActive(false);
                        piece.transform.position = Vector3.zero;
                        piece.transform.rotation = Quaternion.identity;
                    }
                }
                else
                {
                    Destroy(piece);
                }
            }
            else
            {
                //This was kept around for the prototype,
                //but we technically want to keep the piece around if it is a piece gameobject, or a wood material gameobject
                //There just needs to be a container that will store all of the pieces and wood materials in the project.
                Destroy(piece);
            }

            //If none of the pieces were wood material gameobjects, find one from the AvailableWoodMaterial list
            if (!pieceAdded && AvailableWoodMaterial.Count > 0)
            {
                currentPieceIndex = 0;
                AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                SetupForCutting();
                EnableCurrentBoardMovement(true);
                RestrictCurrentBoardMovement(false, false);
                AvailableWoodMaterial[currentPieceIndex].GetComponent <Rigidbody>().position = currentSpawnPoint.position + new Vector3(0.0f, 0.0f, -1.0f);
                Vector3    directionToPiece = (AvailableWoodMaterial[currentPieceIndex].GetComponent <Rigidbody>().position - currentSpawnPoint.position).normalized;
                Ray        ray = new Ray(currentSpawnPoint.position, directionToPiece);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                {
                    float distance = (hit.point - currentSpawnPoint.position).magnitude;
                    AvailableWoodMaterial[currentPieceIndex].GetComponent <Rigidbody>().position += (distance * -directionToPiece);
                }
            }
            SawBlade.TurnOff();
            UI_Manager.ChangeSawButtons(false);
        }

        //If all the lines are cut, the step is done
        if (LinesToCut.Count > 0)
        {
            UI_Manager.UpdateSelectionButtons(currentPieceIndex, AvailableWoodMaterial.Count);
        }
        else
        {
            UI_Manager.InfoPanel.SetActive(true);
            UI_Manager.InfoText.text = "All of the lines are cut. \nOn to the next step.";
            UI_Manager.HideButton.gameObject.SetActive(false);
            UI_Manager.StartOverButton.gameObject.SetActive(false);
            UI_Manager.NextSceneButton.gameObject.SetActive(true);
            StillCutting = false;
            float percentage = cumulativeLineScore / numberOfCuts;
            if (GameManager.instance != null)
            {
                GameManager.instance.scoreTracker.ApplyScore(percentage);
            }
            else
            {
                Debug.Log("Score Applied: " + percentage);
            }
        }
    }
Exemplo n.º 4
0
    public void SplitMaterial(CutLine lineToRemove)
    {
        WoodMaterialObject board = AvailableWoodMaterial[currentPieceIndex].GetComponent <WoodMaterialObject>();
        BoardController    previousBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();

        LinesToCut.Remove(lineToRemove);
        AvailableWoodMaterial.RemoveAt(currentPieceIndex);
        List <GameObject> pieces = WoodManagerHelper.SplitBoard(lineToRemove.GetFirstBaseNode(),
                                                                lineToRemove.GetSecondBaseNode(),
                                                                board, lineToRemove);

        bool pieceAdded = false;

        foreach (GameObject piece in pieces)
        {
            WoodMaterialObject boardPiece = piece.GetComponent <WoodMaterialObject>();
            if (boardPiece != null)
            {
                bool lineFound = false;
                for (int i = 0; i < LinesToCut.Count && !lineFound; i++)
                {
                    lineFound = boardPiece.ContainsLine(LinesToCut[i]);
                }
                if (lineFound)
                {
                    BoardController controller = piece.AddComponent <BoardController>();
                    controller.Moveable   = true;
                    controller.WoodObject = boardPiece;
                    controller.MaxLimit_X = previousBoardController.MaxLimit_X;
                    controller.MaxLimit_Z = previousBoardController.MaxLimit_Z;
                    controller.MinLimit_X = previousBoardController.MinLimit_X;
                    controller.MinLimit_Z = previousBoardController.MinLimit_Z;
                    AvailableWoodMaterial.Add(piece);
                    if (!pieceAdded)
                    {
                        pieceAdded = true;
                        int index = AvailableWoodMaterial.IndexOf(piece);
                        currentPieceIndex = index;
                        AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                        currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                    }
                    else
                    {
                        piece.SetActive(false);
                        piece.transform.position = Vector3.zero;
                        piece.transform.rotation = Quaternion.identity;
                    }
                }
                else
                {
                    Destroy(piece);
                }
            }
        }

        if (!pieceAdded && AvailableWoodMaterial.Count > 0)
        {
            currentPieceIndex = 0;
            AvailableWoodMaterial[currentPieceIndex].SetActive(true);
            currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
            SetupForCutting();
            PlacePiece();
        }
        SawBlade.TurnOff();
        UI_Manager.ChangeSawButtons(false);

        if (LinesToCut.Count > 0)
        {
            UI_Manager.UpdateSelectionButtons(currentPieceIndex, AvailableWoodMaterial.Count);
        }
        else
        {
            UI_Manager.InfoPanel.SetActive(true);
            UI_Manager.InfoText.text = "All of the lines are cut. \nOn to the next step.";
            UI_Manager.HideButton.gameObject.SetActive(false);
            UI_Manager.StartOverButton.gameObject.SetActive(false);
            UI_Manager.NextSceneButton.gameObject.SetActive(true);
            StillCutting = false;
            float percentage = cumulativeLineScore / numberOfCuts;
            if (GameManager.instance != null)
            {
                GameManager.instance.ApplyScore(percentage);
            }
            else
            {
                Debug.Log("No game manager");
            }
        }
    }