void RunFPBenchmark() { long testA, testB; if (spawnedObjects == null) { spawnedObjects = new GameObject[times]; } sw = new System.Diagnostics.Stopwatch(); sw.Reset(); sw.Start(); for (int i = 0; i < times; i++) { spawnedObjects[i] = FastPoolManager.GetPool(sourcePrefab, true).FastInstantiate(); } sw.Stop(); testA = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 0; i < times; i++) { FastPoolManager.GetPool(sourcePrefab, false).FastDestroy(spawnedObjects[i]); } sw.Stop(); testB = sw.ElapsedMilliseconds; Results.text = string.Format("FastInstantiating 1000 cubes: {0}ms\r\nFastDestroying 1000 cubes: {1}ms", testA, testB); }
private void setBulletPool() { if (bullets == null) { bullets = new List <GameObject>(); } switch (GameGlobalVariables.Instance.currentBulletType) { case GameGlobalVariables.PlayerBulletType.BULLET_FORK: bulletPool = FastPoolManager.GetPool(GameGlobalVariables.bulletType.bulletForkID, null, false); break; case GameGlobalVariables.PlayerBulletType.BULLET_KNIFE: bulletPool = FastPoolManager.GetPool(GameGlobalVariables.bulletType.bulletKnifeID, null, false); break; case GameGlobalVariables.PlayerBulletType.BULLET_MIXER: bulletPool = FastPoolManager.GetPool(GameGlobalVariables.bulletType.bulletMixerID, null, false); break; case GameGlobalVariables.PlayerBulletType.BULLET_CUTTER: bulletPool = FastPoolManager.GetPool(GameGlobalVariables.bulletType.bulletCutterID, null, false); break; } //print("Setting Bullet pool: " + GameGlobalVariables.Instance.currentBulletType.ToString()); }
// Use this for initialization protected override void Start() { Time.timeScale = 1; base.Start(); powerupWeaponPool = FastPoolManager.GetPool(GameGlobalVariables.gamePowerupType.powerupWeaponID, null, false); SoundManager.instance.PlayBgm(GameGlobalVariables.BGM_GAMEPLAY); StartCoroutine(spawnPowerupWeapon()); }
void Start() { hugeObjectsArray = new GameObject[1000]; //Create a new pool for our sampleGameObject clones and let him to preload 1000 clones fastPool = FastPoolManager.CreatePool(sampleGameObject, true, 1000); //Or you may don't use the FastPoolManager and create and manage pool by yourself. //If you make your FastPool variable public - it will be visible at the inspector //with the same UI as in the FastPoolManager. Look "Without Manager" example for details. // //fastPool = new FastPool(sampleGameObject, null, true, 1000); }
IEnumerator Despawn(float despawn_delay) { yield return(new WaitForSeconds(despawn_delay)); StopAllCoroutines(); if (FastPoolManager.Instance != null) { FastPoolManager.GetPool(targetPoolID, gameObject, true).FastDestroy(gameObject); } else { Debug.LogError("FastPoolManager is not present in the scene or being disabled! AutoDespawn will not working on GameObject " + name); } }
public void DestroyObjects() { //lets despawn our 1000 objects for (int i = 0; i < 1000; i++) { //Get the pool for our source game object. //If it's not exists - it will be created automatically with default settings. //Note that you must always provide the SOURCE game object and NOT a clone! FastPool fastPool = FastPoolManager.GetPool(sampleGameObject); //Cache our clone. fastPool.FastDestroy(hugeObjectsArray[i]); //Or you can do it all in one line: // FastPoolManager.GetPool(sampleGameObject).FastDestroy(hugeObjectsArray[i]); } }
public void Spawn() { //lets spawn 1000 objects for (int i = 0; i < 1000; i++) { //First of all we need to get the pool for our source game object. //If it's not exists - it will be created automatically with default settings. //Note that you must always provide the SOURCE game object and NOT a clone! FastPool fastPool = FastPoolManager.GetPool(sampleGameObject); //Just spawn a clone and remember it. //If pool has cached objects - it will quickly activate it instead of instantiating a new one. hugeObjectsArray[i] = fastPool.FastInstantiate(); //Or you can do it all in one line: // hugeObjectsArray[i] = FastPoolManager.GetPool(sampleGameObject).FastInstantiate(); } }
public void DestroyObjects() { //lets despawn our 1000 objects for (int i = 0; i < 1000; i++) { //Get the pool for our custom pool ID. //If pool for this id does not exist and you want it will be created automatically - then provide the sourcePrefab //and set "createIfNotExists" to true. //Otherwise you can set prefab parameter as null (in this case "createIfNotExists" must be false) FastPool fastPool = FastPoolManager.GetPool(1, null, false); //Cache our clone. fastPool.FastDestroy(hugeObjectsArray[i]); //Or you can do it all in one line: // FastPoolManager.GetPool(1, null, false).FastDestroy(hugeObjectsArray[i]); } }
public void Spawn() { //lets spawn 1000 objects for (int i = 0; i < 1000; i++) { //First of all we need to get the pool for our custom pool ID. //If pool for this id does not exist and you want it will be created automatically - then provide the sourcePrefab //and set "createIfNotExists" to true. //Otherwise you can set prefab parameter as null (in this case "createIfNotExists" must be false) FastPool fastPool = FastPoolManager.GetPool(1, null, false); //Just spawn a clone and remember it. //If pool has cached objects - it will quickly activate it instead of instantiating a new one. hugeObjectsArray[i] = fastPool.FastInstantiate(); //Or you can do it all in one line: // hugeObjectsArray[i] = FastPoolManager.GetPool(sampleGameObject).FastInstantiate(); } }
void OnEnable() { pools = serializedObject.FindProperty("predefinedPools"); fpm = (FastPoolManager)target; }
private void initDictionary() { if (!inited) { coinsPool[BallColor.White] = FastPoolManager.CreatePool(Coin1Prefab); coinsPool[BallColor.Black] = FastPoolManager.CreatePool(Coin2Prefab); coinsPool[BallColor.Red] = FastPoolManager.CreatePool(Coin5Prefab); coinsPool[BallColor.Green] = FastPoolManager.CreatePool(Coin10Prefab); coinsPool[BallColor.Blue] = FastPoolManager.CreatePool(Coin20Prefab); coinsPool[BallColor.Yellow] = FastPoolManager.CreatePool(Coin50Prefab); coinsPool[BallColor.Aqua] = FastPoolManager.CreatePool(Coin100Prefab); foreach (GameObject o in BonusPrefabs) { BaseBonus e = o.GetComponent <BaseBonus>(); ballTypesPool[e.BonusType] = FastPoolManager.CreatePool(o); } foreach (GameObject o in EffectsPrefabs) { effectsPool[o.name] = FastPoolManager.CreatePool(o); } lightningPool = FastPoolManager.CreatePool(LightningPrefab); ColorFigureSprites = new Dictionary <BallColor, Sprite>(); ColorFigureSprites[BallColor.Black] = Black; ColorFigureSprites[BallColor.White] = White; ColorFigureSprites[BallColor.Green] = Green; ColorFigureSprites[BallColor.Aqua] = Aqua; ColorFigureSprites[BallColor.Red] = Red; ColorFigureSprites[BallColor.Blue] = Blue; ColorFigureSprites[BallColor.Yellow] = Yellow; BallTypeSprites = new Dictionary <BallType, Sprite>(); BallTypeSprites[BallType.Simple] = Simple; BallTypeSprites[BallType.Chameleon] = Chameleon; BallTypeSprites[BallType.Freeze] = Freeze; BallTypeSprites[BallType.Brush] = Brush; BallTypeSprites[BallType.Bomb] = Bomb; BallTypeSprites[BallType.Lightning] = Lightning; BallTypeSprites[BallType.Anchored] = Anchored; BallTypeSprites[BallType.Anchor] = Anchor; BallTypeSprites[BallType.Aim] = Aim; BallTypeSprites[BallType.Bubble] = Bubble; BallTypeSprites[BallType.Frozen] = Frozen; BallTypeSprites[BallType.Crashed] = Crashed; BallTypeSprites[BallType.Rust] = Rust; BallColors = new Dictionary <BallColor, Color32>(); BallColors[BallColor.White] = WhiteColor; BallColors[BallColor.Black] = BlackColor; BallColors[BallColor.Green] = GreenColor; BallColors[BallColor.Aqua] = AquaColor; BallColors[BallColor.Red] = RedColor; BallColors[BallColor.Blue] = BlueColor; BallColors[BallColor.Yellow] = YellowColor; BallColors[BallColor.None] = Color.white; BallsPool = FastPoolManager.GetPool(BallPrefab); colors = new BallColor[8]; colors[0] = BallColor.White; colors[1] = BallColor.Black; colors[2] = BallColor.Green; colors[3] = BallColor.Aqua; colors[4] = BallColor.Red; colors[5] = BallColor.Blue; colors[6] = BallColor.Yellow; inited = true; } }
public static GameObject FastInstantiate(this GameObject sourcePrefab, int poolID, Vector3 position, Quaternion rotation, Transform parentTransform = null) { return(FastPoolManager.GetPool(poolID, sourcePrefab, true).FastInstantiate(position, rotation, parentTransform)); }
// Use this for initialization void Start() { powerupType = GameGlobalVariables.PowerupType.POWERUP_WEAPON; powerupPool = FastPoolManager.GetPool(GameGlobalVariables.gamePowerupType.powerupWeaponID, null, false); }
public static void FastDestroy(this GameObject objectToDestroy, Component sourcePrefab) { FastPoolManager.GetPool(sourcePrefab, true).FastDestroy(objectToDestroy); }
public static GameObject FastInstantiate(this GameObject sourcePrefab, Transform parentTransform = null) { return(FastPoolManager.GetPool(sourcePrefab, true).FastInstantiate(parentTransform)); }
public static void FastDestroy(this GameObject objectToDestroy, int poolID) { FastPoolManager.GetPool(poolID, null, false).FastDestroy(objectToDestroy); }