void InitAllGameviewSizes() { // Remove all resolutions not in devices List <string> deviceSizes = new List <string>(); foreach (ScreenshotResolution res in m_ConfigAsset.m_Config.GetActiveResolutions()) { deviceSizes.Add(m_GameviewSizeName + res.ToString()); } List <string> gameviewSizes = GameViewUtils.GetAllSizeNames(); foreach (string size in gameviewSizes) { if (size.Contains(m_GameviewSizeName) && !deviceSizes.Contains(size)) { GameViewUtils.RemoveCustomSize(GameViewUtils.FindSize(size)); } } // Add all new devices foreach (ScreenshotResolution res in m_ConfigAsset.m_Config.GetActiveResolutions()) { if (!gameviewSizes.Contains(m_GameviewSizeName + res.ToString())) { GameViewUtils.AddCustomSize(GameViewUtils.SizeType.FIXED_RESOLUTION, res.ComputeTargetWidth(), res.ComputeTargetHeight(), m_GameviewSizeName + res.ToString()); } } }
public static void SetSize(int width, int height) { GameViewSizeGroupType currentType = GameViewUtils.GetCurrentGroupType(); bool addToList = false; if (!GameViewUtils.SizeExists(currentType, width, height)) { string viewName = GetViewName(width, height); GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, currentType, width, height, viewName); addToList = true; } int index = GameViewUtils.FindSize(currentType, width, height); if (index < 0) { Debug.LogError("Cannot find Game View Size for width: " + width.ToString() + " height: " + height.ToString()); } else { if (addToList) { indices.Add(index); } GameViewUtils.SetSize(index); } }
static void EnsureSizeExists(OrientationMetadata orientationMetadata) { if (GameViewUtils.SizeExists(GROUP_TYPE, orientationMetadata.sizeName)) { return; } GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, GROUP_TYPE, orientationMetadata.width, orientationMetadata.height, orientationMetadata.sizeName); }
//Allows switching to a size, if the size is not in the list, add and switch public static void SwitchToSize(Vector2 compareSize, GameViewUtils.GameViewSizeType resoType, string name) { int displayIndex = FindSize(compareSize); if (displayIndex < 0) { GameViewUtils.AddCustomSize(resoType, (int)compareSize.x, (int)compareSize.y, name); int index = FindSize(compareSize); GameViewUtils.SetSize(index); } else { GameViewUtils.SetSize(displayIndex); } }
void SetGameViewSize() { if (typedTarget == null) { return; } if (GameViewUtils.SizeExists(GameViewSizeGroupType.Standalone, testGameViewSize)) { GameViewUtils.RemoveCustomSize(GameViewSizeGroupType.Standalone, GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, testGameViewSize)); } GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, GameViewSizeGroupType.Standalone, typedTarget.ImageComparisonSettings.TargetWidth, typedTarget.ImageComparisonSettings.TargetHeight, testGameViewSize); GameViewUtils.SetSize(GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, testGameViewSize)); }
private async Task PerformShot() { if (this.bundleType == ScreenshotBundleType.None) { int width = resWidth * scale; int height = resHeight * scale; this.Capture(width, height, ScreenShotName(width, height)); } else { var screenshotBundle = ScreenshotBundle.ByType(this.bundleType); foreach (var screenshotDefinition in screenshotBundle.definitions) { int width = screenshotDefinition.width * scale; int height = screenshotDefinition.height * scale; if (GameViewUtils.FindSize(GameViewUtils.GetCurrentGroupType(), width, height) == -1) { GameViewUtils.AddCustomSize(GameViewSizeType.FixedResolution, GameViewUtils.GetCurrentGroupType(), width, height, screenshotDefinition.suffix); } GameViewUtils.SetSize(GameViewUtils.FindSize(GameViewUtils.GetCurrentGroupType(), width, height)); await Task.Delay(ShutterDelay); var directory = screenshotBundle.GetDirectory(screenshotDefinition); this.PrepareDirectory(path + "/", directory); var fullPath = $"{path}/{directory}"; var fileName = string.Format("{0}{1}_{2}.png", fullPath, screenshotDefinition.Name, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); this.Capture(width, height, fileName); } } }
private static IEnumerator TakeAndSave_(int w, int h) { GameViewSizeGroupType type; if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { type = GameViewSizeGroupType.Android; } else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { type = GameViewSizeGroupType.iOS; } else { throw new Exception( $"Target platform must be Android or iOS, it is {EditorUserBuildSettings.activeBuildTarget}"); } int size = GameViewUtils.FindSize(type, w, h); if (size < 0) { GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, type, w, h, $"SS_{w}x{h}"); Debug.Log("Add size " + $"SS_{w}x{h}"); EditorApplication.Step(); size = GameViewUtils.FindSize(type, w, h); } if (size < 0) { throw new Exception("Cannot find size (1)"); } GameViewUtils.SetSize(size); yield return(null); AssetDatabase.Refresh(); var path = Application.dataPath.Replace("Assets", "") + $"Screenshots/{w}x{h}_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}" + ".png"; ScreenCapture.CaptureScreenshot(path, 1); yield return(null); AssetDatabase.Refresh(); /* * yield return null; * * w = _w; * h = _h; * Debug.Log(size); * size = GameViewUtils.FindSize(type, w, h); * GameViewUtils.SetSize(size); */ }
/// <summary> /// Updates by positioning the camera over the current model /// and capture a screenshot to be used as a 2D tile for that model. /// Another perspective camera is used to capture the screenshot for the /// 3D preview tile. This function also handles rotating all models once /// the current rotaion is completed for all of them. All tiles are captured /// as 3D preview in addition to top-view with 0, 90, 180 and 270 degrees rotations. /// File name format is height-tileObjectName_Rotation.png. /// When tile generation is done, the current object is saved as a prefab with collection /// name in "Assets/Prefabs" folder /// </summary> void Update() { if (transform.childCount == 0) { Debug.LogWarning("Warning: '" + gameObject.name + "' has no children to build tiles from. Exiting..."); UnityEditor.EditorApplication.isPlaying = false; return; } if (prevCam == null) { return; } if (!GameViewUtils.SizeExists(GameViewSizeGroupType.Standalone, tileSize, tileSize)) { GameViewUtils.AddCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, GameViewSizeGroupType.Standalone, tileSize, tileSize, tileSize + "*" + tileSize + " tile generation"); } GameViewUtils.SetSize(GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, tileSize, tileSize)); if (string.IsNullOrEmpty(collectionName.Trim())) { Debug.LogWarning("Warning: collection name cannot be empty. Exiting..."); UnityEditor.EditorApplication.isPlaying = false; return; } string tilesPath = Application.dataPath + "/" + TILES_FOLDER + "/" + collectionName; if (rot > 270) { SetTextureAlpha(); GenerateTilesetFile(); Debug.Log("Done!! your sprites are in " + tilesPath); try { string atlasesFullPath = Application.dataPath + "/Resources/" + ATLASES_FOLDER; if (!Directory.Exists(atlasesFullPath)) { Directory.CreateDirectory(atlasesFullPath); } //Object prefab = PrefabUtility.CreateEmptyPrefab("Assets/Resources/" + ATLASES_FOLDER + "/" + collectionName + ".prefab"); //PrefabUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, "Assets/Resources/" + ATLASES_FOLDER + "/" + collectionName + ".prefab", InteractionMode.AutomatedAction); Debug.Log("Your tile collection was saved as " + atlasesFullPath + "/" + collectionName + ".prefab"); } catch { Debug.LogError("Error: unable to save atlas prefab"); } UnityEditor.EditorApplication.isPlaying = false; EditorScriptsController.enableSpriteImporter2D = true; AssetDatabase.Refresh(); EditorScriptsController.enableSpriteImporter2D = false; return; } MoveToNext(); if (Time.frameCount < 5) { return; } string rotString = "_000"; if (index == transform.childCount - 1) { //Special case of last tile if (rot == 0) { rotString = "_090"; } else if (rot == 90) { rotString = "_180"; } else if (rot == 180) { rotString = "_270"; } } else { if (rot == 90) { rotString = "_090"; } else if (rot == 180) { rotString = "_180"; } else if (rot == 270) { rotString = "_270"; } } currentTile = current.GetComponent <Tile3D>(); string fullPath; if (rot != -90) { fullPath = tilesPath + "/" + currentTile.height.ToString("F2") + "-" + current.name + rotString + ".png"; } else { fullPath = tilesPath + "/" + currentTile.height.ToString("F2") + "-" + current.name + "__PRV" + ".png"; } generatedPaths.Add(fullPath); if (!Directory.Exists(tilesPath)) { Directory.CreateDirectory(tilesPath); } try { ScreenCapture.CaptureScreenshot(fullPath); } catch { Debug.LogError("Error: unable to save 2D tile sprite '" + fullPath + "'. Exiting..."); UnityEditor.EditorApplication.isPlaying = false; } index++; if (index == transform.childCount) { index = 0; rot += 90; if (rot != 0) { for (int i = 0; i < transform.childCount; i++) { Transform t = transform.GetChild(i); t.Rotate(0, 90, 0, Space.World); } } } }