Пример #1
0
    public GameObject addPrefab_wllEidtor(int nType)
    {
        WllTemplate wt = GetWllItemTemplate(nType);

        string itemTempletePath = wt.path;
        // 创建新的
        string     path = "Assets/Lib/" + itemTempletePath + ".prefab";
        GameObject load = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path) as GameObject;
        GameObject obj  = UnityEditor.PrefabUtility.InstantiatePrefab(load) as GameObject;

        obj.transform.SetParent(transform);
        obj.transform.localScale    = load.transform.localScale;
        obj.transform.localPosition = load.transform.localPosition;
        obj.transform.localRotation = load.transform.localRotation;
        RectTransform objR = obj.GetComponent <RectTransform>();

        if (objR != null)
        {
            RectTransform rect2 = load.GetComponent <RectTransform>();
            objR.anchoredPosition = rect2.anchoredPosition;
            objR.offsetMin        = rect2.offsetMin;
            objR.offsetMax        = rect2.offsetMax;
        }
        LayoutRebuilder.ForceRebuildLayoutImmediate(objR);
        return(obj);
    }
Пример #2
0
    /// <summary>
    /// 渲染视口内的cell
    /// </summary>
    /// <param name="showData"></param>
    public void renderCell(LineData.ShowCellData showData)
    {
        LineData.ShowCellData scd = showData;
        if (scd.itemKey == 0)
        {
            if (onCellInitHandler != null)
            {
                WllTemplate wt = itemTemplate.GetWllItemTemplate(scd.nType);
                if (string.IsNullOrEmpty(wt.path))
                {
                    Debug.Log("没有Item路径");
                    return;
                }
                scd.itemKey = onCellInitHandler.Invoke(wt.path, scd.nType, content);
            }
            else
            {
                scd.itemKey = itemTemplate.findItem(scd.nType, content);
            }
        }
        Vector2 vec = scd.calcuatePos();

        Debug.Log("render " + scd.dataIndex);
        onCellRenderHandler.Invoke(scd.dataIndex, scd.nType, scd.itemKey, vec, scd);
    }
Пример #3
0
    /// <summary>
    /// 添加节点到这一行
    /// </summary>
    /// <param name="rect"></param>
    /// <param name="index"></param>
    /// <param name="viewWidth"></param>
    /// <param name="lineHeightDelta"></param>
    /// <returns></returns>
    public bool AddCell(GridDataSource source, int index, WllTemplate templateInfo, RecycleGrid rg, ref float lineHeightDelta)
    {
        float delta = templateInfo.width;
        float ft    = posx;

        if (list.Count > 0)
        {
            delta = delta + rg.padding.spacex;
        }
        else
        {
            ft = ft + rg.padding.left;
        }
        ft = ft + delta;
        if (ft > rg.ViewWidth)
        {
            return(false);
        }
        else
        {
            posx = ft;
            ShowCellData scd = obtainShowCellData(posx - templateInfo.width, this, index);
            scd.nType       = source.templateId;
            lineHeightDelta = Mathf.Max(lineHeight, templateInfo.height);
            lineHeight      = lineHeightDelta;
            endIndex        = index;
            list.Add(scd);
            return(true);
        }
    }
Пример #4
0
    public GameObject createItem(int nType)
    {
        if (templateType == sType.eidtor)
        {
            return(addPrefab_wllEidtor(nType));
        }
        else
        {
#if UNITY_EDITOR
            WllTemplate template = GetWllItemTemplate(nType);
            return(GameObject.Instantiate <GameObject>(template.tItem));
#else
            return(null);
#endif
        }
    }
Пример #5
0
    /// <summary>
    /// 计算显示cell需要的数据,按行存储
    /// </summary>
    /// <param name="beginIndex">开始计算的cell索引</param>
    /// <param name="source">数据源</param>
    public void fillData(int beginIndex, List <GridDataSource> source)
    {
        float tempPosY = padding.top;

        for (int i = beginIndex; i < source.Count; i++)
        {
            GridDataSource data = source[i];
            WllTemplate    wllt = itemTemplate.GetWllItemTemplate(data.templateId);

            LineData ld          = GetLine(tempPosY, i, wllt.height);
            float    heightDelta = 0;
            bool     addSucess   = ld.AddCell(data, i, wllt, this, ref heightDelta);
            if (!addSucess)
            {
                //滑动位置
                tempPosY = tempPosY + ld.lineHeight + padding.spacey;
                //新增一行
                ld = LineData.NewLine(tempPosY, i, wllt.height);

                addSucess = ld.AddCell(data, i, wllt, this, ref heightDelta);
                if (!addSucess)
                {
                    Debug.LogError("Item的大小不合适窗口的大小");
                    break;
                }
                else
                {
                    lineDataList.Add(ld);
                }
            }
        }
        //控制content的长度
        LineData last = lineDataList[lineDataList.Count - 1];

        ContentHeight = last.childLineY + last.lineHeight + padding.bottom;
    }