private XBulletComponent GenerateBullet(string bulletPath, BulletCache bulletCache) { XBulletComponent bullet = null; if (bulletCache.queue.Count > 0) { bullet = bulletCache.queue.Dequeue(); bullet.gameObject.SetActive(true); } else { if (bulletCache.prefab == null) { RemoveCache <BulletCache>(_bulletCacheList, bulletCache); return(null); } GameObject obj = GameObject.Instantiate(bulletCache.prefab) as GameObject; bullet = obj.GetComponent <XBulletComponent>(); if (bullet != null) { bullet.resPath = bulletPath; } } AddBulletMap(bullet); return(bullet); }
public void ClearQueueInCache() { for (int i = 0; i < _cacheList.Count; i++) { if (_cacheList[i].queue != null) { while (_cacheList[i].queue.Count > 0) { XEffectComponent eff = _cacheList[i].queue.Dequeue(); if (eff != null && eff.gameObject != null) { GameObject.Destroy(eff.gameObject); } } } } for (int i = 0; i < _bulletCacheList.Count; i++) { if (_bulletCacheList[i].queue != null) { while (_bulletCacheList[i].queue.Count > 0) { XBulletComponent eff = _bulletCacheList[i].queue.Dequeue(); if (eff != null && eff.gameObject != null) { GameObject.Destroy(eff.gameObject); } } } } _currentEffectCountDic.Clear(); }
public static XBulletComponent GetBullet(int id) { XBulletComponent bullet = null; Instance._bulletMap.TryGetValue(id, out bullet); return(bullet); }
private IEnumerator GetBullet(string bulletPath, System.Action <XBulletComponent> callback) { BulletCache bulletCache = null; XBulletComponent bullet = null; TryGetBulletCache(bulletPath, out bulletCache); if (bulletCache == null) { bulletCache = new BulletCache(); bulletCache.loading = true; AddBulletCache(bulletPath, bulletCache); yield return(XRes.LoadAsync <GameObject>(bulletPath, delegate(Object obj) { bulletCache.queue = new Queue <XBulletComponent>(); bulletCache.prefab = obj as GameObject; bulletCache.loading = false; })); } while (bulletCache.loading) { yield return(null); } if (bulletCache.prefab != null) { bullet = GenerateBullet(bulletPath, bulletCache); } callback(bullet); }
public void RegisterBullet(XBulletComponent bullet) { if (_bullets.Contains(bullet)) { return; } _bullets.Add(bullet); }
public void UnRegisterBullet(XBulletComponent bullet) { if (!_bullets.Contains(bullet)) { return; } _bullets.Remove(bullet); }
private void AddBulletMap(XBulletComponent bullet) { if (bullet == null) { return; } bullet.gid = _effectGlobalId++; _bulletMap.Add(bullet.gid, bullet); }
public void DestroyBulletById(int id) { XBulletComponent bullet = null; _bulletMap.TryGetValue(id, out bullet); if (bullet != null) { DestroyBullet(bullet); } }
private bool IsWarningAttack(XBulletComponent bc, XBoxComponent hard) { XBoxRect box = bc.GetBulletWarningBox(); if (box == null) { return(false); } return(_InternalWarningAttack(box, hard)); }
private static void FireBullet(GameObject go, Vector3 dest, XBulletProperty property, System.Func <XBulletComponent, Transform, bool> callback, Transform[] hitTargets) { XBulletComponent bullet = go.GetComponent <XBulletComponent>(); if (bullet != null) { bullet.Fire(dest, property, hitTargets, callback); } else { GameObject.Destroy(go); } }
private void ReleaseAllBulletQueueInCacheByTimeThreshold() { for (int i = 0; i < _bulletCacheList.Count; i++) { if ((Time.time - _bulletCacheList[i].createTime) > _bulletQueueTimeThreshold && _bulletCacheList[i].queue != null) { while (_bulletCacheList[i].queue.Count > _maxBullectQueueCount) { XBulletComponent efc = _bulletCacheList[i].queue.Dequeue(); GameObject.Destroy(efc.gameObject); } } } }
private void AddBulletHero(XBulletComponent bullet, Transform trans) { XBulletHero bh = _bulletHeroes.Find(delegate(XBulletHero obj) { return(obj.Bullet == bullet); }); if (bh == null) { bh = new XBulletHero(); bh.Bullet = bullet; _bulletHeroes.Add(bh); } bh.TransList.Add(trans);; }
public override void Release() { if (queue != null) { while (queue.Count > 0) { XBulletComponent efc = queue.Dequeue(); if (efc != null && efc.gameObject != null) { GameObject.Destroy(efc.gameObject); } } queue.Clear(); queue = null; } base.Release(); }
public void BulletFixedUpdate(float fFixedDeltaTime) { foreach (KeyValuePair <int, XBulletComponent> it in _bulletMap) { it.Value.ForceFixedUpdate(fFixedDeltaTime); } for (int i = 0; i < _destroyMap.Count; i++) { XBulletComponent bullet = _destroyMap[i]; if (bullet != null) { DestroyBullet(bullet); } } _destroyMap.Clear(); }
public void DestroyBullet(XBulletComponent bullet) { BulletCache bulletCache = null; TryGetBulletCache(bullet.resPath, out bulletCache); if (bulletCache != null) { bulletCache.queue.Enqueue(bullet); bullet.transform.parent = objectContainer; bullet.gameObject.SetActive(false); } else if (bullet.gameObject != null) { GameObject.Destroy(bullet.gameObject); } if (bullet.gid > 0) { _bulletMap.Remove(bullet.gid); bullet.gid = 0; } }
public static void DestroyAllBullet() { foreach (KeyValuePair <int, XBulletComponent> entry in Instance._bulletMap) { XBulletComponent bullet = entry.Value; BulletCache bulletCache = null; Instance.TryGetBulletCache(bullet.resPath, out bulletCache); if (bulletCache != null) { bulletCache.queue.Enqueue(bullet); bullet.transform.parent = Instance.objectContainer; bullet.gameObject.SetActive(false); } else { GameObject.Destroy(bullet.gameObject); } bullet.gid = 0; } Instance._bulletMap.Clear(); }
public void AddDestroyBullet(XBulletComponent bullet) { _destroyMap.Add(bullet); }