Exemple #1
0
    private IEnumerator GetEffect(string effectPath, System.Action <XEffectCache, XEffectComponent> callback)
    {
        XEffectCache     effectCache = null;
        XEffectComponent effect      = null;

        TryGetEffectCache(effectPath, out effectCache);
        if (effectCache == null)
        {
            effectCache         = new XEffectCache();
            effectCache.loading = true;
            AddEffectCache(effectPath, effectCache);

            yield return(XRes.LoadAsync <GameObject>(effectPath, delegate(Object obj) {
                effectCache.queue = new Queue <XEffectComponent>();
                effectCache.prefab = obj as GameObject;
                effectCache.loading = false;
            }));
        }

        while (effectCache.loading)
        {
            yield return(null);
        }

        if (effectCache.prefab != null)
        {
            effect = GenerateEffect(effectPath, effectCache);
        }

        callback(effectCache, effect);
    }
Exemple #2
0
    public void DestroyEffect(XEffectComponent effect, bool destroyed = false)
    {
        if (effect == null)
        {
            return;
        }

        if (!destroyed)
        {
            XEffectCache effectCache = null;
            TryGetEffectCache(effect.resPath, out effectCache);
            if (effectCache != null)
            {
                if (effectCache.queue == null)
                {
                    effectCache.queue = new Queue <XEffectComponent>();
                }
                effectCache.queue.Enqueue(effect);
                effect.transform.parent = objectContainer;
                effect.gameObject.SetActive(false);
            }
            else if (effect.gameObject != null)
            {
                GameObject.Destroy(effect.gameObject);
            }
        }

        if (effect.gid > 0)
        {
            _map.Remove(effect.gid);
            effect.gid = 0;
            RemoveEffectCount(effect.resPath);
        }
    }
Exemple #3
0
    private IEnumerator GetEffect(GameObject effectPrefab, System.Action <XEffectCache, XEffectComponent> callback)
    {
        XEffectCache     effectCache = null;
        XEffectComponent effect      = null;

        string effectPath = effectPrefab.name;

        TryGetEffectCache(effectPath, out effectCache);
        if (effectCache == null)
        {
            effectCache         = new XEffectCache();
            effectCache.loading = true;
            AddEffectCache(effectPath, effectCache);

            effectCache.queue   = new Queue <XEffectComponent>();
            effectCache.prefab  = effectPrefab;
            effectCache.loading = false;
        }

        while (effectCache.loading)
        {
            yield return(null);
        }

        if (effectCache.prefab != null)
        {
            effect = GenerateEffect(effectPath, effectCache);
        }

        callback(effectCache, effect);
    }
Exemple #4
0
    private void DoGenerateAsync(string effectPath, System.Action <XEffectCache, XEffectComponent> callback)
    {
        XEffectCache effectCache = null;

        TryGetEffectCache(effectPath, out effectCache);

        if (effectCache != null && !effectCache.loading)
        {
            callback(effectCache, GenerateEffect(effectPath, effectCache));
        }
        else
        {
            XCoroutine.Run(GetEffect(effectPath, callback));
        }
    }
Exemple #5
0
    private bool CheckReleaseQueueInCacheByTimeThreshold(XEffectCache cache, float timeThreshold)
    {
        bool canEnqueue = true;

        if ((Time.time - cache.createTime) > timeThreshold && cache.queue != null)
        {
            while (cache.queue.Count > _maxEffectQueueCount)
            {
                XEffectComponent efc = cache.queue.Dequeue();
                GameObject.Destroy(efc.gameObject);
                canEnqueue = false;
            }
        }
        return(canEnqueue);
    }
Exemple #6
0
    private IEnumerator DoPreloadEffectPrefabs(string[] resList, System.Action <bool> callback)
    {
        List <string> resLoad = new List <string>();

        for (int i = 0; i < resList.Length; i++)
        {
            string       effectPath  = resList[i];
            XEffectCache effectCache = null;
            TryGetEffectCache(effectPath, out effectCache);
            if (effectCache == null)
            {
                effectCache = new XEffectCache();
                AddEffectCache(effectPath, effectCache);
            }

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

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

            if (callback != null)
            {
                callback(true);
            }
        }));
    }
Exemple #7
0
    private XEffectComponent GenerateEffect(string effectPath, XEffectCache effectCache)
    {
        XEffectComponent effect = null;

        if (effectCache.queue.Count > 0)
        {
            effect = effectCache.queue.Dequeue();
            if (effect == null || effect.gameObject == null)
            {
                effect = null;
            }
            else
            {
                effect.gameObject.SetActive(true);
            }
        }
        else
        {
            if (effectCache.prefab == null)
            {
                RemoveCache <XEffectCache>(_cacheList, effectCache);
                return(null);
            }

            if (!CanEffectInstantial(effectPath))
            {
                return(null);
            }

            GameObject obj = GameObject.Instantiate(effectCache.prefab) as GameObject;
            effect = obj.GetComponent <XEffectComponent>();
            if (effect != null)
            {
                effect.resPath = effectPath;
            }
        }

        AddEffectMap(effect);
        return(effect);
    }
Exemple #8
0
 private bool CheckReleaseQueueInCacheByTimeThreshold(XEffectCache cache)
 {
     return(CheckReleaseQueueInCacheByTimeThreshold(cache, _effectQueueTimeThreshold));
 }
Exemple #9
0
 // get cache
 private bool TryGetEffectCache(string path, out XEffectCache effectCache)
 {
     return(TryGetCache <XEffectCache>(_cacheList, path, out effectCache));
 }
Exemple #10
0
 //add cache
 private void AddEffectCache(string path, XEffectCache cache)
 {
     AddCache <XEffectCache>(_cacheList, _maxEffectCacheCount, path, cache);
     ReleaseAllEffectQueueInCacheByTimeThreshold();
 }