SimplePM.PrefabPool.PreloadInstances C# (CSharp) Method

PreloadInstances() private method

private PreloadInstances ( ) : void
return void
        internal void PreloadInstances()
        {
            if (PreLoaded)
            {
                Debug.Log(string.Format("SpawnPool {0} ({1}): " +
                                          "Already preloaded! You cannot preload twice. " +
                                          "If you are running this through code, make sure " +
                                          "it isn't also defined in the Inspector.",
                                        mSpawnPool.PoolName,
                                        mPrefab.name));
                return;
            }

            PreLoaded = true;

            if (mPrefab == null)
            {
                Debug.LogError(string.Format("SpawnPool {0} ({1}): Prefab cannot be null.",
                                          mSpawnPool.PoolName,
                                          mPrefab.name));
                return;
            }

            if (mLimitInstances && PreLoadAmount > LimitAmount)
            {
                Debug.LogWarning
                (
                    string.Format
                    (
                        "SpawnPool {0} ({1}): " +
                            "You turned ON 'Limit Instances' and entered a " +
                            "'Limit Amount' greater than the 'Preload Amount'! " +
                            "Setting preload amount to limit amount.",
                                mSpawnPool.PoolName,
                                mPrefab.name
                    )
                );

                PreLoadAmount = LimitAmount;
            }

            if (CullDespawned && PreLoadAmount > CullAbove)
            {
                Debug.LogWarning(string.Format("SpawnPool {0} ({1}): " +
                    "You turned ON Culling and entered a 'Cull Above' threshold " +
                    "greater than the 'Preload Amount'! This will cause the " +
                    "culling feature to trigger immediatly, which is wrong " +
                    "conceptually. Only use culling for extreme situations. " +
                    "See the docs.",
                    mSpawnPool.PoolName,
                    mPrefab.name
                ));
            }

            if (PreLoadTime)
            {
                if (PreLoadFrames > PreLoadAmount)
                {
                    Debug.LogWarning(string.Format("SpawnPool {0} ({1}): " +
                        "Preloading over-time is on but the frame duration is greater " +
                        "than the number of instances to preload. The minimum spawned " +
                        "per frame is 1, so the maximum time is the same as the number " +
                        "of instances. Changing the preloadFrames value...",
                        mSpawnPool.PoolName,
                        mPrefab.name
                    ));

                    PreLoadFrames = PreLoadAmount;
                }
                mSpawnPool.StartCoroutine(PreloadOverTime());
            }
            else
            {
                mForceLogSilent = true;

                Transform inst;
                while (TotalCount < PreLoadAmount)
                {
                    inst = SpawnNew();
                    DespawnInstance(inst, false);
                }
                mForceLogSilent = false;
            }
        }

Usage Example

コード例 #1
0
        public void CreatePrefabPool(PrefabPool prefabPool)
        {
            bool isAlreadyPool = GetPrefabPool(prefabPool.Prefab) == null ? false : true;

            if (isAlreadyPool)
            {
                return;
            }

            prefabPool.OwnedSpawnPool = this;
            mPrefabPools.Add(prefabPool);

            mPrefabs.Add(prefabPool.Prefab.name, prefabPool.Prefab);

            if (!prefabPool.PreLoaded)
            {
                prefabPool.PreloadInstances();
            }
        }
All Usage Examples Of SimplePM.PrefabPool::PreloadInstances