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); }
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)); }
public IEnumerator CaptureMultipleResolutions() { locked = true; Time.timeScale = 0; count++; yield return(new WaitForEndOfFrame()); for (int i = 0; i < resolutions.Length; i++) { if (GameViewUtils.SizeExists(resolutions[i])) { GameViewUtils.SetSize(resolutions[i]); yield return(new WaitForEndOfFrame()); Capture(resolutions[i]); } } GameViewUtils.SetSize(currentResolution); Time.timeScale = currentTimeScale; locked = false; }
/// <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); } } } }