12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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<CurvedUIPool>();
- if (instance == null)
- { //创建游戏对象然后绑定单例脚本
- GameObject go = new GameObject("CurvedUIPool");
- instance = go.AddComponent<CurvedUIPool>();
- }
- }
- 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<CurvedUIBaseController> _cuiBaseControllerPools = new List<CurvedUIBaseController>();
- 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);
- }
- }
|