Exemplo n.º 1
0
    private void TuneUIPanels(InteractableUIHolder ui_holder, Vector4 v_cur_padding, Vector4 v_last_padding)
    {
        GameObject this_obj = ui_holder.gameObject;

        if (ui_holder.PanelInfoList.Length != 0)
        {
            for (int i = 0; i < ui_holder.PanelInfoList.Length; i++)
            {
                InteractableUIHolder.PanelInfo p_i = ui_holder.PanelInfoList[i];
                if (p_i.Panel != null && !p_i.IsIgnoreResizng)
                {
                    ////did this when build
                    ////if (ui_holder.PanelInfoList[i].Panel == this_obj && ui_holder.PanelInfoList[i].IsKeptFullScreen)
                    ////{
                    ////}
                    ////else
                    //_TuneRect(ui_holder.PanelInfoList[i].Panel, ui_holder.PanelInfoList[i].IsKeptFullScreen, v_cur_padding, v_last_padding, ref ui_holder.PanelInfoList[i].LastArea);
                    _TuneRect(ui_holder.PanelInfoList[i], v_cur_padding, v_last_padding);
                }
            }
        }
        //else
        //{
        //    Vector4 v_area = Vector4.zero;
        //    _TuneRect(this_obj, true, v_cur_padding, v_last_padding, ref v_area);
        //}
    }
Exemplo n.º 2
0
    ////Adjust rect to full screen or safe area.
    //private void _TuneRect(GameObject target_panel, bool keep_fullScreen, Vector4 v_padding, Vector4 v_last_padding, ref Vector4 v_lastArea)
    //{
    //    //RectTransform rt_ui = target_panel.transform as RectTransform;
    //    //RectTransform rt_p = rt_ui.parent as RectTransform;
    //    //if (rt_p != null)
    //    //{
    //    //    Rect rt_pRT = GNewUITools.GetRelativeRect(ThisPanel, rt_p);
    //    //    Rect rt_sr = ThisPanel.rect;

    //    //    if (!keep_fullScreen)
    //    //    {
    //    //        Vector4 v_padding = CurSafePadding;
    //    //        rt_sr.xMin += v_padding.x;
    //    //        rt_sr.yMax -= v_padding.y;
    //    //        rt_sr.xMax -= v_padding.z;
    //    //        rt_sr.yMin += v_padding.w;
    //    //    }

    //    //    //calc the difference of parent and the screen
    //    //    Vector4 v_area = new Vector4(rt_sr.xMin - rt_pRT.xMin, rt_sr.yMax - rt_pRT.yMax, rt_sr.xMax - rt_pRT.xMax, rt_sr.yMin - rt_pRT.yMin);

    //    //    rt_ui.offsetMin += new Vector2(v_area.x, v_area.w);
    //    //    rt_ui.offsetMax += new Vector2(v_area.z, v_area.y);
    //    //}

    //    RectTransform rt_ui = target_panel.transform as RectTransform;
    //    RectTransform rt_p = rt_ui.parent as RectTransform;
    //    if (rt_p != null)
    //    {
    //        Vector4 v_area = Vector4.zero;
    //        if (rt_p != ThisPanel)
    //        {
    //            Rect rect_sr = GNewUITools.GetRelativeRect(rt_p, ThisPanel);
    //            Rect rect_pt = rt_p.rect;

    //            //calc the difference of parent and the screen
    //            v_area.Set(rect_sr.xMin - rect_pt.xMin, rect_sr.yMax - rect_pt.yMax, rect_sr.xMax - rect_pt.xMax, rect_sr.yMin - rect_pt.yMin);
    //        }

    //        Vector4 v_area_new = v_area;
    //        if (!keep_fullScreen)
    //        {
    //            v_area_new.x += v_padding.x;
    //            v_area_new.y -= v_padding.y;
    //            v_area_new.z -= v_padding.z;
    //            v_area_new.w += v_padding.w;
    //        }
    //        else if (rt_p != ThisPanel)
    //        {
    //            v_area_new -= v_lastArea;
    //            v_lastArea = v_lastArea + v_area_new;
    //        }

    //        //if (rt_p != ThisPanel)
    //        //{
    //        //    v_areaUndo -= v_lastArea;
    //        //}
    //        //rt_ui.offsetMin += new Vector2(v_area.x * (rt_ui.pivot.x - rt_ui.anchorMin.x), v_area.w * (rt_ui.pivot.y - rt_ui.anchorMin.y));
    //        //rt_ui.offsetMax += new Vector2(v_area.z * (rt_ui.anchorMax.x - rt_ui.pivot.x), v_area.y * (rt_ui.anchorMax.y - rt_ui.pivot.y));

    //        Vector2 min_off = new Vector2(Mathf.Lerp(v_area_new.x, v_area_new.z, rt_ui.anchorMin.x),
    //            Mathf.Lerp(v_area_new.w, v_area_new.y, rt_ui.anchorMin.y));
    //        Vector2 max_off = new Vector2(Mathf.Lerp(v_area_new.x, v_area_new.z, rt_ui.anchorMax.x),
    //            Mathf.Lerp(v_area_new.w, v_area_new.y, rt_ui.anchorMax.y));

    //        rt_ui.offsetMin += min_off;
    //        rt_ui.offsetMax += max_off;

    //        //Check

    //        Vector4 v_area_chk = v_area;
    //        Vector4 v_padding_new = v_padding + v_last_padding;
    //        if (!keep_fullScreen)
    //        {
    //            v_area_chk.x += v_padding_new.x;
    //            v_area_chk.y -= v_padding_new.y;
    //            v_area_chk.z -= v_padding_new.z;
    //            v_area_chk.w += v_padding_new.w;
    //        }
    //        else if (rt_p != ThisPanel)
    //        {
    //            v_area_chk -= v_padding_new;
    //        }

    //        Vector2 min_off_2 = new Vector2(Mathf.Lerp(v_area_chk.x, v_area_chk.z, rt_ui.anchorMin.x),
    //            Mathf.Lerp(v_area_chk.w, v_area_chk.y, rt_ui.anchorMin.y));
    //        Vector2 max_off_2 = new Vector2(Mathf.Lerp(v_area_chk.x, v_area_chk.z, rt_ui.anchorMax.x),
    //            Mathf.Lerp(v_area_chk.w, v_area_chk.y, rt_ui.anchorMax.y));

    //        if (min_off != min_off_2 || max_off != max_off_2)
    //        {
    //            Common.HobaDebuger.LogError("TuneUI " + rt_ui.name + " " + min_off + ", " + max_off + " != " + min_off_2 + ", " + max_off_2);
    //        }
    //    }
    //}

    //Adjust rect to full screen or safe area.
    private void _TuneRect(InteractableUIHolder.PanelInfo p_info, Vector4 v_cur_padding, Vector4 v_last_padding)
    {
        RectTransform rt_ui = p_info.Panel.transform as RectTransform;
        RectTransform rt_p  = rt_ui.parent as RectTransform;

        if (rt_p != null)
        {
            Vector4 v_padding_new = v_cur_padding;
            if (!p_info.IsKeptFullScreen)
            {
                Vector4 v_area_chk = Vector4.zero;
                v_area_chk.x += v_padding_new.x;
                v_area_chk.y -= v_padding_new.y;
                v_area_chk.z -= v_padding_new.z;
                v_area_chk.w += v_padding_new.w;

                Vector2 min_off_2 = p_info.OffsetMin + new Vector2(Mathf.Lerp(v_area_chk.x, v_area_chk.z, rt_ui.anchorMin.x),
                                                                   Mathf.Lerp(v_area_chk.w, v_area_chk.y, rt_ui.anchorMin.y));
                Vector2 max_off_2 = p_info.OffsetMax + new Vector2(Mathf.Lerp(v_area_chk.x, v_area_chk.z, rt_ui.anchorMax.x),
                                                                   Mathf.Lerp(v_area_chk.w, v_area_chk.y, rt_ui.anchorMax.y));

                rt_ui.offsetMin = min_off_2;
                rt_ui.offsetMax = max_off_2;
            }
            else if (rt_p != ThisPanel)
            {
                Rect rect_sr = GNewUITools.GetRelativeRect(rt_p, ThisPanel);
                Rect rect_pt = rt_p.rect;

                ////calc the difference of parent and the screen
                //v_area_chk.Set(rect_sr.xMin - rect_pt.xMin, rect_sr.yMax - rect_pt.yMax, rect_sr.xMax - rect_pt.xMax, rect_sr.yMin - rect_pt.yMin);

                rt_ui.anchorMin = Vector2.zero;
                rt_ui.anchorMax = Vector2.one;

                rt_ui.offsetMin = new Vector2(rect_sr.xMin - rect_pt.xMin, rect_sr.yMin - rect_pt.yMin);
                rt_ui.offsetMax = new Vector2(rect_sr.xMax - rect_pt.xMax, rect_sr.yMax - rect_pt.yMax);
            }
        }
    }