using UnityEngine;
using System.Collections.Generic;

public class XAdaptor : MonoBehaviour
{
    public float OffsetY = 65;

    RectTransform mRect;

    private void Awake()
    {
        mRect = GetComponent<RectTransform>();
        if (mRect != null)
        {
            if (IsIphoneX)
            {
                mRect.offsetMax = new Vector2(mRect.offsetMax.x, -OffsetY);
            }
        }
    }

    private bool IsIphoneX
    {
        get
        {
            string tModelStr = SystemInfo.deviceModel;

            if (tModelStr.Contains("iPhone"))
            {
                string[] tNumStrs = tModelStr.Replace("iPhone", "").Split(',');
                int tNumber1 = 0, tNumber2 = 0;

                if (int.TryParse(tNumStrs[0], out tNumber1) && int.TryParse(tNumStrs[1], out tNumber2))
                {
                    if (tNumber1 == 10 && (tNumber2 == 3 || tNumber2 == 6))//Include iPhoneX
                        return true;

                    if (tNumber1 == 12 && tNumber2 == 8)//Exclude iPhoneSE2
                        return false;

                    if (tNumber1 >= 11)
                        return true;
                }
            }

            if (Mathf.Abs((float)Screen.height / Screen.width - 2436 / 1125f) <= 0.01f)
                return true;

            return false;
        }
    }
}