//RockManager用 public void Move(o_RockManager moveToRockManager, o_RockManager.MOVE right_left0, int colNum, int rowNum, Vector3 pos) { transform.parent = moveToRockManager.transform; if (pos != Vector3.zero) { if (ridingRock != null) { if (pos.x > 0.5f) { pos.x += (pos.x - 0.5f) * 2.0f; } else if (pos.x < -0.5f) { pos.x += (pos.x + 0.5f) * 2.0f; } else if (pos.y > 0.5f) { pos.y += (pos.y - 0.5f) * 2.0f; } else if (pos.y < -0.5f) { pos.y += (pos.y + 0.5f) * 2.0f; } } transform.localPosition = pos; } rockManager = moveToRockManager; right_left = right_left0; colum = colNum; row = rowNum; }
//外部参照用Player用 岩移動要求 public bool RockMove(o_RockManager.MOVE caseMove) { if (!canMove) { return(false); } return(rockManager.RockMoveM(this /*,colum*/, row, caseMove)); }
//Rockからよう 移動 成功ならtrue失敗ならfalse public bool RockMoveM(o_Rock rockA /*, int col*/, int row, o_RockManager.MOVE caseNum) { int[] adr = new int[2] { 0, 0 }; //Rockの位置検索 for (int listNum = 0; listNum < rocksCol; listNum++) { if (rockA.EqualsRocksPos(list_rocksR[listNum][row])) { adr[0] = (int)MOVE.RIGHT; adr[1] = listNum; break; } else if (rockA.EqualsRocksPos(list_rocksL[listNum][row])) { adr[0] = (int)MOVE.LEFT; adr[1] = listNum; break; } } //移動先岩マネージャー o_RockManager moveToRockManager = this; //移動先用アドレス int[] adr2 = { adr[0], adr[1], row }; //移動先調整 switch (caseNum) { case MOVE.UP: adr2[1]--; if (adr2[1] < 0) { adr2[1]++; if (adr[0] == (int)MOVE.RIGHT) { adr2[0] = (int)MOVE.LEFT; } else { adr2[0] = (int)MOVE.RIGHT; } } break; case MOVE.DOWN: adr2[1]++; if (adr2[1] >= rocksCol) { adr2[1]--; if (adr[0] == (int)MOVE.RIGHT) { adr2[0] = (int)MOVE.LEFT; } else { adr2[0] = (int)MOVE.RIGHT; } } break; case MOVE.FRONT: adr2[2]--; if (adr2[2] < 0) { if (moveToRockManager.frontRM == null) { return(false); } moveToRockManager = moveToRockManager.frontRM; adr2[2] = moveToRockManager.rocksRow - 1; } break; case MOVE.BACK: adr2[2]++; if (adr2[2] >= rocksRow) { if (moveToRockManager.backRM == null) { return(false); } moveToRockManager = moveToRockManager.backRM; adr2[2] = 0; } break; default: break; } //Debug.Log("adr2:" + adr2[0] + adr2[1] + adr2[2]); //移動 成功ならtrue失敗ならfalse switch (adr2[0]) { case (int)MOVE.RIGHT: //移動先が空なら突っ込む if (moveToRockManager.list_rocksR[adr2[1]][adr2[2]] == null) { moveToRockManager.list_rocksR[adr2[1]][adr2[2]] = rockA; if (!rockA.GetOffRock()) { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row] = null; } else { list_rocksL[adr[1]][row] = null; } } else { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row].CalcMass(); } else { list_rocksL[adr[1]][row].CalcMass(); } } } //移動先にあるなら乗せる else if (moveToRockManager.list_rocksR[adr2[1]][adr2[2]].RideRock(rockA)) { if (adr[0] == (int)MOVE.RIGHT) { if (rockA.Equals(list_rocksR[adr[1]][row])) { list_rocksR[adr[1]][row] = null; } else { list_rocksR[adr[1]][row].CalcMass(); } } else { if (rockA.Equals(list_rocksL[adr[1]][row])) { list_rocksL[adr[1]][row] = null; } else { list_rocksL[adr[1]][row].CalcMass(); } } } else { //乗せるのに失敗したらfalse return(false); } // rockA.Move(moveToRockManager, (MOVE)adr2[0], adr2[1], adr2[2], CalcMoveToPosition(adr2[0], adr2[1], adr2[2])); moveToRockManager.list_rocksR[adr2[1]][adr2[2]].CalcMass(); CalcMassRL(); return(true); break; case (int)MOVE.LEFT: if (moveToRockManager.list_rocksL[adr2[1]][adr2[2]] == null) { moveToRockManager.list_rocksL[adr2[1]][adr2[2]] = rockA; if (!rockA.GetOffRock()) { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row] = null; } else { list_rocksL[adr[1]][row] = null; } } else { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row].CalcMass(); } else { list_rocksL[adr[1]][row].CalcMass(); } } } else if (moveToRockManager.list_rocksL[adr2[1]][adr2[2]].RideRock(rockA)) { if (adr[0] == (int)MOVE.RIGHT) { if (rockA.Equals(list_rocksR[adr[1]][row])) { list_rocksR[adr[1]][row] = null; } else { list_rocksR[adr[1]][row].CalcMass(); } } else { if (rockA.Equals(list_rocksL[adr[1]][row])) { list_rocksL[adr[1]][row] = null; } else { list_rocksL[adr[1]][row].CalcMass(); } } } else { //乗せるのに失敗したらfalse return(false); } rockA.Move(moveToRockManager, (MOVE)adr2[0], adr2[1], adr2[2], CalcMoveToPosition(adr2[0], adr2[1], adr2[2])); moveToRockManager.list_rocksL[adr2[1]][adr2[2]].CalcMass(); CalcMassRL(); return(true); break; } return(false); }