コード例 #1
0
        public FusionObjectPool GetPool <T>(T prefab) where T : NetworkObject
        {
            FusionObjectPool pool;

            if (!_poolsByPrefab.TryGetValue(prefab, out pool))
            {
                pool = new FusionObjectPool();
                _poolsByPrefab[prefab] = pool;
            }

            return(pool);
        }
コード例 #2
0
        public NetworkObject AcquireInstance(NetworkRunner runner, NetworkPrefabInfo info)
        {
            NetworkObject prefab;

            if (NetworkProjectConfig.Global.PrefabTable.TryGetPrefab(info.Prefab, out prefab))
            {
                FusionObjectPool pool = GetPool(prefab);
                NetworkObject    newt = pool.GetFromPool(Vector3.zero, Quaternion.identity);

                if (newt == null)
                {
                    newt = Instantiate(prefab, Vector3.zero, Quaternion.identity);
                    _poolsByInstance[newt] = pool;
                }

                newt.gameObject.SetActive(true);
                return(newt);
            }

            Debug.LogError("No prefab for " + info.Prefab);
            return(null);
        }