예제 #1
0
    public bool IsListItemVisible(int index, float err = 1f)
    {
        if (IsInited)
        {
            RectTransform rt_v = _ScrollRect.viewport;
            GListItem     item = GetListItem(index);
            if (item != null)
            {
                Rect rect_child = GNewUITools.GetRelativeRect(rt_v, item.RectTrans);
                Rect rect_v     = rt_v.rect;

                if (IsVertical)
                {
                    bool is_inside = rect_child.yMin + err >= rect_v.yMin && rect_child.yMax - err <= rect_v.yMax;
                    return(is_inside);
                }
                else
                {
                    bool is_inside = rect_child.xMin + err >= rect_v.xMin && rect_child.xMax - err <= rect_v.xMax;
                    return(is_inside);
                }
            }
        }
        return(false);
    }
예제 #2
0
    public void SetMaskTrs(GameObject dest)
    {
        //Debug.Log ("destname="+dest.name);

        _CurTime = 0;
        _CurV4   = Vector4.zero;

        RectTransform rt = dest.GetComponent <RectTransform> ();

        RectTransform t_root  = Main.UIRootCanvas as RectTransform;
        Rect          rt_root = t_root.rect;

        //Vector4 v4 = t_root.InverseTransformPoint(dest.transform.position);
        float a = 0, b = 0, c = 0, d = 0;
        //float a1 = 0, c1 = 0;
        Rect rect = GNewUITools.GetRelativeRect(t_root, rt);

        a = rect.xMin / rt_root.width + 0.5f;
        c = 0.5f - rect.xMax / rt_root.width;
        b = rect.yMin / rt_root.height + 0.5f;
        d = 0.5f - rect.yMax / rt_root.height;
        //if (Util.Equals(rt.pivot.x, 0f))
        //{
        //    a = rt.anchoredPosition.x / rt_root.width;
        //    c = (rt_root.width - (rt.anchoredPosition.x + rt.sizeDelta.x)) / rt_root.width;
        //}
        //else if (Util.Equals(rt.pivot.x, 1f))
        //{
        //    a = (rt_root.width + rt.anchoredPosition.x - rt.sizeDelta.x) / rt_root.width;
        //    c = (rt_root.width - (rt_root.width + rt.anchoredPosition.x)) / rt_root.width;
        //}
        //else if (Util.Equals(rt.pivot.x, 0.5f))
        //{

        //    a = ((rt_root.width / 2) + (rt.anchoredPosition.x - rt.sizeDelta.x / 2)) / rt_root.width;
        //    c = (rt_root.width - ((rt_root.width / 2) + (rt.anchoredPosition.x + rt.sizeDelta.x / 2))) / rt_root.width;
        //}

        //if (Util.Equals(rt.pivot.y,0f)) {
        //	b = rt.anchoredPosition.y / rt_root.height;
        //	d = (rt_root.height - (rt.anchoredPosition.y + rt.sizeDelta.y)) / rt_root.height;
        //} else if (Util.Equals(rt.pivot.y,1f)){
        //	b = (rt_root.height + rt.anchoredPosition.y - rt.sizeDelta.y) / rt_root.height;
        //	d = (rt_root.height - (rt_root.height +rt.anchoredPosition.y)) / rt_root.height;
        //} else if (Util.Equals(rt.pivot.y,0.5f)) {
        //	b = ((rt_root.height / 2) + (rt.anchoredPosition.y - rt.sizeDelta.y / 2)) / rt_root.height;
        //	d = (rt_root.height - ((rt_root.height / 2) + (rt.anchoredPosition.y + rt.sizeDelta.y / 2))) / rt_root.height;
        //}

        _TarV4 = new Vector4(a, b, c, d);
        if (!IsLerp)
        {
            mask.SetVector("_Rect", _TarV4);
        }
        //Debug.Log(":: " + a1 + ", " + c1);
        //Debug.Log("::: " + a + ", " + c);
    }
예제 #3
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);
            }
        }
    }