示例#1
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);
    }
示例#2
0
    public void MakeOneShot(RectTransform center, BulletCache cache)
    {
        float targetPoint;

        if (times % 2 == 0)
        {
            var half = times / 2;
            targetPoint = center.anchoredPosition.x - (distanceInterval / 2 + distanceInterval * (half - 1));
        }
        else
        {
            var half = (times - 1) / 2;
            targetPoint = center.anchoredPosition.x - (distanceInterval * half);
        }
        var bulletList = new List <Bullet>();

        for (int i = 0; i < times; ++i)
        {
            var bullet = cache.GetBullet();
            bullet.SwitchBulletImage(false);
            bullet.BulletRect.anchoredPosition = new Vector2(targetPoint, center.anchoredPosition.y + centerDistance);
            targetPoint += distanceInterval;
            bulletList.Add(bullet);
        }
        foreach (var bullet in bulletList)
        {
            bullet.BulletRigidbody2D.velocity = Vector2.up * speed;
        }
    }
示例#3
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);
    }
示例#4
0
 private void DestroyCurFrame()
 {
     Time.timeScale      = 1;
     BaseScene.TimeScale = 1;
     EffectCache.Clear();
     BulletCache.Clear();
     Global.gApp.gResMgr.UnLoadAssets();
     if (m_FrameCtrl != null)
     {
         m_FrameCtrl.OnDestroy();
         m_FrameCtrl = null;
     }
     Time.timeScale = 1;
 }
示例#5
0
 public IEnumerator MakeUzumaki(RectTransform center, BulletCache cache, int times, Action action)
 {
     for (int i = 0; i < times; i++)
     {
         var deg = 0f;
         while (deg < fullAngle)
         {
             var rad    = deg * Mathf.Deg2Rad;
             var cos    = Mathf.Cos(rad);
             var sin    = Mathf.Sin(rad);
             var bullet = cache.GetBullet();
             bullet.SwitchBulletImage(true);
             bullet.BulletRect.anchoredPosition = new Vector2(center.anchoredPosition.x + radius * cos, center.anchoredPosition.y + radius * sin);
             bullet.BulletRigidbody2D.velocity  = (bullet.BulletRect.anchoredPosition - center.anchoredPosition).normalized * speed;
             deg += degInterval;
             yield return(new WaitForSeconds(makeInterval));
         }
     }
     action?.Invoke();
 }
示例#6
0
    private IEnumerator DoPreloadBulletPrefabs(string[] resList, System.Action <bool> callback)
    {
        List <string> resLoad = new List <string>();

        for (int i = 0; i < resList.Length; i++)
        {
            string      effectPath  = resList[i];
            BulletCache bulletCache = null;
            TryGetBulletCache(effectPath, out bulletCache);
            if (bulletCache == null)
            {
                bulletCache = new BulletCache();
                AddBulletCache(effectPath, bulletCache);
            }

            if (!bulletCache.loading)
            {
                bulletCache.loading = true;
                resLoad.Add(effectPath);
            }
        }

        yield return(XRes.LoadMultiAsync(resLoad.ToArray(), delegate(Object[] obj) {
            for (int i = 0; i < obj.Length; i++)
            {
                BulletCache bulletCache = null;
                if (TryGetBulletCache(resLoad[i], out bulletCache))
                {
                    bulletCache.prefab = obj[i] as GameObject;
                    bulletCache.queue = new Queue <XBulletComponent>();
                    bulletCache.loading = false;
                }
            }

            if (callback != null)
            {
                callback(true);
            }
        }));
    }
示例#7
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;
        }
    }
示例#8
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();
    }
示例#9
0
 public void Initialize(BulletCache bulletCache, RectTransform background)
 {
     this.bulletCache = bulletCache;
     this.background  = background;
 }
示例#10
0
 private bool TryGetBulletCache(string path, out BulletCache bulletCache)
 {
     return(TryGetCache <BulletCache>(_bulletCacheList, path, out bulletCache));
 }
示例#11
0
 private void AddBulletCache(string path, BulletCache cache)
 {
     AddCache <BulletCache>(_bulletCacheList, _maxBulletCacheCount, path, cache);
     ReleaseAllBulletQueueInCacheByTimeThreshold();
 }