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().verticalFit = ContentSizeFitter.FitMode.MinSize; viewport.GetComponent().enabled = true; viewport.GetComponent().childControlHeight = true; scroll_view.GetComponent().horizontal = false; scroll_view.GetComponent().vertical = false; viewport.GetComponent().minHeight = minimumHeight; scroll_view.GetComponent().minHeight = minimumHeight; break; case ModeEnum.fixedSize://固定大小滚动 contentList.GetComponent().verticalFit = ContentSizeFitter.FitMode.MinSize; viewport.GetComponent().enabled = false; viewport.GetComponent().childControlHeight = false; scroll_view.GetComponent().horizontal = false; scroll_view.GetComponent().vertical = true; viewport.GetComponent().minHeight = minimumHeight; scroll_view.GetComponent().minHeight = minimumHeight; break; } } public ModeEnum Mode = ModeEnum.autofill;//窗口模式 public void setMinimumHeight(int value) { minimumHeight = value; this.GetComponent().minHeight = minimumHeight; viewport.GetComponent().minHeight = minimumHeight; scroll_view.GetComponent().minHeight = minimumHeight; Debug.Log(GetComponent().minHeight); } private int minimumHeight = -1;//最小高度 public void setMinimumWidth(int value) { minimumWidth = value; GetComponent().minWidth = minimumWidth; Debug.Log(GetComponent().minWidth); } private int minimumWidth = -1;//最小宽度 public GameObject Title;//窗口标题对象 public GameObject contentList;//窗口内容对象 public GameObject viewport;//窗口视窗对象 public GameObject scroll_view;//窗口滑动对象 private List gameObjects = new List();//注册的全部窗体 public List newPopup(List my_boxTypes, string title = "标题")//ui更新返回数组 { List gameObjectitem = new List(); Title.GetComponent().text = title; float posY = 0; foreach (BoxTypeItem boxType in my_boxTypes) { GameObject gameObject = AddItem(boxType); gameObjects.Add(gameObject); gameObjectitem.Add(gameObject); posY += gameObject.GetComponent().sizeDelta.y; } //scroll_view.GetComponent().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().UpdateBoxTypeItem(boxType); return ranking_list_item; } }