using System.Collections; using System.Collections.Generic; using UnityEngine; public class CurvedUIPool : MonoBehaviour { private static CurvedUIPool instance = null; //共有的唯一的,全局访问点 public static CurvedUIPool Instance { get { if (instance == null) { //查找场景中是否已经存在单例 instance = GameObject.FindObjectOfType(); if (instance == null) { //创建游戏对象然后绑定单例脚本 GameObject go = new GameObject("CurvedUIPool"); instance = go.AddComponent(); } } return instance; } } private void Awake() { //防止存在多个单例 if (instance == null) instance = this; else Destroy(gameObject); } public Transform _poolTrans; public bool isPlayCurvedLoadAni = true; public CurvedUIBaseController _cuiBasePrefab; public List _cuiBaseControllerPools = new List(); public CurvedUIBaseController GetCUIBaseController() { if (_cuiBaseControllerPools.Count > 0) { CurvedUIBaseController get_CuiBase = _cuiBaseControllerPools[0]; _cuiBaseControllerPools.Remove(get_CuiBase); return get_CuiBase; } else { CurvedUIBaseController item = GameObject.Instantiate(_cuiBasePrefab); item.transform.parent = _poolTrans; item.gameObject.SetActive(true); item.InitCurvedOpenState(false); return item; } } public void PutCUIBaseController(CurvedUIBaseController cuiBase) { if (!_cuiBaseControllerPools.Contains(cuiBase)) { _cuiBaseControllerPools.Add(cuiBase); } cuiBase.InitCurvedOpenState(false); } }