CustomAppScaling.cs 1.54 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CustomAppScaling : MonoBehaviour {

    private Rect rect;

    void Awake () {
        rect = GetComponent<RectTransform>().rect;
        if (rect.width == 4098 && rect.height == 1536)
        {
            //Globacore foyer touch wall testing
            GetComponent<CanvasScaler>().scaleFactor = (rect.height / (1080f * 4)) * 2;
            GameObject orbbec = GameObject.Find("Orbbec Sensors");
            if (orbbec)
                orbbec.SetActive(false);
        }
        else
        {
            GetComponent<CanvasScaler>().scaleFactor = Mathf.Min(rect.width / (1920f * 4), rect.height / (1080f * 4));
        }
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            GetComponent<CanvasScaler>().scaleFactor = Mathf.Min(rect.width / 1920f, rect.height / 1080f);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (rect.width == 4098 && rect.height == 1536)
            {
                GetComponent<CanvasScaler>().scaleFactor = (rect.height / (1080f * 4)) * 2;
            }
            else
            {
                GetComponent<CanvasScaler>().scaleFactor = Mathf.Min(rect.width / (1920f * 2), rect.height / (1080f * 2));
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            GetComponent<CanvasScaler>().scaleFactor = Mathf.Min(rect.width / (1920f * 4), rect.height / (1080f * 4));
        }
    }
}