PoolManager插件的简单使用

在这里插入图片描述


//创建预设
using PathologicalGames;

public class UI_MightyKnight_Main : MonoBehaviour
 {
    
    
    private SpawnPool _sp_KillMonsterPool;
     void Start ()
    {
    
    
      //某个池子
      _sp_KillMonsterPool = PoolManager.Pools["MonsterDieGetGold"];
      }
      public void KillMonsterGetGold( Transform tf, float getGold)
    {
    
    
        
        //产生金币,方法里就是预设的名字
        Transform temp_item = _sp_KillMonsterPool.Spawn("Pool_MonsterDieGetGold");
        temp_item.localPosition = tf.localPosition;
        temp_item.GetComponent<MonsterDieGetGold>().Initial();
    }
 }
 ------------------------------------------
//预设体脚本,用完之后回收
using PathologicalGames;

public class MonsterDieGetGold : MonoBehaviour {
    
    
    
    Transform trans_GameGoldDisplay;
    private SpawnPool _sp_KillMonsterPool;
   
   public void Initial()
    {
    
    
        _sp_KillMonsterPool = PoolManager.Pools["MonsterDieGetGold"];
        //要移动到的地方
        trans_GameGoldDisplay = GameObject.Find("GameGoldDisplay").transform;
        this.transform.DOLocalMove(trans_GameGoldDisplay.localPosition, 1).OnComplete(() =>
        {
    
    
        //判断是否已经被回收
           if (_sp_KillMonsterPool.IsSpawned(this.transform))
                {
    
       
                 //移动完成后回收
                    _sp_KillMonsterPool.Despawn(this.transform);
                }
        });
    }
	
}

猜你喜欢

转载自blog.csdn.net/qq_36592993/article/details/84954425