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());
                }
            }
        }
예제 #2
0
파일: GameViewUtils.cs 프로젝트: eagee/CWAL
    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);
        }
    }
        public static void SizeIsAddedAndRemovedCorrectly()
        {
            GameViewUtils.AddOrGetCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, GameViewSizeGroupType.Standalone, 123, 456, "Test size");

            int idx = GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, 123, 456);

            Assert.AreNotEqual(-1, idx);
            GameViewUtils.RemoveCustomSize(GameViewSizeGroupType.Standalone, idx);

            idx = GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, 123, 456);
            Assert.AreEqual(-1, idx);
        }
예제 #4
0
 static void Update()
 {
     if (delayedMove > 0)
     {
         delayedMove--;
     }
     else if (delayedMove == 0)
     {
         MoveGameWindow();
         //set the proper aspect/resolution
         int gameSize = GameViewUtils.FindSize(GameViewSizeGroupType.Standalone, "Standalone");
         GameViewUtils.SetSize(gameSize);
         delayedMove--;
         EditorApplication.update -= Update;
     }
 }
예제 #5
0
    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);
            }
        }
    }
예제 #7
0
        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);
             */
        }
예제 #8
0
    void OnGUI()
    {
        EditorGUILayout.LabelField("Resolution", EditorStyles.boldLabel);
//		resWidth = EditorGUILayout.IntField ("Width", resWidth);
//		resHeight = EditorGUILayout.IntField ("Height", resHeight);

        EditorGUILayout.Space();

        for (int i = 0; i < resolutions.Length; i++)
        {
            resolutions[i] = EditorGUILayout.Vector2Field("size -> ", resolutions[i]);
        }

        EditorGUILayout.Space();

//        scale = EditorGUILayout.IntSlider("Scale", scale, 1, 15);

//        EditorGUILayout.HelpBox(
//            "The default mode of screenshot is crop - so choose a proper width and height. The scale is a factor " +
//            "to multiply or enlarge the renders without loosing quality.", MessageType.None);


//        EditorGUILayout.Space();


        GUILayout.Label("Save Path", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(path, GUILayout.ExpandWidth(false));
        if (GUILayout.Button("Browse", GUILayout.ExpandWidth(false)))
        {
            path = EditorUtility.SaveFolderPanel("Path to Save Images", path, Application.dataPath);
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.HelpBox("Choose the folder in which to save the screenshots ", MessageType.None);
        EditorGUILayout.Space();


        //isTransparent = EditorGUILayout.Toggle(isTransparent,"Transparent Background");


        GUILayout.Label("Select Camera", EditorStyles.boldLabel);


        myCamera = EditorGUILayout.ObjectField(myCamera, typeof(Camera), true, null) as Camera;


        if (myCamera == null)
        {
            myCamera = Camera.main;
        }

        isTransparent = EditorGUILayout.Toggle("Transparent Background", isTransparent);


        EditorGUILayout.HelpBox(
            "Choose the camera of which to capture the render. You can make the background transparent using the transparency option.",
            MessageType.None);

        EditorGUILayout.Space();
//        EditorGUILayout.BeginVertical();
//        EditorGUILayout.LabelField("Default Options", EditorStyles.boldLabel);
//
//
//        if (GUILayout.Button("Set To Screen Size")) {
//            resHeight = (int) Handles.GetMainGameViewSize().y;
//            resWidth = (int) Handles.GetMainGameViewSize().x;
//        }
//
//
//        if (GUILayout.Button("Default Size")) {
//            resHeight = 1440;
//            resWidth = 2560;
//            scale = 1;
//        }
//
//
//        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();
//        EditorGUILayout.LabelField(
//            "Screenshot will be taken at " + resWidth * scale + " x " + resHeight * scale + " px",
//            EditorStyles.boldLabel);

        if (GUILayout.Button("Take Screenshot", GUILayout.MinHeight(60)))
        {
            if (path == "")
            {
                path = EditorUtility.SaveFolderPanel("Path to Save Images", path, Application.dataPath);
//                Debug.Log("Path Set");
                TakeHiResShot();
            }
            else
            {
                TakeHiResShot();
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();

//        if (GUILayout.Button("Open Last Screenshot", GUILayout.MaxWidth(160), GUILayout.MinHeight(40))) {
//            if (lastScreenshot != "") {
//                Application.OpenURL("file://" + lastScreenshot);
//                Debug.Log("Opening File " + lastScreenshot);
//            }
//        }

        if (GUILayout.Button("Open Folder", GUILayout.MaxWidth(100), GUILayout.MinHeight(40)))
        {
            Application.OpenURL("file://" + path);
        }

        EditorGUILayout.EndHorizontal();

//        if (!takeHiResShot) {
//            Event e = Event.current;
//            switch (e.type)
//            {
//                case EventType.KeyDown:
//                {
//                    if (Event.current.keyCode == (KeyCode.S))
//                    {
//                        Debug.Log("Take screenshot");
//                        TakeHiResShot();
//                    }
//                    break;
//                }
//            }
//        }

        if (takeHiResShot)
        {
            Debug.Log("take hit -> " + takeHiResShot);
//            for (int i = 0; i < resolutions.Length; i++) {
//                Screen.SetResolution((int)resolutions[i].x, (int)resolutions[i].y, false);
            var sizeIndex = GameViewUtils.FindSize(GameViewSizeGroupType.iOS, (int)resolutions[tickResolutionIndex].x,
                                                   (int)resolutions[tickResolutionIndex].y);
            if (sizeIndex != -1 && prevIndexSize != sizeIndex)
            {
//                int resWidthN = (int)resolutions[tickResolutionIndex].x;
//                int resHeightN = (int)resolutions[tickResolutionIndex].y;

                GameViewUtils.SetSize(sizeIndex);
                prevIndexSize = sizeIndex;
                Debug.Log("size Index -> " + sizeIndex);

//                var pathToFolder = path + "/" + resWidthN + "x" + resHeightN;
////                if (!AssetDatabase.IsValidFolder(path + "/" + resWidthN + "x" + resHeightN)) {
////                    AssetDatabase.CreateFolder(path, resWidthN + "x" + resHeightN);
////                }
//
//                if (!Directory.Exists(pathToFolder)) {
////                    AssetDatabase.CreateFolder(path, resWidthN + "x" + resHeightN);
//                    Directory.CreateDirectory(pathToFolder);
//                }
//
//                RenderTexture rt = new RenderTexture(resWidthN, resHeightN, 24);
//                myCamera.targetTexture = rt;
//
//                TextureFormat tFormat;
//                if (isTransparent)
//                    tFormat = TextureFormat.ARGB32;
//                else
//                    tFormat = TextureFormat.RGB24;
//
//
//                Texture2D screenShot = new Texture2D(resWidthN, resHeightN, tFormat, false);
//                myCamera.Render();
//                RenderTexture.active = rt;
//                screenShot.ReadPixels(new Rect(0, 0, resWidthN, resHeightN), 0, 0);
//                myCamera.targetTexture = null;
//                RenderTexture.active = null;
//                byte[] bytes = screenShot.EncodeToPNG();
//                string filename = ScreenShotName(resWidthN, resHeightN);
//
//                System.IO.File.WriteAllBytes(filename, bytes);
            }
//            }

//			Application.OpenURL(filename);
        }

//        EditorGUILayout.HelpBox(
//            "In case of any error, make sure you have Unity Pro as the plugin requires Unity Pro to work.",
//            MessageType.Info);
    }
예제 #9
0
    /// <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);
                }
            }
        }
    }