예제 #1
0
    public void SplitMaterial(DadoBlock dadoToRemove)
    {
        if (!dadoToRemove.AnyCutsLeft())
        {
            WoodMaterialObject board = AvailableWoodMaterial[currentPieceIndex].GetComponent <WoodMaterialObject>();
            DadosToCut.Remove(dadoToRemove);
            board.RemoveDado(dadoToRemove);
            Destroy(dadoToRemove.gameObject);

            if (board.DadosToCut.Count <= 0)
            {
                AvailableWoodMaterial.RemoveAt(currentPieceIndex);
                Destroy(board.gameObject);
                if (AvailableWoodMaterial.Count > 0)
                {
                    currentPieceIndex = 0;
                    AvailableWoodMaterial[currentPieceIndex].SetActive(true);
                    currentBoardController = AvailableWoodMaterial[currentPieceIndex].GetComponent <BoardController>();
                    UI_Manager.UpdateSelectionButtons(currentPieceIndex, AvailableWoodMaterial.Count);
                    SetupForCutting();
                    PlacePiece();
                }
            }
        }
        SawBlade.TurnOff();
        UI_Manager.ChangeSawButtons(false);

        if (DadosToCut.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");
            }
        }
    }
    /// <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);
            }
        }
    }
예제 #3
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);
            }
        }
    }
예제 #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");
            }
        }
    }