public static void ChangeID(ref PuzzleData puzzleData,PuzzleOperaterParam puzzleParam,int targetID) { PuzzlePiece selectedPuzzle = puzzleData.pieceObjectList[puzzleData.selectedPieceNo].GetComponent<PuzzlePiece>(); PuzzlePiece nowPiece; int targetObjectIdx = puzzleData.FindPieceObjectIndex(targetID); int tempID = selectedPuzzle.ID; // debug if(PuzzleStateChecker.HasIndexOutOfRange(puzzleData,targetObjectIdx)) return; // The amount of movement becomes a constant value,Change ID Vector3 amount = puzzleData.pieceObjectList[targetObjectIdx].transform.position - selectedPuzzle.transform.position; if( amount.x < puzzleParam.puzzleSpace && amount.x > -puzzleParam.puzzleSpace && amount.z < puzzleParam.puzzleSpace && amount.z > -puzzleParam.puzzleSpace ) { nowPiece = puzzleData.pieceObjectList[targetObjectIdx].GetComponent<PuzzlePiece>(); nowPiece.ID = tempID; selectedPuzzle.ID = targetID; selectedPuzzle.MoveAmountClear(PuzzleCalculator.GetPiecePosition(puzzleParam,targetID)); nowPiece.Move(PuzzleCalculator.GetPiecePosition(puzzleParam,tempID),puzzleParam.moveTime); } // Register puzzles traced puzzleData.selectedPieceNameList.Add(puzzleData.pieceObjectList[targetObjectIdx].name); }
public static void SortByRefEmpty(ref PuzzleData puzzleData,PuzzleOperaterParam puzzleParam) { // Rearranged in ascending order of ID puzzles puzzleData.Sort(); for(int puzzleNo = puzzleData.pieceObjectList.Count - 1; puzzleNo >= 0;puzzleNo--) { Vector3 puzzlePos = Vector3.zero; PuzzlePiece nowPiece = puzzleData.pieceObjectList[puzzleNo].GetComponent<PuzzlePiece>(); // It moves one on the target is empty int targetRowNo = PuzzleCalculator.GetPieceRowNo(puzzleParam,nowPiece.ID); if(targetRowNo < puzzleParam.maxRows - 1) { // Check until it can move for(int id = nowPiece.ID + puzzleParam.maxColumns;id < puzzleParam.maxPuzzles;id += puzzleParam.maxColumns) { GameObject emptyTemp = puzzleData.pieceObjectList[puzzleData.FindPieceObjectIndex(id)]; PuzzlePiece emptyPuzzle = emptyTemp.GetComponent<PuzzlePiece>(); if(emptyPuzzle.used == false) { emptyPuzzle.ID = nowPiece.ID; nowPiece.ID = id; emptyPuzzle.Stop(); emptyTemp.transform.position = PuzzleCalculator.GetPiecePosition(puzzleParam,emptyPuzzle.ID); } } } nowPiece.MoveAmountClear(); // Move puzzle piece Vector3 nowPos = puzzleData.pieceObjectList[puzzleNo].transform.position; Vector3 targetPos = PuzzleCalculator.GetPiecePosition(puzzleParam,nowPiece.ID); if(Vector3.Distance(nowPos,targetPos) > PuzzleCalculator.GetPieceSpaceOffset(puzzleParam)) nowPiece.Move(targetPos,puzzleParam.moveTime); } }