Advertisement
apieceoffruit

PhotonPrefabPoolLoader

Jun 30th, 2022
900
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None
  1. using System.Collections.Generic;
  2. using Photon.Pun;
  3. using UnityEngine;
  4.  
  5. namespace JasonProject.Networking
  6. {
  7.     public class PhotonPrefabPoolLoader : MonoBehaviour
  8.     {
  9.         [SerializeField] private List<GameObject> _playerActors;
  10.  
  11.         private void Start ()
  12.         {
  13.             var pool = PhotonNetwork.PrefabPool as DefaultPool;
  14.             if (pool == null)
  15.                 return;
  16.  
  17.             AddToPool(_playerActors, pool);
  18.         }
  19.  
  20.         private void AddToPool(List<GameObject> prefabList, DefaultPool pool)
  21.         {
  22.             if (prefabList == null)
  23.                 return;
  24.            
  25.             foreach (var prefab in prefabList)
  26.                 if (!pool.ResourceCache.ContainsKey(prefab.name))
  27.                     pool.ResourceCache.Add(prefab.name, prefab);
  28.         }
  29.     }
  30. }
Advertisement
RAW Paste Data Copied
Advertisement