Exemple #1
0
    public void InitSafeArea()
    {
        SafeInit();

        //UI TODO: Find a Callback instead of Calling this every frame.
        Vector4 v_safeArea = GetSafePadding(); // or Screen.safeArea if you use a version of Unity that supports it

        //#if IN_GAME
        //        Common.HobaDebuger.Log("[UI] InitSafeArea " + v_safeArea + SystemInfo.deviceModel);
        //#else
        //        Debug.Log("[UI] InitSafeArea " + v_safeArea + SystemInfo.deviceModel);
        //#endif

#if !UNITY_EDITOR
        if (v_safeArea == Vector4.zero)
        {
            enabled = false;
        }
#endif

        if (!_ShouldBeEnable)
        {
            return;
        }
        float scale = 1;
#if IN_GAME && UNITY_IOS || IN_GAME && UNITY_ANDROID || UNITY_EDITOR
        CanvasScaler cs = GetComponentInParent <CanvasScaler>();
        if (cs == null)
        {
            return;
        }
        else
        {
            RectTransform rt = cs.GetComponent <RectTransform>();
            if (rt != null)
            {
                scale = rt.rect.width / Screen.width;
            }
        }
#endif

        Vector4 v_result   = new Vector4();
        int     i_platform = 0;
#if UNITY_EDITOR
        v_result = v_safeArea * VDensity;
#elif IN_GAME && UNITY_IOS
        v_result = new Vector4(v_safeArea.x, 0, 0, 0);
        Debug.Log("Safe padding " + v_result + " , " + " , " + scale);
        i_platform = 1;
#elif IN_GAME && UNITY_ANDROID
        float d = AndroidUtil.GetDensity();
        v_result = v_safeArea * d;
        Debug.Log("Safe padding " + v_result + " , " + d + " , " + scale);
        i_platform = 2;
#endif

#if IN_GAME
        object[] float4_results = LuaScriptMgr.Instance.CallLuaFunction("ConfirmSafeArea", v_result.x, v_result.y, v_result.z, v_result.w, SystemInfo.deviceModel, i_platform);
        if (float4_results != null)
        {
            CurSafePadding = new Vector4((float)(double)float4_results[0], (float)(double)float4_results[1], (float)(double)float4_results[2], (float)(double)float4_results[3]) * scale;
        }
#else
        CurSafePadding = v_result * scale;
#endif
    }