71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.UIElements;
|
|
public enum ModeEnum//窗口模式枚举
|
|
{
|
|
autofill = 0,//自动填充
|
|
fixedSize = 1,//固定大小
|
|
}
|
|
public class BoxTypeItem//注册窗体物体类
|
|
{
|
|
public int type;//窗体类型
|
|
public string title = "测试窗体标题";//窗体标题
|
|
public string content = "测试窗体内容";//窗体内容
|
|
}
|
|
public class NormalPopUpWindow : MonoBehaviour
|
|
{
|
|
|
|
public ModeEnum Mode = ModeEnum.autofill;//窗口模式
|
|
|
|
public void setMinimumHeight(int value) {
|
|
minimumHeight = value;
|
|
GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
Debug.Log(GetComponent<LayoutElement>().minHeight);
|
|
}
|
|
private int minimumHeight = -1;//最小高度
|
|
public void setMinimumWidth(int value)
|
|
{
|
|
minimumWidth = value;
|
|
GetComponent<LayoutElement>().minWidth = minimumWidth;
|
|
Debug.Log(GetComponent<LayoutElement>().minWidth);
|
|
}
|
|
private int minimumWidth = -1;//最小宽度
|
|
|
|
public GameObject Title;//窗口标题对象
|
|
public GameObject contentList;//窗口内容对象
|
|
|
|
private List<GameObject> gameObjects = new List<GameObject>();//注册的全部窗体
|
|
public List<GameObject> newPopup(List<BoxTypeItem> my_boxTypes, string title = "标题")//ui更新返回数组
|
|
{
|
|
List<GameObject> gameObjectitem = new List<GameObject>();
|
|
Title.GetComponent<Text>().text = title;
|
|
float posY = 0;
|
|
foreach (BoxTypeItem boxType in my_boxTypes)
|
|
{
|
|
GameObject gameObject = AddItem(boxType);
|
|
gameObjects.Add(gameObject);
|
|
gameObjectitem.Add(gameObject);
|
|
posY += gameObject.GetComponent<RectTransform>().sizeDelta.y;
|
|
|
|
}
|
|
//scroll_view.GetComponent<ScrollRect>().verticalNormalizedPosition = 1.0f;
|
|
return gameObjectitem;
|
|
}
|
|
|
|
private GameObject AddItem(BoxTypeItem boxType)
|
|
{
|
|
GameObject ranking_list_item = null;
|
|
switch (boxType.type)
|
|
{
|
|
case 0:
|
|
ranking_list_item = Instantiate(popUpsCanvas.popUpsCanvasobj.buttonItem, contentList.transform);
|
|
break;
|
|
}
|
|
|
|
ranking_list_item.GetComponent<PopUpWindowitem>().UpdateBoxTypeItem(boxType);
|
|
return ranking_list_item;
|
|
}
|
|
}
|