unitytools/Assets/UnityTools/script/NormalPopUpWindow.cs

104 lines
4.2 KiB
C#
Raw Permalink Normal View History

2024-11-12 00:30:33 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2024-11-12 01:06:12 +08:00
using UnityEngine.UIElements;
2024-11-12 00:30:33 +08:00
public enum ModeEnum//<2F><><EFBFBD><EFBFBD>ģʽö<CABD><C3B6>
{
autofill = 0,//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
fixedSize = 1,//<2F>̶<EFBFBD><CCB6><EFBFBD>С
}
2024-11-12 01:06:12 +08:00
public class BoxTypeItem//ע<><EFBFBD><E1B4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
public int type;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public string title = "<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public string content = "<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-12 02:50:27 +08:00
public string hint = "<22><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ʾ";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
2024-11-12 01:06:12 +08:00
}
2024-11-12 00:30:33 +08:00
public class NormalPopUpWindow : MonoBehaviour
{
2024-11-12 02:50:27 +08:00
public void setMode(ModeEnum modeEnum)
{
Mode = modeEnum;
switch (modeEnum)
{
case ModeEnum.autofill://<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
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://<2F>̶<EFBFBD><CCB6><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
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;
}
}
2024-11-12 00:30:33 +08:00
public ModeEnum Mode = ModeEnum.autofill;//<2F><><EFBFBD><EFBFBD>ģʽ
public void setMinimumHeight(int value) {
minimumHeight = value;
2024-11-12 02:50:27 +08:00
this.GetComponent<LayoutElement>().minHeight = minimumHeight;
viewport.GetComponent<LayoutElement>().minHeight = minimumHeight;
scroll_view.GetComponent<LayoutElement>().minHeight = minimumHeight;
2024-11-12 00:30:33 +08:00
Debug.Log(GetComponent<LayoutElement>().minHeight);
}
private int minimumHeight = -1;//<2F><>С<EFBFBD>߶<EFBFBD>
public void setMinimumWidth(int value)
{
minimumWidth = value;
GetComponent<LayoutElement>().minWidth = minimumWidth;
Debug.Log(GetComponent<LayoutElement>().minWidth);
}
private int minimumWidth = -1;//<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
2024-11-12 01:06:12 +08:00
public GameObject Title;//<2F><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameObject contentList;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
2024-11-12 02:50:27 +08:00
public GameObject viewport;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>
public GameObject scroll_view;//<2F><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-12 01:06:12 +08:00
private List<GameObject> gameObjects = new List<GameObject>();//ע<><D7A2><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public List<GameObject> newPopup(List<BoxTypeItem> my_boxTypes, string title = "<22><><EFBFBD><EFBFBD>")//ui<75><69><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-12 00:30:33 +08:00
{
2024-11-12 01:06:12 +08:00
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;
2024-11-12 00:30:33 +08:00
}
2024-11-12 01:06:12 +08:00
private GameObject AddItem(BoxTypeItem boxType)
2024-11-12 00:30:33 +08:00
{
2024-11-12 01:06:12 +08:00
GameObject ranking_list_item = null;
switch (boxType.type)
{
case 0:
2024-11-12 02:50:27 +08:00
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);
2024-11-12 01:06:12 +08:00
break;
}
ranking_list_item.GetComponent<PopUpWindowitem>().UpdateBoxTypeItem(boxType);
return ranking_list_item;
2024-11-12 00:30:33 +08:00
}
}