protected virtual void Handle() { if (!(this.m_Canvas == null) && this.m_Canvas.isRootCanvas) { if (this.m_Canvas.renderMode == RenderMode.WorldSpace) { this.HandleWorldCanvas(); } else { CanvasScaler.ScaleMode uiScaleMode = this.m_UiScaleMode; if (uiScaleMode != CanvasScaler.ScaleMode.ConstantPixelSize) { if (uiScaleMode != CanvasScaler.ScaleMode.ScaleWithScreenSize) { if (uiScaleMode == CanvasScaler.ScaleMode.ConstantPhysicalSize) { this.HandleConstantPhysicalSize(); } } else { this.HandleScaleWithScreenSize(); } } else { this.HandleConstantPixelSize(); } } } }
public CanvasScalerSerializable(CanvasScaler scaler) : base(scaler) { uiScaleMode = scaler.uiScaleMode; referenceResolution = scaler.referenceResolution; screenMatchMode = scaler.screenMatchMode; matchWidthOrHeight = scaler.matchWidthOrHeight; defaultSpriteDPI = scaler.defaultSpriteDPI; fallbackScreenDPI = scaler.fallbackScreenDPI; referencePixelsPerUnit = scaler.referencePixelsPerUnit; dynamicPixelsPerUnit = scaler.dynamicPixelsPerUnit; physicalUnit = scaler.physicalUnit; scaleFactor = scaler.scaleFactor; }
public CanvasScalerSpec( CanvasScaler.ScaleMode scaleMode = CanvasScaler.ScaleMode.ConstantPhysicalSize, Vector2?referenceResolution = null, CanvasScaler.ScreenMatchMode screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight, float matchWidthOrHeight = 0f, float referencePixelsPerUnit = 100f) { ScaleMode = scaleMode; ReferenceResolution = referenceResolution.GetValueOrDefault(new Vector2(x: 1920, y: 1080)); ScreenMatchMode = screenMatchMode; MatchWidthOrHeight = matchWidthOrHeight; ReferencePixelsPerUnit = referencePixelsPerUnit; }
void setResolution(string txt) { print(txt); if (txt.Contains("×")) { string[] resolutionArray = txt.Split(new string[] { " × " }, StringSplitOptions.RemoveEmptyEntries); print(resolutionArray); Screen.SetResolution(Convert.ToInt32(resolutionArray[0]), Convert.ToInt32(resolutionArray[1]), false); } else { Screen.SetResolution(Screen.width, Screen.height, true); } if (Screen.height < 550 || (Screen.dpi >= 200 && !Input.mousePresent)) { scaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; GameObject.FindGameObjectWithTag("Main Canvas").GetComponent <CanvasScaler>().uiScaleMode = scaleMode; } }
void Awake() { print(Application.persistentDataPath); settings = Settings.Load(Application.persistentDataPath); print(settings); settings_backup = settings; saveButton.onClick.AddListener(delegate { settings.Save(Application.persistentDataPath); print(settings); }); fullScreenToggle.onValueChanged.AddListener(delegate { settings.fullScreen = fullScreenToggle.isOn; setFullscreen(settings.fullScreen); resolutionDropdown.interactable = !settings.fullScreen; print(settings); }); resolutionDropdown.onValueChanged.AddListener(delegate { settings.resolution = resolutionDropdown.value; setResolution(resolutions[settings.resolution]); print(settings); }); qualityDropdown.onValueChanged.AddListener(delegate { settings.quality = qualityDropdown.value; QualitySettings.SetQualityLevel(settings.quality); print(settings); }); resolutions = Dropdown2dict(resolutionDropdown); fullScreenToggle.isOn = settings.fullScreen; resolutionDropdown.value = settings.resolution; qualityDropdown.value = settings.quality; resolutionDropdown.RefreshShownValue(); qualityDropdown.RefreshShownValue(); QualitySettings.SetQualityLevel(settings.quality); setFullscreen(settings.fullScreen); if (!settings.fullScreen) { //setResolution(resolutions[settings.resolution]); } else { resolutionDropdown.interactable = false; } if (Screen.height < 550 || (Screen.dpi >= 200 && !Input.mousePresent)) { scaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; GameObject.FindGameObjectWithTag("Main Canvas").GetComponent <CanvasScaler>().uiScaleMode = scaleMode; } SceneManager.sceneLoaded += delegate { GameObject.FindGameObjectWithTag("Main Canvas").GetComponent <CanvasScaler>().uiScaleMode = scaleMode; }; SmartMath.Fraction aspectRatio = new SmartMath.Fraction(Screen.height, Screen.width); Debug.LogFormat("Resolution= {0} x {1} , DPI= {2} , Size= {3} cm x {4} cm , Aspect Ratio= {5} : {6}", Screen.width, Screen.height, Screen.dpi, SmartMath.Converting.Length.InchToCm(Screen.width / Screen.dpi).ToString("0.0"), SmartMath.Converting.Length.InchToCm(Screen.height / Screen.dpi).ToString("0.0"), aspectRatio.Denominator, aspectRatio.Numerator ); }