Ejemplo n.º 1
0
        public IEnumerator CheckOutAsync <T>(string name, System.Action <T> callback, bool forceLoad = false) where T : class
        {
                        #if ASSET_BUNDLE
            if (GameSystemManager.Get <AssetBundleManager>().IsAssetBundle(name))
            {
                yield return(StartCoroutine(CheckOutAssetBundleAsync <T>(name, callback, forceLoad)));
            }
                        #endif

            if (forceLoad)
            {
                yield return(StartCoroutine(LoadResourceAsync(name)));
            }

            Resource res = null;

            if (m_resources.ContainsKey(name))
            {
                res = m_resources[name];
                res.CheckoutCount++;
            }

            if (callback != null)
            {
                callback((T)res.Res);
            }
        }
Ejemplo n.º 2
0
        public IEnumerator LoadResourceAsync(string name)
        {
                        #if ASSET_BUNDLE
            if (GameSystemManager.Get <AssetBundleManager>().IsAssetBundle(name))
            {
                yield return(StartCoroutine(LoadAssetBundleAsync(name)));
            }
                        #endif

            if (m_resources.ContainsKey(name))
            {
                yield break;
            }

            ResourceRequest resourceRequest = Resources.LoadAsync(name);

            while (!resourceRequest.isDone)
            {
                yield return(0);
            }

            Resource res = new Resource();
            res.Res           = (object)resourceRequest.asset;
            res.CheckoutCount = 0;

            if (res.Res == null)
            {
                Debug.LogError("[ResourceManager] - Failed to find resource '" + name + "'");
            }

            m_resources[name] = res;
        }
Ejemplo n.º 3
0
        public IEnumerator LoadAssetBundleAsync(string assetPath)
        {
            if (m_resources.ContainsKey(assetPath))
            {
                yield break;
            }

            string assetName = assetPath.Split('/') [assetPath.Split('/').Length - 1];

            Debug.LogWarning(string.Format("Start to load asset \"{0}\" at frame {1}", assetName, Time.frameCount));

            // Load asset from assetBundle.
            AssetBundleLoadAssetOperation request = GameSystemManager.Get <AssetBundleManager>().LoadAssetAsync(assetPath.ToLower() + ".assetbundle", assetName, typeof(Object));

            if (request == null)
            {
                yield break;
            }
            yield return(StartCoroutine(request));

            // Get the asset.
            Object asset = request.GetAsset <Object> ();

            Debug.LogWarning(string.Format("{0} to load asset \"{1}\" at frame {2}", asset == null ? "Failed" : "Succeeded", assetName, Time.frameCount));

            Resource res = new Resource();

            res.Res           = (object)asset;
            res.CheckoutCount = 0;

            if (res.Res == null)
            {
                Debug.LogError("[ResourceManager] - Failed to find resource '" + assetName + "'");
            }

            m_resources[assetPath] = res;
        }
Ejemplo n.º 4
0
        public IEnumerator LoadResourceAsync(string name, System.Action <string> callback)
        {
                        #if ASSET_BUNDLE
            if (GameSystemManager.Get <AssetBundleManager>().IsAssetBundle(name))
            {
                yield return(StartCoroutine(LoadAssetBundleAsync(name, callback)));
            }
                        #endif

            yield return(StartCoroutine(LoadResourceAsync(name)));

            Resource res = null;

            if (m_resources.ContainsKey(name))
            {
                res = m_resources[name];
                res.CheckoutCount++;
            }

            if (callback != null)
            {
                callback(name);
            }
        }
Ejemplo n.º 5
0
        //Removes all resources that aren't checkout out
        public void Clean()
        {
            List <string> itemsToRemove = new List <string>();

            foreach (KeyValuePair <string, Resource> kvp in m_resources)
            {
                if (kvp.Value.CheckoutCount <= 0)
                {
                    itemsToRemove.Add(kvp.Key);
                }
            }


            foreach (string key in itemsToRemove)
            {
                m_resources.Remove(key);
                                #if ASSET_BUNDLE
                GameSystemManager.Get <AssetBundleManager>().UnloadAssetBundle(key);
                                #endif
            }

            Resources.UnloadUnusedAssets();
            System.GC.Collect();
        }