System.Type T = System.Type.GetType ("Unityeditor.gameview,unityeditor"); System.Reflection.MethodInfo Getmaingameview= T.getmethod ("Getmaingameview", System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Static); System.Object Res= Getmaingameview.invoke (NULL,NULL);varGameview =(Unityeditor.editorwindow) Res;varProp = Gameview.gettype (). GetProperty ("currentgameviewsize", System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance);varGvsize = Prop. GetValue (Gameview,New Object[0] { });varGvsizetype =gvsize. GetType ();varDebug_h = (int) Gvsizetype.getproperty ("Height", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance). GetValue (Gvsize,New Object[0] { });varDebug_w = (int) Gvsizetype.getproperty ("width", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance). GetValue (Gvsize,New Object[0] { });
The above code can get the currently selected resolution in the game view, not the using resolution. The value that is taken can be used to dynamically set parameters such as Ngui components (such as Uiscrollview).
[Unity3d] Gets the current selected resolution of the game view by means of reflection