private static string GetMatrixPosition(int id, int x, int y) { PuzzleObject obj; int top = SearchTopSide(id, x); int bottom = SearchBottomSide(id, x, y); int left = SearchLeftSide(id, x); int right = SearchRightSide(id, x); if (top == 3) { obj = new PuzzleObject(id - x); string b_side = obj.GetTypeSide(); //Debug.Log("top " + b_side); top = (b_side[1] == '1') ? 2: 1; } if (left == 3) { obj = new PuzzleObject(id - 1); string r_side = obj.GetTypeSide(); //Debug.Log("left " + r_side); left = (r_side[3] == '1') ? 2: 1; } return(top + "" + bottom + "" + left + "" + right); }
public static void GeneratorPuzzles(int x, int y, string image) { puzzleArray = new PuzzleObject[y * x]; backArray = new PuzzleObject[y * x]; //horizontal for (int i = 0; i < y; i++) { //vertical for (int j = 0; j < x; j++) { //formula getting id of puzzle int id = j + (x * i) + 1; PuzzleObject puzzle = new PuzzleObject("puzzle_UI", new Vector3(GeneratePX(), GeneratePZ(), 0), id, Scale(x)); //save object puzzleArray[id - 1] = puzzle; //Debug.Log("start id = " + id + " / x=" + x + " / y=" + y); puzzle.SetMaterial(image, GetMatrixPosition(id, x, y)); //float off = 1.0f / (float)y * 0.32f; float off_x = 1.0f / (float)x * 0.32f; float off_y = 1.0f / (float)y * 0.32f; puzzle.SetMaterialOffset(new Vector2((1.0f / (float)x * (float)j) - off_x, (1.0f / (float)y * ((float)y - 1 - (float)i)) - off_y)); float scale_x = 1.0f / (float)x * 0.609f; puzzle.SetMaterialScale(new Vector2((1.0f / (float)x) + scale_x, (1.0f / (float)y) / 0.609f)); PuzzleObject puzzle_back = new PuzzleObject("puzzle_UI_back", back_position(id, x, y), id, Scale(x), "back"); backArray[id - 1] = puzzle_back; puzzle_back.SetMaterial("back", puzzle.GetTypeSide()); //puzzle_back.SetMaterialOffset(new Vector2((1.0f / (float)x * (float)j) - off_x, (1.0f / (float)y * ((float)y - 1 -(float)i)) - off_y)); //puzzle_back.SetMaterialScale(new Vector2((1.0f / (float)x) + scale_x, (1.0f / (float)y) / 0.609f)); puzzle_back.AttachToBack(); puzzle_back.SetTransform(back_position(id, x, y)); } } }