GameFramwork游戏框架4 克隆一样的模板

GameFramwork游戏框架4 克隆一样的模板_第1张图片
我们可以看到整个活动面板可以说都是由一个模板复制出来的
在这里插入图片描述

步骤:

先搭建好UI模板,并添加 Scroll View组件,在content同一级之下搭建模板
在这里插入图片描述
图片数据都是通过读表然后赋值上去的

然后在content上添加排版工具
GameFramwork游戏框架4 克隆一样的模板_第2张图片
以上操作完成之后,就是脚本了

using System;
using GameFramework;
using UnityEngine;
using UnityEngine.UI;
using GameFramework.DataTable;
using System.Collections.Generic;

namespace StarForce
{
    public class SevenDayForm : UGuiForm
    {
        private GameObject itemPrefab;  //每一档的模板
        private Transform grid;  //动态加载的每一档的父节点
        
        protected override void OnInit(object userData)
        {
            itemPrefab = transform.Find("bg/Scroll View/Viewport/bg").gameObject;
            grid = transform.Find("bg/Scroll View/Viewport/Content");
        }
        private void InitSevenDayItems()
        {
            //读表
            IDataTable<DRSevenDayLoginEvent> dtSevenDayLogins = GameEntry.DataTable.GetDataTable<DRSevenDayLoginEvent>();
            totalDays = dtSevenDayLogins.Count;  //获取总共有几档
            for (int i = 0; i < totalDays; i++)
            {
                GameObject item = Instantiate(itemPrefab);
                item.SetActive(true);
                item.transform.SetParent(grid,false);
                DRSevenDayLoginEvent dtSevenDayLogin = dtSevenDayLogins.GetDataRow(i + 1);
                item.AddComponent<SevenDayLoginItem>().SetSevenDayItemInfo(dtSevenDayLogin);
            }
        }
    }
    public class SevenDayLoginItem : MonoBehaviour
    {
        private GameObject _sprite;
        private Transform grid2;
        private Text des; //文本描述
        private Button lingquBtn;

        private void Awake()
        {
            des = transform.Find("desImg/Text").GetComponent<Text>();
            grid2 = transform.Find("ImgJieDian");
            _sprite = transform.Find("Image1").gameObject;
            lingquBtn = transform.Find("Button").GetComponent<Button>();
            if (lingquBtn != null)
            {
                lingquBtn.onClick.AddListener(OnClickLingquBtn);
            }
        }
        public void SetSevenDayItemInfo(DRSevenDayLoginEvent info)
        {
            des.text = info.AWARD_DESCRIBE;
            //调用 按 | 切割 返回List
            List<string> items = DataTableExtension.GetItemIdAndNumString(info.LOGIN_AWARD);
            for (int i = 0; i < items.Count; i++)
            {
                GameObject item2 = Instantiate(_sprite);
                item2.SetActive(true);
                item2.transform.SetParent(grid2);
                if (items != null)
                {
                    item2.GetComponent<Image>().sprite = UIExtension.GetItemSprite(DataTableExtension.GetItemIdAndNum(items[i])[0]);
                }
            }
        }
        void OnClickLingquBtn()
        {
            lingquBtn.interactable = false;
        }

    }
}

你可能感兴趣的:(GameFramwork游戏框架4 克隆一样的模板)