Skip to content

Instantly share code, notes, and snippets.

@20chan
Created August 28, 2019 08:25
Show Gist options
  • Select an option

  • Save 20chan/ea302f501f96c717e98b921dbe8bb77d to your computer and use it in GitHub Desktop.

Select an option

Save 20chan/ea302f501f96c717e98b921dbe8bb77d to your computer and use it in GitHub Desktop.
unity set game view window scale to min when played
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