static GameViewSizeInitializer()
 {
     if (!GameViewSizeHelper.Contains(groupType, gameViewSizeType, width, height, text))
     {
         GameViewSizeHelper.AddCustomSize(groupType, gameViewSizeType, width, height, text);
     }
 }
Beispiel #2
0
        protected void ResizeImple()
        {
            var groupType    = GameViewSizeHelper.GetCurrentGameViewSizeGroupType();
            var gameViewSize = new GameViewSizeHelper.GameViewSize();

            gameViewSize.type     = GameViewSizeHelper.GameViewSizeType.FixedResolution;
            gameViewSize.width    = Window.Orientation == Orientation.Portrait ? Width : Height;
            gameViewSize.height   = Window.Orientation == Orientation.Portrait ? Height : Width;
            gameViewSize.baseText = Label;

            if (!GameViewSizeHelper.Contains(groupType, gameViewSize))
            {
                GameViewSizeHelper.AddCustomSize(groupType, gameViewSize);
            }

            GameViewSizeHelper.ChangeGameViewSize(groupType, gameViewSize);
            Save.Set <string>(GameViewSizeChanger.Key_GameViewSizeChanger_LastLabel, Label);

            // HACK: 2フレーム待たないとSnapZoomが動作しないケースがある
            EditorApplication.delayCall += () =>
            {
                EditorApplication.delayCall += () =>
                {
                    var   flag             = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
                    var   assembly         = typeof(Editor).Assembly;
                    var   type             = assembly.GetType("UnityEditor.GameView");
                    var   gameView         = EditorWindow.GetWindow(type, false, "Game", false);
                    var   minScaleProperty = type.GetProperty("minScale", flag);
                    float minScale         = (float)minScaleProperty.GetValue(gameView, null);
                    type.GetMethod("SnapZoom", flag, null, new System.Type[] { typeof(float) }, null).Invoke(gameView, new object[] { minScale });
                    gameView.Repaint();
                    Window.Focus();
                };
            };
        }
        static IEnumerator CaptureScreenshot(int number)
        {
            string directoryName = "screenshots";

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            var editorWindowAssembly = typeof(EditorWindow).Assembly;
            var currentSizeGroupType = GetCurrentSizeGroupType(editorWindowAssembly);
            var gameViewType         = editorWindowAssembly.GetType("UnityEditor.GameView");
            var gameViewWindow       = EditorWindow.GetWindow(gameViewType);

            foreach (var customSize in _customSizes)
            {
                if (!GameViewSizeHelper.Contains(currentSizeGroupType, customSize))
                {
                    GameViewSizeHelper.AddCustomSize(currentSizeGroupType, customSize);
                }

                GameViewSizeHelper.ChangeGameViewSize(currentSizeGroupType, customSize);
                var filename = Path.Combine(directoryName, $"{customSize.baseText}_{number}.png");
                EditorApplication.Step();
                EditorApplication.Step();
                ScreenCapture.CaptureScreenshot(filename);
                gameViewWindow.Repaint();
                Debug.Log($">> ScreenshotForAppStore : save to {filename}");
                yield return(null);
            }
        }
Beispiel #4
0
        void ApplyImpl()
        {
            var gameViewSize = Convert();
            var groupType    = GetCurrentGroupType();

            if (!GameViewSizeHelper.Contains(groupType, gameViewSize))
            {
                GameViewSizeHelper.AddCustomSize(groupType, gameViewSize);
            }
            GameViewSizeHelper.ChangeGameViewSize(groupType, gameViewSize);
        }
Beispiel #5
0
 private static void AddResolution(GameViewSizeGroupType target, string baseText, int width, int height)
 {
     GameViewSizeHelper.AddCustomSize(
         target,
         new GameViewSizeHelper.GameViewSize {
         baseText = baseText,
         type     = GameViewSizeHelper.GameViewSizeType.FixedResolution,
         width    = width,
         height   = height
     }
         );
 }
Beispiel #6
0
        static IEnumerator CaptureScreenshot(int number)
        {
            string directoryName = "screenshots";

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            var assembly  = typeof(EditorWindow).Assembly;
            var groupType = currentSizeGroupType(assembly);
            var type      = assembly.GetType("UnityEditor.GameView");
            var gameview  = EditorWindow.GetWindow(type);

            GameViewSize[] customSizes =
            {
                new GameViewSize(1242, 2688, "6.5"),
                new GameViewSize(1242, 2208, "5.5"),
                new GameViewSize(2048, 2732, "12.9"),
            };

            for (int i = 0; i < customSizes.Length; i++)
            {
                var customSize = customSizes[i];
                if (!GameViewSizeHelper.Contains(groupType, customSize))
                {
                    GameViewSizeHelper.AddCustomSize(groupType, customSize);
                }
                GameViewSizeHelper.ChangeGameViewSize(groupType, customSize);
                var filename = $"{directoryName}/{customSize.baseText}_{number}.png";
                EditorApplication.Step();
                EditorApplication.Step();
                ScreenCapture.CaptureScreenshot(filename);
                gameview.Repaint();
                Debug.Log(">> CaptureScreenshotsForAppStore : save to " + filename);
                //GameViewSizeHelper.RemoveCustomSize(groupType, customSize);
                yield return(null);
            }
        }
Beispiel #7
0
    static void Init()
    {
        var wide = new GameViewSizeHelper.GameViewSize
        {
            type     = GameViewSizeHelper.GameViewSizeType.FixedResolution,
            width    = 2436,
            height   = 1125,
            baseText = "iPhone X/XS Landscape"
        };
        var tall = new GameViewSizeHelper.GameViewSize
        {
            type     = GameViewSizeHelper.GameViewSizeType.FixedResolution,
            width    = 1125,
            height   = 2436,
            baseText = "iPhone X/XS Portrait"
        };

        GameViewSizeHelper.AddCustomSize(GameViewSizeGroupType.Standalone, wide);
        GameViewSizeHelper.AddCustomSize(GameViewSizeGroupType.Standalone, tall);
        GameViewSizeHelper.AddCustomSize(GameViewSizeGroupType.Android, wide);
        GameViewSizeHelper.AddCustomSize(GameViewSizeGroupType.Android, tall);
    }
        void OnGUI()
        {
            var removeTargets = new List <GameViewSizeHelper.GameViewSize>();
            var addTargets    = new List <GameViewSizeHelper.GameViewSize>();

            selectedTab = (GameViewSizeGroupType)GUILayout.Toolbar((int)selectedTab, tabNames);
            var presets     = GameViewSizePreset.GetPresets(selectedTab);
            var customSizes = gameViewSizeMap[selectedTab];

            using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = scroll.scrollPosition;
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("■■■REGISTERED■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                if (customSizes.Length == 0)
                {
                    EditorGUILayout.LabelField("Nothing registered custom GameViewSize");
                }
                foreach (var gameViewSize in customSizes)
                {
                    using (new EditorGUILayout.VerticalScope("ShurikenModuleTitle"))
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(55)))
                            {
                                removeTargets.Add(gameViewSize);
                            }
                            if (GUILayout.Button(gameViewSize.baseText, EditorStyles.label, GUILayout.Width(300)))
                            {
                                GameViewSizeHelper.ChangeGameViewSize(selectedTab, gameViewSize);
                            }
                            // EditorGUILayout.LabelField(gameViewSize.baseText);
                            EditorGUILayout.LabelField(string.Format("{0} × {1}", gameViewSize.width, gameViewSize.height));
                        }
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField("■■■PRESET■■■■■■■■■■■■■■■■■■■■■■■■", EditorStyles.boldLabel);
                    if (GUILayout.Button("Add all preset", GUILayout.Width(140)))
                    {
                        addTargets.AddRange(presets);
                    }
                    if (GUILayout.Button("Remove all preset", GUILayout.Width(140)))
                    {
                        removeTargets.AddRange(presets);
                    }
                }
                EditorGUILayout.Space();
                if (presets.Length == 0)
                {
                    EditorGUILayout.LabelField("Nothing preset GameViewSize. Please request https://github.com/Syy12345-Unity/GameViewSizeController");
                }
                foreach (var gameViewSize in presets)
                {
                    bool contains = customSizes.Any(data => GameViewSizeEqual(data, gameViewSize));
                    using (new EditorGUILayout.VerticalScope("ShurikenModuleTitle"))
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            if (contains)
                            {
                                if (GUILayout.Button("", EditorStyles.label, GUILayout.Width(55)))
                                {
                                }
                            }
                            else
                            {
                                if (GUILayout.Button("Add", EditorStyles.miniButton, GUILayout.Width(55)))
                                {
                                    addTargets.Add(gameViewSize);
                                }
                            }
                            EditorGUILayout.LabelField(gameViewSize.baseText, GUILayout.Width(300));
                            EditorGUILayout.LabelField(string.Format("{0} × {1}", gameViewSize.width, gameViewSize.height));
                        }
                    }
                }

                if (removeTargets.Count != 0)
                {
                    var list = customSizes.ToList();
                    foreach (var target in removeTargets)
                    {
                        GameViewSizeHelper.RemoveCustomSize(selectedTab, target);
                        var findObj = list.FirstOrDefault(data => GameViewSizeEqual(data, target));
                        if (findObj != null)
                        {
                            list.Remove(findObj);
                        }
                    }
                    gameViewSizeMap[selectedTab] = list.ToArray();
                }

                if (addTargets.Count != 0)
                {
                    var list = customSizes.ToList();
                    foreach (var target in addTargets)
                    {
                        var findObj = list.FirstOrDefault(data => GameViewSizeEqual(data, target));
                        if (findObj == null)
                        {
                            GameViewSizeHelper.AddCustomSize(selectedTab, target);
                            list.Add(target);
                        }
                    }
                    gameViewSizeMap[selectedTab] = list.ToArray();
                }
                EditorGUILayout.Space();
            }
            EditorGUILayout.Space();
        }
 private static void AddGameViewSize(int width, int height, string name)
 {
     GameViewSizeHelper.AddCustomSize(GameViewSizeGroupType.Standalone, GameViewSizeHelper.GameViewSizeType.FixedResolution, width, height, name);
 }