[Unity][PoolManager]对象池加载多对象

本文详细介绍了Unity中PoolManager的使用,包括基础应用、处理预制体已存在于spawnPool中的问题、通过名称查找和操作物体、解决物体未消除的状况、如何为Pool中的对象添加脚本并初始化,以及应对对象池过多导致的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PathologicalGames;//PoolManager

public class Pool_Effect : MonoBehaviour
{
    public static Pool_Effect instance;//单例
    #region

    int coluSize = 1, rowSize = 9999;

    SpawnPool spawnPool_effect;
    PrefabPool prefabPool_effect;

    private string effectPath = "Effects/";

    private string[] effectNames = new string[]
    {
        "Cube",
        "Cube1",
        "Cube2",
        "Cube3",
    };//预制体对象名字 数组

    #endregion//

    private void Awake()
    {
        instance = this;
        createSpawnPool("pool_Effect", "Effect", out spawnPool_effect, false, false, false, false, false, 60f);
    }//
    // Start is called before the first frame update
    void Start()
    {
        initPool();
    }
    private void initPool()//初始化对象池
    {
        foreachInit(effectNames, spawnPool_effect, prefabPool_effect, effectPath, 1);

    }//
    /// <summary>
    /// 创建 生成池
    /// </summary>
    /// <param name="poolGOName">池子实体 的名称</param>
    /// <param name="poolName">池子的名称</param>
    /// /// <param name="pool_"></param>
    /// <param name="matchPoolLayer">勾选后实例化的游戏对象的Layer将用Prefab默认的。</param>
    /// <param name="matchPoolScale">勾选后实例化的游戏对象的缩放比例将全是1,不勾选择用Prefab默认的。</param>
    /// <param name="logMessages">是否打印日志信息</param>
    /// <param name="dontReparent">勾选后实例化的对象将没有父节点,通通在最上层,建议不要勾选。</param>
    /// <param name="dontDestroyOnLoad">如果为true,则将Pool的组GameObject设置为Unity的Object.DontDestroyOnLoad()</param>
    /// <param name="maxParticleDespawnTime">停止等待粒子死亡的时间(以秒为单
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值