[Unity3d] Gets the current selected resolution of the game view by means of reflection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.