using System.Collections; using System.Collections.Generic; using UnityEngine; public class PollManager : MonoBehaviour { Transform m_PollParent; //对象池字典 Dictionary m_Polls = new Dictionary(); private void Awake() { m_PollParent = this.transform.parent.Find("Poll"); } /// /// 创建对象池 /// /// /// /// private void CreatePoll(string pollName, float releaseTime) where T : PollBase { if (!m_Polls.TryGetValue(pollName, out PollBase poll)) { GameObject go = new GameObject(); go.name = pollName; go.transform.SetParent(m_PollParent); poll = go.AddComponent(); poll.Init(releaseTime); m_Polls.Add(pollName, poll); } } /// /// 创建物体对象池 /// /// /// public void CreateGameObjectPoll(string pollName, float releaseTime) { CreatePoll(pollName, releaseTime); } /// /// 取出对象 /// /// /// /// public Object Spwan(string pollName, string asseteName) { if (m_Polls.TryGetValue(pollName, out PollBase poll)) { return poll.Spwan(asseteName); } return null; } /// /// 回收对象 /// /// /// /// public void UnSpwan(string pollName, string asseteName, Object assete) { if (m_Polls.TryGetValue(pollName, out PollBase poll)) { poll.UnSpwan(asseteName, assete); } } }