104 lines
4.2 KiB
C#
104 lines
4.2 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 string hint = "测试窗体提示";//窗体提示
|
|
}
|
|
public class NormalPopUpWindow : MonoBehaviour
|
|
{
|
|
public void setMode(ModeEnum modeEnum)
|
|
{
|
|
Mode = modeEnum;
|
|
switch (modeEnum)
|
|
{
|
|
case ModeEnum.autofill://自动填充
|
|
contentList.GetComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.MinSize;
|
|
viewport.GetComponent<VerticalLayoutGroup>().enabled = true;
|
|
viewport.GetComponent<VerticalLayoutGroup>().childControlHeight = true;
|
|
scroll_view.GetComponent<ScrollRect>().horizontal = false;
|
|
scroll_view.GetComponent<ScrollRect>().vertical = false;
|
|
viewport.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
scroll_view.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
break;
|
|
case ModeEnum.fixedSize://固定大小滚动
|
|
contentList.GetComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.MinSize;
|
|
viewport.GetComponent<VerticalLayoutGroup>().enabled = false;
|
|
viewport.GetComponent<VerticalLayoutGroup>().childControlHeight = false;
|
|
scroll_view.GetComponent<ScrollRect>().horizontal = false;
|
|
scroll_view.GetComponent<ScrollRect>().vertical = true;
|
|
viewport.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
scroll_view.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
break;
|
|
}
|
|
}
|
|
public ModeEnum Mode = ModeEnum.autofill;//窗口模式
|
|
|
|
public void setMinimumHeight(int value) {
|
|
minimumHeight = value;
|
|
this.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
viewport.GetComponent<LayoutElement>().minHeight = minimumHeight;
|
|
scroll_view.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;//窗口内容对象
|
|
public GameObject viewport;//窗口视窗对象
|
|
public GameObject scroll_view;//窗口滑动对象
|
|
|
|
|
|
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.singleButton, GameObject.Find("Content").transform);
|
|
break;
|
|
case 1:
|
|
ranking_list_item = Instantiate(popUpsCanvas.popUpsCanvasobj.inputBoxWithButton, GameObject.Find("Content").transform);
|
|
break;
|
|
}
|
|
|
|
ranking_list_item.GetComponent<PopUpWindowitem>().UpdateBoxTypeItem(boxType);
|
|
return ranking_list_item;
|
|
}
|
|
}
|