using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIFit : MonoBehaviour
{
    private Vector3 _scale;
    private float value;
    public float currentWidth;
    public float currentHeight;
    private float rangeValue=100f;
    // Update is called once per frame

   
    private void Start()
    {
        value = 0.7f;
        GetCurrentScreenWidth();

    }

    void Update()
    {

        GetCurrentScreenWidth();


        if (Mathf.Abs(Screen.width-1920)< rangeValue || Mathf.Abs(Screen.width - 2560) < rangeValue || Mathf.Abs(Screen.width - 4096) < rangeValue)
        {

            value = 1;
        }
        else
        {
            value = 0.8f;
        }
        _scale.x = Screen.width / (currentWidth * value);
        _scale.y = 1;
        _scale.z = 1;
        this.transform.localScale = _scale;
    }



    void GetCurrentScreenWidth()
    {
        if (Screen.width < 1920)
        {
            currentWidth = Screen.width;

            if (Mathf.Abs(Screen.width - (1920 * 0.6f)) <= rangeValue)
            {
                currentWidth = 1920f;
                currentHeight = 1080f;
            }
            if (Mathf.Abs(Screen.width - (2560 * 0.6f)) <= rangeValue)
            {
                currentWidth = 2560f;
                currentHeight = 1440;
            }
            if (Mathf.Abs(Screen.width - (4096 * 0.6f)) <= rangeValue)
            {
                currentWidth = 4096f;
                currentHeight = 3112f;
            }


        }
        else
        {
            currentWidth = Screen.width;
            currentHeight = Screen.height;
        }

        GameRoot.Instance.infoWnd._screenHeight = currentHeight;
        GameRoot.Instance.infoWnd._screenWidth = currentWidth;
    }
}