Пример #1
0
    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);
    }
Пример #2
0
    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();
    }
Пример #3
0
    public static XBulletComponent GetBullet(int id)
    {
        XBulletComponent bullet = null;

        Instance._bulletMap.TryGetValue(id, out bullet);
        return(bullet);
    }
Пример #4
0
    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);
    }
Пример #5
0
    public void RegisterBullet(XBulletComponent bullet)
    {
        if (_bullets.Contains(bullet))
        {
            return;
        }

        _bullets.Add(bullet);
    }
Пример #6
0
    public void UnRegisterBullet(XBulletComponent bullet)
    {
        if (!_bullets.Contains(bullet))
        {
            return;
        }

        _bullets.Remove(bullet);
    }
Пример #7
0
 private void AddBulletMap(XBulletComponent bullet)
 {
     if (bullet == null)
     {
         return;
     }
     bullet.gid = _effectGlobalId++;
     _bulletMap.Add(bullet.gid, bullet);
 }
Пример #8
0
    public void DestroyBulletById(int id)
    {
        XBulletComponent bullet = null;

        _bulletMap.TryGetValue(id, out bullet);
        if (bullet != null)
        {
            DestroyBullet(bullet);
        }
    }
Пример #9
0
    private bool IsWarningAttack(XBulletComponent bc, XBoxComponent hard)
    {
        XBoxRect box = bc.GetBulletWarningBox();

        if (box == null)
        {
            return(false);
        }

        return(_InternalWarningAttack(box, hard));
    }
Пример #10
0
    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);
        }
    }
Пример #11
0
 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);
             }
         }
     }
 }
Пример #12
0
    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);;
    }
Пример #13
0
 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();
 }
Пример #14
0
    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();
    }
Пример #15
0
    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;
        }
    }
Пример #16
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();
    }
Пример #17
0
 public void AddDestroyBullet(XBulletComponent bullet)
 {
     _destroyMap.Add(bullet);
 }