public CutLine GetNearestLine(Vector3 fromPosition) { bool lineFound = false; int nearestLineIndex = -1; float smallestDistance = 0.0f; if (WoodToCut == null) { Debug.Log(WoodToCut); } if (WoodToCut[currentPieceIndex] == null) { Debug.Log(WoodToCut[currentPieceIndex]); } if (WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>() == null) { Debug.Log(WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>()); } if (WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>() == null) { Debug.Log(WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>().LinesToCut); } if (WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>().LinesToCut == null) { Debug.Log(WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>().LinesToCut); } List <CutLine> lines = WoodToCut[currentPieceIndex].GetComponent <WoodMaterialObject>().LinesToCut; for (int i = 0; i < lines.Count && !lineFound; i++) { CutLine currentLine = lines[i]; if (currentLine != null) { if (currentLine.CutType == CutLineType.CurvatureCut) { float firstDistance = Vector3.Distance(fromPosition, currentLine.Checkpoints[0].GetPosition()); float lastDistance = Vector3.Distance(fromPosition, currentLine.Checkpoints[currentLine.Checkpoints.Count - 1].GetPosition()); if (nearestLineIndex == -1 || firstDistance < smallestDistance || lastDistance < smallestDistance) { if (nearestLineIndex == -1) { smallestDistance = (firstDistance < lastDistance) ? firstDistance : lastDistance; } else { smallestDistance = (firstDistance < smallestDistance) ? firstDistance : smallestDistance; smallestDistance = (lastDistance < smallestDistance) ? lastDistance : smallestDistance; } nearestLineIndex = i; } } } } return(lines[nearestLineIndex]); }
void OnDisable() { if (currentLine != null) { currentLine.DisplayLine(false, true); currentLine = null; } CurrentState = CutState.ReadyToCut; SawBlade.ResetEdgePosition(); }
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); } } }
private void SwitchLine() { CutLine nearestLine = manager.GetNearestLine(Blade.transform.position); nearestLine.ChangeColor(SelectedLineColor); if (currentLine != null && currentLine != nearestLine) { currentLine.ResetColor(NotSelectedLineColor); } currentLine = nearestLine; }
public void LeaveMark(Gesture gesture) { if (gesture.pickedObject != null && CanMeasure && gesture.touchCount == 1) { if ((gesture.pickedObject.tag == "Piece" || gesture.pickedObject.tag == "Leftover") && SecondPointIsOnWoodMaterial(gesture.position)) { LineMark markedLine = currentLineRenderer.gameObject.AddComponent <LineMark>(); CutLine nearestLine = manager.GetNearestLine(currentLineRenderer.gameObject.transform.position); Vector3 markedPosition = currentLineRenderer.gameObject.transform.position; if (nearestLine.IsMarked) { GameObject previousLine = nearestLine.LineMark; nearestLine.LineMark = null; Destroy(previousLine); } if (MarkIsNearLine(nearestLine, markedPosition)) { markedLine.GoodLineMark = true; nearestLine.IsMarked = true; currentLineRenderer.material.color = GoodLineColor; } else { markedLine.GoodLineMark = false; nearestLine.IsMarked = true; currentLineRenderer.material.color = BadLineColor; } nearestLine.LineMark = currentLineRenderer.gameObject; markedLine.StartPoint = currentLineRenderer.gameObject.transform; GameObject secondPoint = new GameObject(); secondPoint.transform.position = SecondPosition; secondPoint.transform.parent = currentLineMark.transform; markedLine.EndPoint = secondPoint.transform; markedLine.line = currentLineRenderer; } else { if (currentLineRenderer != null) { Destroy(currentLineRenderer.material); Destroy(currentLineRenderer.gameObject); } } } else { if (currentLineRenderer != null) { Destroy(currentLineRenderer.material); Destroy(currentLineRenderer.gameObject); } } }
private void SwitchLine() { CutLine nearestLine = manager.GetNearestLine(SawBlade.transform.position); if (nearestLine.IsMarked && nearestLine.LineMark != null) { if (nearestLine.LineMark.GetComponent <LineMark>().GoodLineMark) { nearestLine.DisplayLine(true, true); } } if (currentLine != null && currentLine != nearestLine) { currentLine.DisplayLine(false, true); } currentLine = nearestLine; }
public bool MarkIsNearLine(CutLine line, Vector3 markPosition) { bool closeToLine = false; if (line.CutType == CutLineType.TableSawCut) { float distanceToLine = line.CalculateDistance(markPosition); closeToLine = (distanceToLine < OffsetFromLine); } else if (line.CutType == CutLineType.ChopSawCut) { Vector3 linePosition = line.Checkpoints[0].GetPosition(); Vector3 adjustedMarkedPosition = new Vector3(markPosition.x, linePosition.y, markPosition.z); Vector3 toAdjustedMark = adjustedMarkedPosition - linePosition; Vector3 rightOfLine = (linePosition + line.Checkpoints[0].transform.forward) - linePosition; float projectionOntoLine = Vector3.Dot(toAdjustedMark, rightOfLine); closeToLine = (Mathf.Abs(projectionOntoLine) < OffsetFromLine); } return(closeToLine); }
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); } } }
public static List <GameObject> SplitBoard(Node baseNode, Node baseNode2, WoodMaterialObject boardToSplit, CutLine detachedLine) { WoodManagerHelper.RemoveCutLine(boardToSplit, detachedLine); List <GameObject> splitPieces = new List <GameObject>(); splitPieces.Add(WoodManagerHelper.DeterminePiece(baseNode, ref boardToSplit)); splitPieces.Add(WoodManagerHelper.DeterminePiece(baseNode2, ref boardToSplit)); Destroy(boardToSplit.gameObject); return(splitPieces); }
void Start() { currentLine = null; //timeStalling = 0.0f; CurrentState = CutState.ReadyToCut; }
void Start() { currentLine = null; cuttingAlongLine = false; CurrentState = CutState.ReadyToCut; }
void Start() { CheckScoreRanges(); line = GetComponent <CutLine>(); }
void Update() { #region CuttingCode if (manager.StillCutting) { currentBladePosition = SawBlade.EdgePosition(); totalTimePassed += Time.deltaTime; UpdateFeedRateDate(); if (CurrentState == CutState.ReadyToCut) { SwitchLine(); if (SawBlade.CuttingWoodBoard && SawBlade.SawBladeActive) { Vector3 origin = SawBlade.EdgePosition() + new Vector3(0.0f, 0.5f, 0.0f); Ray ray = new Ray(origin, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover")) { Vector3 bladeEdgePosition = new Vector3(currentLine.GetCurrentCheckpointPosition().x, hit.point.y, hit.point.z); StartWoodCutting(bladeEdgePosition); } } } else if (CurrentState == CutState.Cutting && SawBlade.SawBladeActive) { if (cuttingAlongLine) { currentLine.UpdateLine(SawBlade.EdgePosition()); if (currentLine.LineIsCut()) { CurrentState = CutState.EndingCut; } else { if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; totalTimeStalling = 0.0f; FeedRateTracker.UpdateScoreWithRate(playerFeedRate); } if (FeedRateTracker.RateTooSlow || FeedRateTracker.RateTooFast) { totalTimeStalling += Time.deltaTime; FeedRateTracker.ReduceScoreDirectly(0.1f); if (totalTimeStalling >= MaxStallTime && FeedRateTracker.RateTooSlow) { manager.StopGameDueToLowScore("You were cutting too slow, now the wood is burnt."); } else if (totalTimeStalling >= 1.0f && FeedRateTracker.RateTooFast) { manager.StopGameDueToLowScore("You were cutting too fast and caused the saw to bind."); } } } } else { if (SawBlade.NoInteractionWithBoard) { timeNotCuttingLine = 0.0f; CurrentState = CutState.ReadyToCut; SawBlade.ResetEdgePosition(); currentLine = null; manager.RestrictCurrentBoardMovement(false, false); } else { timeNotCuttingLine += Time.deltaTime; if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; FeedRateTracker.ReduceScoreDirectly(0.8f); } if (timeNotCuttingLine >= MaxStallTime) { manager.StopGameDueToLowScore("You were not cutting along the line, and now the board is ruined."); } } } } else if (CurrentState == CutState.EndingCut) { if (!SawBlade.CuttingWoodBoard && SawBlade.NoInteractionWithBoard) { manager.DisplayScore(FeedRateTracker); manager.SplitMaterial(currentLine); cuttingAlongLine = false; currentLine = null; SawBlade.ResetEdgePosition(); CurrentState = CutState.ReadyToCut; FeedRateTracker.ResetFeedRate(); } } } previousBladePosition = currentBladePosition; if (FeedRateTracker.GetLineScore() <= 0.0f) { manager.StopGameDueToLowScore("This cut is too messed up to keep going."); } #endregion }
public static bool RunLineCut(CutLine line, bool preCut = false) { do { switch (line.CutStep) { case CutStep.Ready: //等待各轴移动到位 { if (line.SinDir || !line.Dual || (line.Dual && Globals.DevData.DualZlife)) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 } if (WaitAxisMoveDone()) //判断各轴是否到位 { line.Cutting = true; //开始切割 line.FirstCut = true; if (line.Seg != null && !line.Abs) { line.Seg.RepairXPosAndLength(Y_Axis.RealPos + line.StartPos.Y, line); //修正起始位置和长度 } if (preCut) //根据是否预划切 修正划切速度 { float s = Globals.Group.PreCut.GetPreDataSpeed(); if (s > 0 && s < line.Speed) //预划切值有效且小于当前划切速度 { line.Speed = s; } else { Globals.PreCut = false; } } line.CutStep = CutStep.ST1; } else { return(false); } } break; case CutStep.ST1: //X 轴移动到划切位置 需要根据当前Y轴位置重新计算X轴起点和划切长度 { X_Axis.JogAbs(line.BackSpeed, Globals.MacData.XCutBackAcc, line.StartPos.X); //设置X返回加速度 if (line.Abs) { Y_Axis.AxisJogAbsWork(line.StartPos.Y); } else { //float v = Math.Abs(line.StartPos.Y / line.Length * line.BackSpeed); //Y_Axis.JogInc(v, 0.1f, line.StartPos.Y); Y_Axis.AxisJogIncWork(line.StartPos.Y); //相对位置 } WaitAxisMoveDone(Y_Axis); if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST2; } else { return(false); } } break; case CutStep.ST2: //Z轴下落到划切位置1 { float pos = line.ReDepth + Globals.TestHeightValue - Globals.BldData.RealCompensatedValue; if (pos < Globals.TestHeightValue) //防止切割到工作台 { pos = Globals.TestHeightValue; } Z_Axis.JogAbs(Globals.MacData.ZCutSpeed, Globals.MacData.ZCutAcc, pos); //Z轴下落到位 必须等候Z到位 if (WaitAxisMoveDone(Z_Axis)) { line.CutStep = CutStep.ST3; } else { return(false); } } break; case CutStep.ST3: //X轴进行划切操作 { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? -line.Length : line.Length); //X轴开始缓慢划切 判断划切方向 if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST4; Globals.BldData.AddCutedLinesAndLength(1, line.Length / 1000); //已划切刀数 } else { return(false); } } break; case CutStep.ST4: //Z轴是否抬刀 { if (line.SinDir || !line.Dual || (line.Dual && Globals.DevData.DualZlife)) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 if (!WaitAxisMoveDone(Z_Axis)) { return(false); } } if (line.Dual) { line.CutStep = CutStep.ST5; } else { line.CutStep = CutStep.CutStop; } } break; case CutStep.ST5: //X轴返回到划切位置 { line.FirstCut = false; if (line.SinDir) //如果是单向划切X轴必须返回到划切位置 { X_Axis.JogAbs(line.BackSpeed, Globals.MacData.XCutBackAcc, line.StartPos.X); //需要重新设置X划切返回速度 if (!WaitAxisMoveDone(X_Axis)) { return(false); } } line.CutStep = CutStep.ST6; } break; case CutStep.ST6: //Z轴下落到划切位置 { if (preCut) //根据是否预划切 修正划切速度 { float s = Globals.Group.PreCut.GetPreDataSpeed(); if (s > 0 && s < line.Speed) //预划切值有效且小于当前划切速度 { line.Speed = s; } else { Globals.PreCut = false; } } float pos = line.ReDepth2 + Globals.TestHeightValue - Globals.BldData.RealCompensatedValue; if (pos < Globals.TestHeightValue) { pos = Globals.TestHeightValue; } Z_Axis.JogAbs(Globals.MacData.ZCutSpeed, Globals.MacData.ZCutAcc, pos); //Z轴下落到位置2 if (WaitAxisMoveDone(Z_Axis)) { line.CutStep = CutStep.ST7; } else { return(false); } } break; case CutStep.ST7: //X轴开始划切 { if (line.SinDir) { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? -line.Length : line.Length); //需要设置返回加速度 } else { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? line.Length : -line.Length); } if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST8; Globals.BldData.AddCutedLinesAndLength(1, line.Length / 1000); //已划切刀数 } else { return(false); } } break; case CutStep.ST8: //Z轴进行抬刀操作 { if (line.SinDir || !line.Dual) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 } line.Cutting = false; line.CutStep = CutStep.CutStop; } break; case CutStep.CutStop: //划切结束 { if (line.Pause) { line.CutStep = CutStep.Pause; } else { line.CutStep = CutStep.STEnd; //当前先判断为切割完成 后续需要判断是否暂停 刀痕检测 和测高 } ReportWorkingProgress(ProcessCmd.CutLineCmd, line); } break; case CutStep.KniefCheck: //进行刀痕检测 { } break; case CutStep.TestHeigh: //进行非接触式测高 { } break; case CutStep.Pause: { ReportCmdKeyProgress(CmdKey.P0105); line.CutStep = CutStep.STEnd; //配置为划切完成 return(false); //中断当前划切操作 } case CutStep.STEnd: { line.Complate = true; } break; default: { } break; } if (Globals.CutStop) { return(false); } ReportWorkingProgress(ProcessCmd.CutLineCmd, line); CuttingCheckStatus(); Thread.Sleep(10); } while (!line.Complate);//没有完成就一直循环 return(true); }//划切线
public void AddLine(CutLine lineToAdd) { LinesToCut.Add(lineToAdd); }
public static void RemoveCutLine(WoodMaterialObject boardToSplit, CutLine detachedLine) { detachedLine.SeverConnections(); boardToSplit.RemoveLine(detachedLine); Destroy(detachedLine.gameObject); }
void Update() { #region CuttingCode if (manager.StillCutting) { totalTimePassed += Time.deltaTime; if (CurrentState == CutState.ReadyToCut) { SwitchLine(); if (Blade.CuttingWoodBoard && Blade.SawActive) { Vector3 origin = Blade.transform.position + new Vector3(0.0f, 0.1f, 0.0f); Ray ray = new Ray(origin, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover" || hit.collider.tag == "Dado")) { hit.collider.gameObject.transform.parent.GetComponent <BandSawPieceController>().RotationPoint = hit.point; StartWoodCutting(); } } } else if (CurrentState == CutState.Cutting && Blade.SawActive) { float distanceFromBlade = currentLine.CalculateDistance(Blade.transform.position); bool cuttingAlongLine = (distanceFromBlade <= ValidCutOffset); if (cuttingAlongLine) { currentLine.UpdateLine(Blade.transform.position, ValidCutOffset); if (currentLine.LineIsCut()) { CurrentState = CutState.EndOfCut; } if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; if (distanceFromBlade <= ValidCutOffset && distanceFromBlade >= 0.015f) { lineScore -= 0.2f; } else if (distanceFromBlade <= 0.015f && distanceFromBlade >= 0.01f) { lineScore -= 0.1f; } } } else { if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; lineScore -= 0.5f; } totalTimeNotCuttingLine += Time.deltaTime; if (totalTimeNotCuttingLine >= MaxTimeAwayFromLine) { manager.StopGameDueToLowScore("You've messed up the wood too much."); } else if (Blade.NoInteractionWithBoard) { CurrentState = CutState.ReadyToCut; Blade.ResetEdgePosition(); currentLine.Reset(); currentLine = null; manager.SetUpBoardForCutting(false); } } } else if (CurrentState == CutState.EndOfCut) { if (!Blade.CuttingWoodBoard && Blade.NoInteractionWithBoard) { manager.DisplayScore(lineScore); lineScore = 100.0f; manager.SetUpBoardForCutting(false); manager.SplitMaterial(currentLine); currentLine = null; Blade.ResetEdgePosition(); CurrentState = CutState.ReadyToCut; } } if (lineScore <= 0.0f) { manager.StopGameDueToLowScore("This cut is too messed up to keep going."); } if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; } } #endregion }
/// <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); } } }
public bool ContainsLine(CutLine line) { return(LinesToCut.Contains(line)); }
private void ProcessCutLineStep(CutLine line) { switch (line.CutStep) { case CutStep.ST1: //更新划切等相关信息 { cutSpeed.Text = line.Speed.ToString(); //当前配置的划切速度 cutLeaveLines.Text = line.Seg.WaitCutNum.ToString(); //当前剩余划切刀数 if (line.Seg != null) { cutProcess.StringFormat = string.Format(userFormat, line.Index, line.Seg.Lines.Count) + sysFormat; cutProcess.Value = (int)(line.Seg.CuttingIndex * 100 / line.Seg.Lines.Count); //划切进度条 } } break; case CutStep.ST3: { if (!watch.IsRunning) { watch.Start(); //开始计时 } lineCutPen.DashStyle = DashStyle.Dash; //虚线划切 startPoint = Globals.AxisPoint; //获取当前位置绝对位置 timer.Start(); //开始进行模拟划切 } break; case CutStep.ST7: { lineCutPen.DashStyle = DashStyle.Solid; startPoint = Globals.AxisPoint; //获取当前位置绝对位置 } break; case CutStep.ST8: case CutStep.CutStop: { if (timer.IsEnabled) { timer.Stop(); } } break; case CutStep.Pause: case CutStep.STEnd: { if (timer.IsEnabled) { timer.Stop(); } if (line.SinDir) { DrawLine(g, startPoint, line.Dir ? line.Length : -line.Length, false); } else { if (line.Dual) { DrawLine(g, startPoint, line.Dir ? -line.Length : line.Length, false); } else { DrawLine(g, startPoint, line.Dir ? line.Length : -line.Length, false); } } } break; //划切停止 default: break; } }
public void RemoveLine(CutLine lineToRemove) { LinesToCut.Remove(lineToRemove); }
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"); } } }