同步操作将从 jzt/UnityFun 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System.Collections.Generic;using UnityEngine;using UnityEngine.Events;/// <summary>/// UGUIԴŲ/// </summary>/// <typeparam name="T"></typeparam>public class ObjectPool<T> where T : new(){private readonly Stack<T> m_Stack = new Stack<T>();private readonly UnityAction<T> m_ActionOnGet;private readonly UnityAction<T> m_ActionOnRelease;public int countAll { get; private set; }public int countActive { get { return countAll - countInactive; } }public int countInactive { get { return m_Stack.Count; } }public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease){m_ActionOnGet = actionOnGet;m_ActionOnRelease = actionOnRelease;}public T Get(){T element;if (m_Stack.Count == 0){element = new T();countAll++;}else{element = m_Stack.Pop();}if (m_ActionOnGet != null)m_ActionOnGet(element);return element;}public void Release(T element){if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");if (m_ActionOnRelease != null)m_ActionOnRelease(element);m_Stack.Push(element);}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。