Skip to content

Instantly share code, notes, and snippets.

@OhkuboSGMS
Created April 13, 2019 07:10
Show Gist options
  • Save OhkuboSGMS/71aa7a9321b5a2fe5e2166473ca5ef0b to your computer and use it in GitHub Desktop.
Save OhkuboSGMS/71aa7a9321b5a2fe5e2166473ca5ef0b to your computer and use it in GitHub Desktop.
Support Portrait Aspect ration of 1:2 or more Device Change m_MatchWidthOrHeight of CanvasScaler
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public class RatioScale : CanvasScaler
{
// Use this for initialization
void Start()
{
base.Start();
ApplyRation();
}
// private void OnValidate()
// {
// print("OnValidate");
// ApplyRation();
// }
private void ApplyRation()
{
if (uiScaleMode != ScaleMode.ScaleWithScreenSize&& screenMatchMode!=ScreenMatchMode.MatchWidthOrHeight) return;
var size = new Vector2(Screen.width, Screen.height);
// print("Size:" + size);
if (size.x > size.y) return; //横持はNG
if (size.x * 1.8 >= size.y)
{
// print("Set Height");
m_MatchWidthOrHeight = 1;
}
else
{
// print("Set Width");
m_MatchWidthOrHeight = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment