示例#1
0
    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());
    }
示例#2
0
		void Start() 
		{
			if(healthBarPool==null) {
				healthBarPool = FastPoolManager.GetPool(healthBarPrefab,true);
			}
			if(canvas==null) {
				canvas = GameObject.Find ("Canvas");
			
			}


			setupUnit();
			
			if(this.flying==false) {
				UnitFacade u = (UnitFacade) this.GetUnitFacade();
				GameObject exit = GameObject.Find("CreepExit");
				u.MoveTo(exit.transform.position,false);
			}
			if(!GameManager.REF.demo) {
				GameObject child = NGUITools.AddChild(CreepSpawner.hudRoot, this.hudTextPrefab);
				mText = child.GetComponent<HUDText>();
			
				// Make the UI follow the target
				child.AddComponent<UIFollowTarget>().target = this.transform;
			}

		}
示例#3
0
 public void Init(FastPool pool)
 {
     this.pool = pool;
     if (!line)
     {
         line = GetComponent <LineRenderer>();
     }
 }
示例#4
0
 public int CreatePoolCache <T>(GameObject gameObject, bool warmOnLoad = false, int preloadCount = 0, int capacity = 0) where T : Component
 {
     if (gameObject != null)
     {
         FastPool fastPool = m_fastPoolFactory.CreatePoolC <T>(gameObject, warmOnLoad, preloadCount, capacity);
         return(fastPool.ID);
     }
     return(-1);
 }
示例#5
0
 public int CreatePoolCache(GameObject gameObject, int preloadCount, int capacity)
 {
     if (gameObject != null)
     {
         FastPool fastPool = m_fastPoolFactory.CreatePool(gameObject, false, preloadCount, capacity);
         return(fastPool.ID);
     }
     return(-1);
 }
示例#6
0
        public GameObject CreatePoolObject(GameObject poolGameObject, Vector3 position, Quaternion rotation, Transform parentTransform, bool active)
        {
            FastPool fastPool = GetPool(poolGameObject.GetInstanceID());

            if (fastPool != null)
            {
                return(fastPool.FastInstantiate(active, position, rotation, parentTransform));
            }
            return(null);
        }
示例#7
0
        /// <summary>
        /// Returns pool for the specified prefab or creates it if needed (with default params)
        /// </summary>
        /// <param name="component">Any component of the source prefab</param>
        /// <returns></returns>
        //public FastPool GetPool(Component component, Transform parent, bool createIfNotExists = true)
        //{
        //    if (component != null)
        //    {
        //        GameObject prefab = component.gameObject;
        //        if (m_pools.ContainsKey(prefab.GetInstanceID()))
        //            return m_pools[prefab.GetInstanceID()];
        //        else
        //            return CreatePool(prefab, parent);
        //    }
        //    else
        //    {
        //        Debug.LogError("Trying to get pool for null object");
        //        return null;
        //    }
        //}


        public GameObject CreatePoolObject(int prefabHash, Vector3 position, Quaternion rotation, Transform parentTransform, bool active)
        {
            FastPool fastPool = GetPool(prefabHash);

            if (fastPool != null)
            {
                return(fastPool.FastInstantiate(active, position, rotation, parentTransform));
            }
            return(null);
        }
示例#8
0
    // 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());
    }
示例#9
0
        public void DestroyPool(int InstanceID)
        {
            FastPool fastPool = GetPool(InstanceID);

            if (fastPool != null)
            {
                fastPool.ClearCache();
                DestroyPoolFactory(fastPool.ID);
                m_pools.Remove(fastPool.ID);
            }
        }
示例#10
0
        public T CreatePoolComponent <T>(int poolHash, Vector3 position, Quaternion rotation, Transform parentTransform, bool active) where T : Component
        {
            FastPool fastPool = GetPool(poolHash);

            if (fastPool == null)
            {
                return(null);
            }

            return(fastPool.FastInstantiate <T>(active, position, rotation, parentTransform));
        }
示例#11
0
        public T CreatePoolComponent <T>(GameObject prefab, Vector3 position, Quaternion rotation, Transform parentTransform, bool active) where T : Component
        {
            FastPool fastPool = GetPool(prefab.GetInstanceID());

            if (fastPool == null)
            {
                fastPool = CreatePoolC <T>(prefab);
            }

            return(fastPool.FastInstantiate <T>(active, position, rotation, parentTransform));
        }
示例#12
0
 private Effect GetEffect(string name, Vector2 pos)
 {
     if (inited)
     {
         FastPool p = null;
         if (effectsPool.TryGetValue(name, out p))
         {
             Effect result = p.FastInstantiate <Effect>(pos, Quaternion.identity, transform);
             result.Init(p);
             return(result);
         }
     }
     return(null);
 }
示例#13
0
    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);
    }
示例#14
0
    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);
    }
示例#15
0
 private BaseBonus InstantiateBonus(Ball ball, Vector3 force, float delay)
 {
     if (inited)
     {
         FastPool p = null;
         if (ballTypesPool.TryGetValue(ball.BallType, out p))
         {
             BaseBonus result = p.FastInstantiate <BaseBonus>(ball.Pos, Quaternion.identity, transform);
             result.Emit(ball, p, force, delay);
             return(result);
         }
     }
     return(null);
 }
示例#16
0
 private Coin GetCoinEffect(BallColor col, Vector2 pos)
 {
     if (inited)
     {
         FastPool p = null;
         if (coinsPool.TryGetValue(col, out p))
         {
             Coin result = p.FastInstantiate <Coin>(pos, Quaternion.identity, transform);
             result.Init(p);
             return(result);
         }
     }
     return(null);
 }
示例#17
0
    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]);
        }
    }
示例#18
0
    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]);
        }
    }
示例#19
0
    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();
        }
    }
示例#20
0
        /// <summary>
        /// Create a new pool from provided prefab
        /// </summary>
        /// <param name="prefab">Prefab that will be cloned</param>
        /// <param name="preloadCount">How much items must be preloaded and cached</param>
        /// <param name="capacity">Cache size (maximum amount of the cached items). [0 - unlimited]</param>
        /// <param name="warmOnLoad">Load source prefab in the memory while scene is loading. A bit slower scene loading, but much faster instantiating of new objects in pool</param>
        /// <returns>FastPool instance</returns>
        public FastPool CreatePool(GameObject prefab, bool warmOnLoad = false, int preloadCount = 0, int capacity = 0)
        {
            if (prefab != null)
            {
                if (m_pools.ContainsKey(prefab.GetInstanceID()) == false)
                {
                    Transform poolTransform = CreatePoolFactory(prefab);

                    FastPool newPool = new FastPool(prefab, poolTransform, warmOnLoad, preloadCount, capacity);
                    m_pools.Add(prefab.GetInstanceID(), newPool);
                    newPool.Init();
                    return(newPool);
                }

                return(m_pools[prefab.GetInstanceID()]);
            }

            Debug.LogError("Creating pool with null object");
            return(null);
        }
示例#21
0
    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();
        }
    }
示例#22
0
 /// <summary>
 /// Create a new pool from provided prefab
 /// </summary>
 /// <param name="prefab">Prefab that will be cloned</param>
 /// <param name="preloadCount">How much items must be preloaded and cached</param>
 /// <param name="capacity">Cache size (maximum amount of the cached items). [0 - unlimited]</param>
 /// <param name="warmOnLoad">Load source prefab in the memory while scene is loading. A bit slower scene loading, but much faster instantiating of new objects in pool</param>
 /// <returns>FastPool instance</returns>
 public static FastPool CreatePool(GameObject prefab, bool warmOnLoad = true, int preloadCount = 0, int capacity = 0)
 {
     if (prefab != null)
     {
         if (!Instance.pools.ContainsKey(prefab.GetInstanceID()))
         {
             FastPool newPool = new FastPool(prefab, Instance.curTransform, warmOnLoad, preloadCount, capacity);
             Instance.pools.Add(prefab.GetInstanceID(), newPool);
             return(newPool);
         }
         else
         {
             return(Instance.pools[prefab.GetInstanceID()]);
         }
     }
     else
     {
         Debug.LogError("Creating pool with null object");
         return(null);
     }
 }
示例#23
0
 public static void FastDestroy(this GameObject objectToDestroy, FastPool pool)
 {
     pool.FastDestroy(objectToDestroy);
 }
示例#24
0
	public void Start() {
		if(blastObjectPool==null||blastObjectPool.ID==0) {
			blastObjectPool = FastPoolManager.GetPool(blastObjectPrefab,true);
		}
	}
示例#25
0
 public virtual void Emit(Ball ball, FastPool pool, Vector2 force, float delay)
 {
     this.pool = pool;
     this.ball = ball;
     StartCoroutine(EnableParticlesRoutine(delay));
 }
示例#26
0
 /// <summary>
 /// Destroys provided pool and it's cached objects
 /// </summary>
 /// <param name="pool">Pool to destroy</param>
 public static void DestroyPool(FastPool pool)
 {
     pool.ClearCache();
     Instance.pools.Remove(pool.ID);
 }
示例#27
0
        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;
            }
        }
示例#28
0
	public void Start () {
		if (CheckErrors() == true) { return; }
		

		
		if(this.shot.ID==0) {
			this.shot = FastPoolManager.GetPool(this.shotPrefab,true);
		}  
		GameObject g = this.shot.TryGetNextObject(Vector3.zero,Quaternion.identity);
		useGravity = g.GetComponent<Rigidbody>().useGravity;
		Destroy(g);

		curAmmoCount = maxAmmoCount;
		
		// find muzzle flash particle systems
		for (int f=0; f < exits.Length; f++) {
			if ( exits[f].transform.childCount == 1 ) { // check for child
				exits[f].flare = exits[f].transform.GetChild(0).gameObject;
				exits[f].particleComponent = exits[f].flare.GetComponent<ParticleSystem>();
				exits[f].particleComponent.Stop(true);
			}
		}
	}
示例#29
0
 public void Init(FastPool pool)
 {
     this.pool = pool;
 }
示例#30
0
 /// <summary>
 /// Destroys provided pool and it's cached objects
 /// </summary>
 /// <param name="pool">Pool to destroy</param>
 public void DestroyPool(FastPool pool)
 {
     pool.ClearCache();
     DestroyPoolFactory(pool.ID);
     m_pools.Remove(pool.ID);
 }
示例#31
0
        public void FastDestroy(int InstanceID, GameObject sceneObject)
        {
            FastPool fastPool = GetPool(InstanceID);

            fastPool.FastDestroy(sceneObject);
        }
示例#32
0
 public static void FastDestroy(this GameObject objectToDestroy, FastPool pool)
 {
     pool.FastDestroy(objectToDestroy);
 }
示例#33
0
 public override void Emit(Ball ball, FastPool pool, Vector2 force, float delay)
 {
     base.Emit(ball, pool, force, delay);
     StartCoroutine(EmitRoutine(delay));
 }
示例#34
0
        public void FastDestroy <T>(int InstanceID, T sceneObject) where T : Component
        {
            FastPool fastPool = GetPool(InstanceID);

            fastPool.FastDestroy(sceneObject);
        }