Created
August 28, 2019 08:25
-
-
Save 20chan/ea302f501f96c717e98b921dbe8bb77d to your computer and use it in GitHub Desktop.
unity set game view window scale to min when played
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Reflection; | |
| using UnityEngine; | |
| namespace Common { | |
| public class GameViewAutoScaler : MonoBehaviour { | |
| #if UNITY_EDITOR | |
| private void Awake() { | |
| SetGameViewScaleMin(); | |
| } | |
| public static void SetGameViewScaleMin() { | |
| var assembly = typeof(UnityEditor.EditorWindow).Assembly; | |
| var ty = assembly.GetType("UnityEditor.GameView"); | |
| var v = UnityEditor.EditorWindow.GetWindow(ty); | |
| var priv = BindingFlags.Instance | BindingFlags.NonPublic; | |
| // var defaultScale = ty.GetField("m_defaultScale", priv); | |
| var areaField = ty.GetField("m_ZoomArea", priv); | |
| var area = areaField.GetValue(v); | |
| var scale = area.GetType().GetField("m_Scale", priv); | |
| scale.SetValue(area, new Vector2(0.01f, 0.01f)); | |
| } | |
| #endif | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment