static int numPerRow = 5;//每行的按钮个数
static int lineHeight = 60;
static float panelWidth = 300;
static float panelHeight = 300;
public static void ShowSelectPanel(EModelType type)
{
List<ModelItem> list = Resource.typeItem[Enum.GetName(typeof(EModelType), type)];
int length = list.Count;
for (int i = 0; i < length; i++)
{
<span style="color:#FF6666;">int row = i / numPerRow;
int col = i % numPerRow;
float offsetX = panelWidth / numPerRow * col - panelWidth / 2 + panelWidth / numPerRow / 2;
float offsetY = panelHeight / 2 - lineHeight * row - lineHeight;</span>
GameObject bt = Instantiate(Resources.Load("KT/SelectItemButton")) as GameObject;
bt.transform.SetParent(_selectPanel);
bt.GetComponent<RectTransform>().localPosition = new Vector3(offsetX, offsetY, 0);
}
}
Unity3d UGUI 动态加载按钮
最新推荐文章于 2021-07-12 20:57:49 发布