private IEnumerator DoSetupRoutine(Texture2D originalTexture, string originalTexturePath, SlicedTextureInfo savedTextureInfo = null) { BackButtonManager.Instance.Suspend(); PrepareUIForSetup(); var originalSize = new Vector2(originalTexture.width, originalTexture.height); var slicingInfo = savedTextureInfo == null?ImgSlicer.GetSliceInfo(originalSize, startMenu.SelectedDifficulty) : new SlicingInfo(savedTextureInfo); InitPlayFieldAndContainers(slicingInfo, originalTexture); Texture2D slicedTexture; var couldLoadSavedTexture = TextureUtility.TryLoadSavedTexture(originalSize, slicingInfo.rows, slicingInfo.columns, savedTextureInfo, originalTexturePath, out slicedTexture); if (!couldLoadSavedTexture) { var pieceConnections = ImgSlicer.SetupConnections(slicingInfo); yield return(ImgSlicer.CreateAndSaveSlicedTextureRoutine(slicingInfo, originalTexture, slicedTexture, originalTexturePath, maskContainer, pieceConnections, loadingScreen.SetLoadStatus)); } slicedTexture.wrapMode = TextureWrapMode.Clamp; slicedTexture.Apply(true, true); SetupPrefabs(slicingInfo.rows, slicingInfo.columns, slicedTexture, couldLoadSavedTexture); Resources.UnloadUnusedAssets(); DoStartGame(); }
public void SliceCountTests01() { Vector2 imgSize = new Vector2(800f, 600f); // Slice the longer side to 8 pieces => it's expected // that the shorter one will be cut to 6 pieces, so as // to have pieces as square as possible. const int pieceCountForLongerSide = 8; var imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, pieceCountForLongerSide); Assert.IsTrue(imgSliceInfo.rows == 6 && imgSliceInfo.columns == 8, imgSliceInfo.ToString()); imgSize = new Vector2(600f, 800f); imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, pieceCountForLongerSide); Assert.IsTrue(imgSliceInfo.rows == 8 && imgSliceInfo.columns == 6, imgSliceInfo.ToString()); }
public void SliceCountTests03() { var imgSize = new Vector2(1024f, 768f); var imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, Difficulty.Easy); // longer side to 4 pieces => shorter to 3 Assert.IsTrue(imgSliceInfo.rows == 3 && imgSliceInfo.columns == 4, imgSliceInfo.ToString()); // longer side avg(4, 1024 / 50)/2 = 12, shorter side to 768 / (1024 / 12) = 9 imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, Difficulty.Medium); Assert.IsTrue(imgSliceInfo.rows == 9 && imgSliceInfo.columns == 12, imgSliceInfo.ToString()); // longer side to 20, shorter side to 768 / (1024 / 20) = 15 imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, Difficulty.Hard); Assert.IsTrue(imgSliceInfo.rows == 15 && imgSliceInfo.columns == 20, imgSliceInfo.ToString()); }
public void SliceCountTests02() { Vector2 imgSize = new Vector2(1024f, 768f); // 1024 x 768, longer side cut to 6 pieces const int pieceCountForLongerSide = 6; var imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, pieceCountForLongerSide); Assert.IsTrue(imgSliceInfo.rows == 4 && imgSliceInfo.columns == 6, imgSliceInfo.ToString()); // 900 x 1600, longer side cut to 6 pieces imgSize = new Vector2(900f, 1600f); imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, pieceCountForLongerSide); Assert.IsTrue(imgSliceInfo.rows == 6 && imgSliceInfo.columns == 3, imgSliceInfo.ToString()); // 900 x 1600, longer side to 7 pieces imgSliceInfo = ImgSlicer.GetSliceInfo(imgSize, pieceCountForLongerSide: 7); Assert.IsTrue(imgSliceInfo.rows == 7 && imgSliceInfo.columns == 4, imgSliceInfo.ToString()); }