Пример #1
0
        public static void AddAndSetCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType,
                                               int width, int height, string name)
        {
            AddCustomSize(viewSizeType, sizeGroupType, width, height, name);

            SetSize(GetIndexOf(sizeGroupType, width, height));
        }
Пример #2
0
 public GameViewSize(string baseText, GameViewSizeType sizeType, int width, int height)
 {
     m_BaseText = baseText;
     m_SizeType = sizeType;
     m_Width    = width;
     m_Height   = height;
 }
Пример #3
0
 public GameViewSize(GameViewSizeType type, int width, int height, string baseText)
 {
     this.sizeType = type;
     this.width = width;
     this.height = height;
     this.baseText = baseText;
 }
Пример #4
0
    public static void SetAspectRatio(GameViewSizeType gameViewSizeType, int width, int height, string name)
    {
        int _aspectIndex = 0;

        if (!string.IsNullOrEmpty(name))
        {
            _aspectIndex = FindSize(GetCurrentGroupType(), name);
        }

        // Verify if the aspect exists. If the aspect is -1, it means that it doesn't exists
        if (_aspectIndex <= -1)
        {
            object     group         = GetGroup(GetCurrentGroupType());
            MethodInfo addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize");
            var        gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
            var        ctor          = gvsType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });
            var        newSize       = ctor.Invoke(new object[] { (int)gameViewSizeType, width, height, name });
            addCustomSize.Invoke(group, new object[] { newSize });
            return;
        }

        Type         gvWndType             = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
        PropertyInfo selectedSizeIndexProp = gvWndType.GetProperty("selectedSizeIndex", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        EditorWindow gvWnd = EditorWindow.GetWindow(gvWndType);
        MethodInfo   SizeSelectionCallback = gvWndType.GetMethod("SizeSelectionCallback", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

        selectedSizeIndexProp.SetValue(gvWnd, _aspectIndex, null);
        EzSS_Editor.currentAspectName = name;

        // All aspect sizes must be reset to prevent a zoom problem
        for (int i = 0; i < _aspectIndex + 1; i++)
        {
            SizeSelectionCallback.Invoke(gvWnd, new object[] { i, null });
        }
    }
Пример #5
0
 public static bool Contains(GameViewSizeGroupType groupType, GameViewSizeType type, int width, int height, string baseText)
 {
     _gameViewSize = new GameViewSize {
         type = type, width = width, height = height, baseText = baseText
     };
     return(Contains(GetGroup(groupType, instance)));
 }
Пример #6
0
        private void Clamp()
        {
            int width  = this.m_Width;
            int height = this.m_Height;
            int min    = 0;
            GameViewSizeType sizeType = this.sizeType;

            if (sizeType == GameViewSizeType.AspectRatio)
            {
                min = 0;
            }
            else if (sizeType == GameViewSizeType.FixedResolution)
            {
                min = 10;
            }
            else
            {
                Debug.LogError("Unhandled enum!");
            }
            this.m_Width  = Mathf.Clamp(this.m_Width, min, 0x1869f);
            this.m_Height = Mathf.Clamp(this.m_Height, min, 0x1869f);
            if ((this.m_Width != width) || (this.m_Height != height))
            {
                this.Changed();
            }
        }
Пример #7
0
 public CustomGameViewSize(string name, int width, int height, GameViewSizeType type = GameViewSizeType.FixedResolution)
 {
     this.name   = name;
     this.width  = width;
     this.height = height;
     this.type   = type;
 }
Пример #8
0
 public GameViewSize(GameViewSizeType type, int width, int height, string baseText)
 {
     this.sizeType = type;
     this.width    = width;
     this.height   = height;
     this.baseText = baseText;
 }
Пример #9
0
    public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
    {
        // goal:
        // var group = ScriptableSingleton<GameViewSizes>.instance.GetGroup(sizeGroupType);
        // group.AddCustomSize(new GameViewSize(viewSizeType, width, height, text);

        var asm           = typeof(Editor).Assembly;
        var sizesType     = asm.GetType("UnityEditor.GameViewSizes");
        var singleType    = typeof(ScriptableSingleton <>).MakeGenericType(sizesType);
        var instanceProp  = singleType.GetProperty("instance");
        var getGroup      = sizesType.GetMethod("GetGroup");
        var instance      = instanceProp.GetValue(null, null);
        var group         = getGroup.Invoke(instance, new object[] { (int)sizeGroupType });
        var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
        var gvsType       = asm.GetType("UnityEditor.GameViewSize");

        var types = new Type[] { typeof(GameViewSizeType), typeof(int), typeof(int), typeof(string) };
        // in original
        // var types = new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) };
        // throws exception too

        var ctor = gvsType.GetConstructor(types);

        // throws exception here
        var newSize = ctor.Invoke(new object[] { viewSizeType, width, height, text });

        // in original
        // var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });
        // throws exception too

        addCustomSize.Invoke(group, new object[] { newSize });

        sizesType.GetMethod("SaveToHDD").Invoke(gameViewSizesInstance, null);
    }
Пример #10
0
        public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width,
                                         int height, string name)
        {
            if (GetIndexOf(sizeGroupType, width, height) != -1)
            {
                return;
            }

            var group = GetGroup(sizeGroupType);

            var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
            var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");

            var ctor = gvsType.GetConstructor(new[]
            {
                typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType"),
                typeof(int),
                typeof(int),
                typeof(string)
            });

            var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, name });

            addCustomSize.Invoke(group, new[] { newSize });
        }
    public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
    {
        var group         = GetGroup(sizeGroupType);
        var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
        var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");

#if NET_4_6
        var ctor       = gvsType.GetConstructor(new Type[] { typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType"), typeof(int), typeof(int), typeof(string) });
        var newGvsType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType");
        if (viewSizeType == GameViewSizeType.AspectRatio)
        {
            newGvsType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType.AspectRatio");
        }
        else
        {
            newGvsType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType.FixedResolution");
        }

        var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });
        addCustomSize.Invoke(group, new object[] { newSize });
#else
        var ctor    = gvsType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });
        var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });
        addCustomSize.Invoke(group, new object[] { newSize });
#endif
    }
Пример #12
0
        public static Rect GetConstrainedRect(Rect startRect, GameViewSizeGroupType groupType, int gameViewSizeIndex, out bool fitsInsideRect)
        {
            fitsInsideRect = true;
            Rect         rect         = startRect;
            GameViewSize gameViewSize = ScriptableSingleton <GameViewSizes> .instance.GetGroup(groupType).GetGameViewSize(gameViewSizeIndex);

            GameViewSizes.RefreshDerivedGameViewSize(groupType, gameViewSizeIndex, gameViewSize);
            Rect result;

            if (gameViewSize.isFreeAspectRatio)
            {
                result = startRect;
            }
            else
            {
                float            num      = 0f;
                GameViewSizeType sizeType = gameViewSize.sizeType;
                bool             flag;
                if (sizeType != GameViewSizeType.AspectRatio)
                {
                    if (sizeType != GameViewSizeType.FixedResolution)
                    {
                        throw new ArgumentException("Unrecognized size type");
                    }
                    if ((float)gameViewSize.height > startRect.height || (float)gameViewSize.width > startRect.width)
                    {
                        num            = gameViewSize.aspectRatio;
                        flag           = true;
                        fitsInsideRect = false;
                    }
                    else
                    {
                        rect.height = (float)gameViewSize.height;
                        rect.width  = (float)gameViewSize.width;
                        flag        = false;
                    }
                }
                else
                {
                    num  = gameViewSize.aspectRatio;
                    flag = true;
                }
                if (flag)
                {
                    rect.height = ((rect.width / num <= startRect.height) ? (rect.width / num) : startRect.height);
                    rect.width  = rect.height * num;
                }
                rect.height = Mathf.Clamp(rect.height, 0f, startRect.height);
                rect.width  = Mathf.Clamp(rect.width, 0f, startRect.width);
                rect.y      = startRect.height * 0.5f - rect.height * 0.5f + startRect.y;
                rect.x      = startRect.width * 0.5f - rect.width * 0.5f + startRect.x;
                rect.width  = Mathf.Floor(rect.width + 0.5f);
                rect.height = Mathf.Floor(rect.height + 0.5f);
                rect.x      = Mathf.Floor(rect.x + 0.5f);
                rect.y      = Mathf.Floor(rect.y + 0.5f);
                result      = rect;
            }
            return(result);
        }
Пример #13
0
        private static void AddResolution(GameViewSizeType sizeType, int width, int height, string name)
        {
            var index = FindSize(name);

            if (index == -1)
            {
                AddCustomSize(sizeType, GameViewSizeGroupType.Standalone, width, height, name);
            }
        }
Пример #14
0
        public static Rect GetConstrainedRect(Rect startRect, GameViewSizeGroupType groupType, int gameViewSizeIndex, out bool fitsInsideRect)
        {
            bool flag;

            fitsInsideRect = true;
            Rect         rect         = startRect;
            GameViewSize gameViewSize = ScriptableSingleton <GameViewSizes> .instance.GetGroup(groupType).GetGameViewSize(gameViewSizeIndex);

            RefreshDerivedGameViewSize(groupType, gameViewSizeIndex, gameViewSize);
            if (gameViewSize.isFreeAspectRatio)
            {
                return(startRect);
            }
            float            aspectRatio = 0f;
            GameViewSizeType sizeType    = gameViewSize.sizeType;

            if (sizeType != GameViewSizeType.AspectRatio)
            {
                if (sizeType != GameViewSizeType.FixedResolution)
                {
                    throw new ArgumentException("Unrecognized size type");
                }
            }
            else
            {
                aspectRatio = gameViewSize.aspectRatio;
                flag        = true;
                goto Label_00D3;
            }
            if ((gameViewSize.height > startRect.height) || (gameViewSize.width > startRect.width))
            {
                aspectRatio    = gameViewSize.aspectRatio;
                flag           = true;
                fitsInsideRect = false;
            }
            else
            {
                rect.height = gameViewSize.height;
                rect.width  = gameViewSize.width;
                flag        = false;
            }
Label_00D3:
            if (flag)
            {
                rect.height = ((rect.width / aspectRatio) <= startRect.height) ? (rect.width / aspectRatio) : startRect.height;
                rect.width  = rect.height * aspectRatio;
            }
            rect.height = Mathf.Clamp(rect.height, 0f, startRect.height);
            rect.width  = Mathf.Clamp(rect.width, 0f, startRect.width);
            rect.y      = ((startRect.height * 0.5f) - (rect.height * 0.5f)) + startRect.y;
            rect.x      = ((startRect.width * 0.5f) - (rect.width * 0.5f)) + startRect.x;
            rect.width  = Mathf.Floor(rect.width + 0.5f);
            rect.height = Mathf.Floor(rect.height + 0.5f);
            rect.x      = Mathf.Floor(rect.x + 0.5f);
            rect.y      = Mathf.Floor(rect.y + 0.5f);
            return(rect);
        }
Пример #15
0
        public static Vector2 GetRenderTargetSize(Rect startRect, GameViewSizeGroupType groupType, int gameViewSizeIndex)
        {
            GameViewSize gameViewSize = ScriptableSingleton <GameViewSizes> .instance.GetGroup(groupType).GetGameViewSize(gameViewSizeIndex);

            GameViewSizes.RefreshDerivedGameViewSize(groupType, gameViewSizeIndex, gameViewSize);
            Vector2 vector;

            if (gameViewSize.isFreeAspectRatio)
            {
                vector = startRect.size;
            }
            else
            {
                GameViewSizeType sizeType = gameViewSize.sizeType;
                if (sizeType != GameViewSizeType.AspectRatio)
                {
                    if (sizeType != GameViewSizeType.FixedResolution)
                    {
                        throw new ArgumentException("Unrecognized size type");
                    }
                    vector = new Vector2((float)gameViewSize.width, (float)gameViewSize.height);
                }
                else if (startRect.height == 0f || gameViewSize.aspectRatio == 0f)
                {
                    vector = Vector2.zero;
                }
                else
                {
                    float num = startRect.width / startRect.height;
                    if (num < gameViewSize.aspectRatio)
                    {
                        vector = new Vector2(startRect.width, startRect.width / gameViewSize.aspectRatio);
                    }
                    else
                    {
                        vector = new Vector2(startRect.height * gameViewSize.aspectRatio, startRect.height);
                    }
                }
            }
            int maxTextureSize = SystemInfo.maxTextureSize;
            int a    = (int)Math.Sqrt((double)SystemInfo.graphicsMemorySize * 0.2 / 12.0 * 1024.0 * 1024.0);
            int b    = 8192;
            int num2 = Mathf.Min(maxTextureSize, Mathf.Min(a, b));

            if (vector.x > (float)num2 || vector.y > (float)num2)
            {
                if (vector.x > vector.y)
                {
                    vector *= (float)num2 / vector.x;
                }
                else
                {
                    vector *= (float)num2 / vector.y;
                }
            }
            return(vector);
        }
Пример #16
0
        private static bool GameViewSize_Equals(GameViewSize a, object b)
        {
            int              b_width    = (int)GetGameSizeProperty(b, "width");
            int              b_height   = (int)GetGameSizeProperty(b, "height");
            string           b_baseText = (string)GetGameSizeProperty(b, "baseText");
            GameViewSizeType b_sizeType = (GameViewSizeType)Enum.Parse(typeof(GameViewSizeType), GetGameSizeProperty(b, "sizeType").ToString());

            return(a.type == b_sizeType && a.width == b_width && a.height == b_height && a.baseText == b_baseText);
        }
Пример #17
0
 public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
 {
     var group = GetGroup(sizeGroupType);
     var addCustomSize = _getGroup.ReturnType.GetMethod("AddCustomSize");
     var gameViewSizeType = typeof (Editor).Assembly.GetType("UnityEditor.GameViewSize");
     var ctor = gameViewSizeType.GetConstructor(new Type[] {typeof (int), typeof (int), typeof (int), typeof (string)});
     var newSize = ctor.Invoke(new object[] {(int) viewSizeType, width, height, text});
     addCustomSize.Invoke(group, new object[] {newSize});
 }
Пример #18
0
        public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
        {
            var group            = GetGroup(sizeGroupType);
            var addCustomSize    = _getGroup.ReturnType.GetMethod("AddCustomSize");
            var gameViewSizeType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
            var ctor             = gameViewSizeType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });
            var newSize          = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

            addCustomSize.Invoke(group, new object[] { newSize });
        }
Пример #19
0
        public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
        {
            var             group            = GetGroup(sizeGroupType);
            var             addCustomSize    = _getGroup.ReturnType.GetMethod("AddCustomSize");
            var             gameViewSizeType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
            var             ctors            = new List <ConstructorInfo>(gameViewSizeType.GetConstructors());
            ConstructorInfo ctor             = ctors.Find(a => a.GetParameters().Length == 4);
            var             newSize          = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

            addCustomSize.Invoke(group, new object[] { newSize });
        }
Пример #20
0
        private static GameViewSize Convert(object instance)
        {
            int              width    = (int)GetGameSizeProperty(instance, "width");
            int              height   = (int)GetGameSizeProperty(instance, "height");
            string           baseText = (string)GetGameSizeProperty(instance, "baseText");
            GameViewSizeType type     = (GameViewSizeType)Enum.Parse(typeof(GameViewSizeType), GetGameSizeProperty(instance, "sizeType").ToString());

            return(new GameViewSize {
                type = type, width = width, height = height, baseText = baseText
            });
        }
Пример #21
0
    public static void AddCustomViewSize(GameViewSizeGroupType sizeGroupType, GameViewSizeType viewSizeType, int width, int height, string name)
    {
        // GameViewSizes group = gameViewSizesInstance.GetGroup(sizeGroupTyge);
        // group.AddCustomSize(new GameViewSize(viewSizeType, width, height, text);

        var group         = GetGroup(sizeGroupType);
        var addCustomSize = getGroupMethodInfo.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
        var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
        var ctor          = gvsType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });
        var newSize       = ctor.Invoke(new object[] { (int)viewSizeType, width, height, name });

        addCustomSize.Invoke(group, new object[] { newSize });
    }
Пример #22
0
        public static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
        {
            var asm           = typeof(UnityEditor.Editor).Assembly;
            var sizesType     = asm.GetType("UnityEditor.GameViewSizes");
            var singleType    = typeof(ScriptableSingleton <>).MakeGenericType(sizesType);
            var instanceProp  = singleType.GetProperty("instance");
            var getGroup      = sizesType.GetMethod("GetGroup");
            var instance      = instanceProp.GetValue(null, null);
            var group         = getGroup.Invoke(instance, new object[] { (int)sizeGroupType });
            var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
            var gvsType       = asm.GetType("UnityEditor.GameViewSize");
            var ctor          = gvsType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });
            var newSize       = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

            addCustomSize.Invoke(group, new object[] { newSize });
        }
Пример #23
0
        /// <summary>
        /// Adds a game view size.
        /// </summary>
        /// <param name="viewSizeType">Aspect ratio or fixed resolution</param>
        /// <param name="sizeGroupType">Build target</param>
        /// <param name="width">Width of game view resolution</param>
        /// <param name="height">Height of game view resolution</param>
        /// <param name="text">Label of game view resolution</param>
        private static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
        {
            var  group            = GetGroup(sizeGroupType);
            var  addCustomSize    = getGroup.ReturnType.GetMethod("AddCustomSize");
            Type gameViewSizeType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameViewSize");

            object[] gameViewSizeConstructorArgs = new object[] { (int)viewSizeType, width, height, text };

            // select a constructor which has 4 elements which are enums/ints/strings
            ConstructorInfo gameViewSizeConstructor = gameViewSizeType.GetConstructors()
                                                      .FirstOrDefault(x =>
            {
                // lambda function defines a filter/predicate of ConstructorInfo objects.
                // The first constructor, if any exists, which satisfies the predicate (true) will be returned
                if (x.GetParameters().Length != gameViewSizeConstructorArgs.Length)
                {
                    return(false);
                }

                // iterate through constructor types + constructor args. If any mismatch, reject
                for (int i = 0; i < gameViewSizeConstructorArgs.Length; i++)
                {
                    Type constructorParamType = x.GetParameters()[i].ParameterType;
                    Type constructorArgType   = gameViewSizeConstructorArgs[i].GetType();

                    bool isMatch = constructorParamType == constructorArgType || constructorParamType.IsEnum && constructorArgType == typeof(int);
                    if (!isMatch)
                    {
                        return(false);
                    }
                }

                // constructor with these params must be able to receive these args
                return(true);
            });

            if (gameViewSizeConstructor != null)
            {
                var newSize = gameViewSizeConstructor.Invoke(gameViewSizeConstructorArgs);
                addCustomSize.Invoke(group, new object[] { newSize });
            }

            sizesType.GetMethod("SaveToHDD").Invoke(gameViewSizesInstance, null);
        }
Пример #24
0
            public static void AddCustomSize(
                GameViewSizeType viewSizeType,
                GameViewSizeGroupType sizeGroupType,
                int width,
                int height,
                string text)
            {
                var group         = GetGroup(sizeGroupType);
                var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize");
                var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");

                // When setting Player Setting > Scripting Runtime Version to .NET 4.x, the runtime
                // environment doens't seem to like how we used to grab the constructor by types.
                // Instead, just grab the first contrsuctor, which is equivalent to the one we wanted.
                var ctor    = gvsType.GetConstructors()[0];
                var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

                addCustomSize.Invoke(group, new object[] { newSize });
            }
Пример #25
0
        private static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
        {
            var group         = GetGroup(sizeGroupType);
            var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
            var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
            var ctor          = gvsType.GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(string) });

            foreach (var c in gvsType.GetConstructors())
            {
                if (ctor == null && c.GetParameters().Length == 4)
                {
                    ctor = c;
                    break;
                }
            }
            var newSize = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

            addCustomSize.Invoke(group, new object[] { newSize });
        }
Пример #26
0
    public static int AddOrGetCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width, int height, string text)
    {
        int id = FindSize(sizeGroupType, width, height);

        if (id != -1)
        {
            return(id);
        }

        var group         = GetGroup(sizeGroupType);
        var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
        var gvsType       = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
        var enumType      = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType");
        var ctor          = gvsType.GetConstructor(new Type[] { enumType, typeof(int), typeof(int), typeof(string) });
        var newSize       = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

        addCustomSize.Invoke(group, new object[] { newSize });

        return(FindSize(sizeGroupType, width, height));
    }
Пример #27
0
        private static void AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width,
                                          int height, string text)
        {
            var type = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType");

            var group            = GetGroup(sizeGroupType);
            var addCustomSize    = GetGroupMethod.ReturnType.GetMethod("AddCustomSize");
            var gameViewSizeType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");

            var constructor = gameViewSizeType.GetConstructor(new[] { type, typeof(int), typeof(int), typeof(string) });

            if (constructor == null)
            {
                return;
            }
            var newSize = constructor.Invoke(new object[] { (int)viewSizeType, width, height, text });

            if (addCustomSize != null)
            {
                addCustomSize.Invoke(group, new[] { newSize });
            }
        }
Пример #28
0
        public static int FindSizeByValue(GameViewSizeType viewType, int width, int height)
        {
            // GameViewSizes group = gameViewSizesInstance.GetGroup(sizeGroupType);
            // string[] texts = group.GetDisplayTexts();
            // for loop...
            string text = width + (viewType.Equals(GameViewSizeType.AspectRatio) ? ":" : "x") + height;

            GetViewSizeGroup();
            var group           = GetGroup(gvsgt);
            var getDisplayTexts = group.GetType().GetMethod("GetDisplayTexts");
            var displayTexts    = getDisplayTexts.Invoke(group, null) as string[];

            for (int i = 0; i < displayTexts.Length; i++)
            {
                string display = displayTexts[i];
                string aspct   = "";
                // the text we get is "Name (W:H)" if the size has a name, or just "W:H" e.g. 16:9
                // so if we're querying a custom size text we substring to only get the name
                // You could see the outputs by just logging
                // Debug.Log(display);
                int pren = display.LastIndexOf('(');
                int x    = display.Length - pren + 1;
                if (pren != -1)
                {
                    aspct = display.Substring(pren + 1);
                    pren  = aspct.IndexOf(')');
                    if (pren != -1)
                    {
                        aspct = aspct.Substring(0, pren);
                    }
                }
                //MyDebug.Log("{0} - {1} - {2} - {3}", display, pren, text, aspct);
                if (aspct == text)
                {
                    return(i);
                }
            }
            return(-1);
        }
Пример #29
0
    /*[MenuItem("Test/AddSize")]
     * public static void AddTestSize()
     * {
     *  AddCustomSize(GameViewSizeType.AspectRatio, GameViewSizeGroupType.Standalone, 123, 456, "Test size");
     * }
     */

    public static int AddCustomSize(GameViewSizeType viewSizeType, GameViewSizeGroupType sizeGroupType, int width,
                                    int height, string text)
    {
        // goal:
        // var group = ScriptableSingleton<GameViewSizes>.instance.GetGroup(sizeGroupType);
        // group.AddCustomSize(new GameViewSize(viewSizeType, width, height, text);
        var asm           = typeof(Editor).Assembly;
        var sizesType     = asm.GetType("UnityEditor.GameViewSizes");
        var singleType    = typeof(ScriptableSingleton <>).MakeGenericType(sizesType);
        var instanceProp  = singleType.GetProperty("instance");
        var getGroup      = sizesType.GetMethod("GetGroup");
        var instance      = instanceProp.GetValue(null, null);
        var group         = getGroup.Invoke(instance, new object[] { (int)sizeGroupType });
        var addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize"); // or group.GetType().
        var gvsType       = asm.GetType("UnityEditor.GameViewSize");
        var ctor          = gvsType.GetConstructor(new[] { typeof(int), typeof(int), typeof(int), typeof(string) });
        var newSize       = ctor.Invoke(new object[] { (int)viewSizeType, width, height, text });

        //Remove any old versions of the custom view size
        if (SizeExists(sizeGroupType, text))
        {
            var index            = FindSize(sizeGroupType, text, true);
            var removeCustomSize = getGroup.ReturnType.GetMethod("RemoveCustomSize");
            removeCustomSize.Invoke(group, new object[] { index });
        }
        //TODO: before adding, maybe check if it exists already, and then override it!


        addCustomSize.Invoke(group, new object[] { newSize });

        var groupType       = group.GetType();
        var getBuiltinCount = groupType.GetMethod("GetBuiltinCount");
        var getCustomCount  = groupType.GetMethod("GetCustomCount");
        int sizesCount      = (int)getBuiltinCount.Invoke(group, null) + (int)getCustomCount.Invoke(group, null);

        //we return the last index, because that's where our new custom size ends up.
        return(sizesCount);
    }
Пример #30
0
        public static Vector2 GetRenderTargetSize(Rect startRect, GameViewSizeGroupType groupType, int gameViewSizeIndex, out bool clamped)
        {
            GameViewSize gameViewSize = ScriptableSingleton <GameViewSizes> .instance.GetGroup(groupType).GetGameViewSize(gameViewSizeIndex);

            GameViewSizes.RefreshDerivedGameViewSize(groupType, gameViewSizeIndex, gameViewSize);
            clamped = false;
            Vector2 vector;

            if (gameViewSize.isFreeAspectRatio)
            {
                vector = startRect.size;
            }
            else
            {
                GameViewSizeType sizeType = gameViewSize.sizeType;
                if (sizeType != GameViewSizeType.AspectRatio)
                {
                    if (sizeType != GameViewSizeType.FixedResolution)
                    {
                        throw new ArgumentException("Unrecognized size type");
                    }
                    vector = new Vector2((float)gameViewSize.width, (float)gameViewSize.height);
                }
                else if (startRect.height == 0f || gameViewSize.aspectRatio == 0f)
                {
                    vector = Vector2.zero;
                }
                else
                {
                    float num = startRect.width / startRect.height;
                    if (num < gameViewSize.aspectRatio)
                    {
                        vector = new Vector2(startRect.width, startRect.width / gameViewSize.aspectRatio);
                    }
                    else
                    {
                        vector = new Vector2(startRect.height * gameViewSize.aspectRatio, startRect.height);
                    }
                }
            }
            float num2 = (float)SystemInfo.graphicsMemorySize * 0.2f / 12f * 1024f * 1024f;
            float num3 = vector.x * vector.y;

            if (num3 > num2)
            {
                float num4 = vector.y / vector.x;
                vector.x = Mathf.Sqrt(num2 * num4);
                vector.y = num4 * vector.x;
                clamped  = true;
            }
            float b    = 8192f;
            float num5 = Mathf.Min((float)SystemInfo.maxRenderTextureSize, b);

            if (vector.x > num5 || vector.y > num5)
            {
                if (vector.x > vector.y)
                {
                    vector *= num5 / vector.x;
                }
                else
                {
                    vector *= num5 / vector.y;
                }
                clamped = true;
            }
            return(vector);
        }
Пример #31
0
 public static void AddCustomSize(GameViewSizeGroupType groupType, GameViewSizeType type, int width, int height, string baseText)
 {
     AddCustomSize(groupType, new GameViewSize {
         type = type, width = width, height = height, baseText = baseText
     });
 }
Пример #32
0
 public static bool SizeExistsByValue(GameViewSizeType viewType, int width, int height)
 {
     return(FindSizeByValue(viewType, width, height) != -1);
 }