LoadAsync() public method

public LoadAsync ( string name, Type type ) : AssetBundleRequest
name string
type Type
return AssetBundleRequest
Ejemplo n.º 1
0
    void OnAssetBundleLoaded(string url, AssetBundle assetBundle, params object[] args)
    {
        Object asset = null;
        System.DateTime beginTime = System.DateTime.Now;
        if (AssetInBundleName == null)
        {
            // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
            try
            {
                asset = assetBundle.mainAsset;
            }
            catch
            {
                CBase.LogError("[OnAssetBundleLoaded:mainAsset]{0}", url);
            }
        }
        else
        {
            AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object));
            asset = request.asset;
        }

        CResourceManager.LogLoadTime("AssetFileBridge", url, beginTime);

        if (asset == null)
        {
            CBase.LogError("Asset is NULL: {0}", url);
        }

        AssetFileLoadedCallback(asset, CallbackArgs);
    }
Ejemplo n.º 2
0
    private void BundleLoadedHandler(WWW request)
    {
        Debug.Log("Bundle loaded: " + request.url);
        _bundle = request.assetBundle;

        AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
        _assetBundleQueue.Send(assetBundleRequest, AssetLoadedHandler);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Begin load
    /// </summary>
    /// <param name="asset"></param>
    /// <param name="resName"></param>
    /// <returns></returns>
    public IEnumerator GoLoader(AssetBundle asset, string resName)
    {
        this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object));

        for (; !this.m_cRequest.isDone; )
            yield return this.m_cRequest;

        GameObject.Destroy(this.gameObject);
    }
Ejemplo n.º 4
0
 static int LoadAsync(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.AssetBundle obj      = (UnityEngine.AssetBundle)ToLua.CheckObject(L, 1, typeof(UnityEngine.AssetBundle));
         string      arg0                 = ToLua.CheckString(L, 2);
         System.Type arg1                 = (System.Type)ToLua.CheckObject(L, 3, typeof(System.Type));
         UnityEngine.AssetBundleRequest o = obj.LoadAsync(arg0, arg1);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 5
0
 static public int LoadAsync(IntPtr l)
 {
     try{
         UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
         System.String           a1;
         checkType(l, 2, out a1);
         System.Type a2;
         checkType(l, 3, out a2);
         UnityEngine.AssetBundleRequest ret = self.LoadAsync(a1, a2);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int LoadAsync(IntPtr l)
 {
     try {
         UnityEngine.AssetBundle self = (UnityEngine.AssetBundle)checkSelf(l);
         System.String           a1;
         checkType(l, 2, out a1);
         System.Type a2;
         checkType(l, 3, out a2);
         var ret = self.LoadAsync(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 7
0
    // ReSharper restore InconsistentNaming
    // ReSharper restore UnusedMember.Local
    // ReSharper disable UnusedMember.Local
    // ReSharper disable InconsistentNaming
    void OnGUI()
    {
        // classic OnGUI
        GUI.depth = 0;
        if (GUI.Button(new Rect(10, 10, 100, 50), _progress == 0 ? "Load" : "Loading: " + _progress + "%"))
        {
            // reset queues
            _bundleQueue.Reset();
            _assetBundleQueue.Reset();

            // destroy old object
            if (null != _object)
                Destroy(_object);

            // unload old bundle
            if (null != _bundle)
                _bundle.Unload(true);

            // load bundle
            _bundleQueue.Send(new WWW(BundleUrl),
                delegate(WWW request)
                {
                    Debug.Log("Bundle loaded: " + request.url);
                    _bundle = request.assetBundle;

                    AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
                    _assetBundleQueue.Send(assetBundleRequest,
                        delegate(AssetBundleRequest request2)
                        {
                            Debug.Log("Asset loaded: " + request2.asset.name);
                            _object = (GameObject)Instantiate(request2.asset);

                            // add mouse orbit
                            GameObject cameraGo = GameObject.Find("Main Camera");
                            if (null != cameraGo)
                            {
                                MouseOrbitCs mouseOrbit = cameraGo.AddComponent<MouseOrbitCs>();
                                mouseOrbit.Target = _object.transform;
                            }
                        }
                    );
                }
            );
        }
    }
Ejemplo n.º 8
0
        //Begin to load
        private IEnumerator GoLoader(AssetBundle asset, string resName , FINISH_CALLBACK finish_callback)
        {
            this.m_delFinishCallback = finish_callback;
            this.m_fProgress = 0;
            this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object));

            for (; !this.m_cRequest.isDone; )
            {
                this.m_fProgress = this.m_cRequest.progress;
                yield return new WaitForEndOfFrame();
            }
            this.m_fProgress = 1;

            if(this.m_delFinishCallback != null)
            {
                this.m_delFinishCallback(resName , this.m_cRequest.asset);
            }

            GameObject.Destroy(this.gameObject);
        }
Ejemplo n.º 9
0
        static IEnumerator AsyncLoadAsset(AssetBundle bundle, Action<UnityObject> onFinish, String path)
        {
            if (EnablePauseFlag)
            {
                if (path.EndsWith(".png.u3dext") || path.EndsWith(".tga.u3dext") || path.EndsWith(".bytes.u3dext") || path.EndsWith(".mp3.u3dext"))
                {
                    while (GetPauseFlag())
                        yield return null;

                    Debug.LogWarning(path);
                    EntryPoint.DebugString = path;
                }
            }

            ////checkres(path, typeof(Texture), 0);
			CheckDependBundlesInCache(path);
            AssetBundleRequest request = bundle.LoadAsync("1", typeof(UnityObject));
            if (request == null)
            {
				Debug.LogWarning("Failed to LoadAsync with name '1' from: " + path);

                if (onFinish != null)
                    onFinish(null);
                yield break;
            }

            while (!request.isDone)
                yield return null;

			UnityObject asset = request.asset;
			if (asset == null)
				Debug.LogWarning("LoadAsync with name '1' return null:" + path);

			if (m_bEnableLog)
				Log("AsyncLoadAsset finish: " + path + "@ " + Time.realtimeSinceStartup);

            if (onFinish != null)
                onFinish(asset);
        }
Ejemplo n.º 10
0
		private IEnumerator NewLoadBGElement ()
		{
				string path = Application.dataPath + "/Bundle/BGElement";
				AssetBundle ab = new AssetBundle ();
				AssetBundleRequest abr = ab.LoadAsync (path, typeof(GameObject));
				yield return abr;
				GameObject newCube = Instantiate (abr.asset) as GameObject;
		}
    public IEnumerator LoadAssetsFromBundleAsync(AssetBundle bundle, string[] names)
    {
        objects = new List<Object>();

        foreach (var name in names)
        {
            AssetBundleRequest request = bundle.LoadAsync(name, typeof(UnityEngine.Object));

            yield return request;
            UnityEngine.Object obj = request.asset;
            TryAddAsset(name, obj, objects);

        }
    }
    public IEnumerator LoadAssetsFromBundleSimultaneouslyAsync(AssetBundle bundle, string[] names, int nAssets)
    {
        objects = new List<Object>();
        List<AssetBundleRequest> requests = new List<AssetBundleRequest>();

        for (int i = 0; i < names.Length; i++)
        {
            string name = names[i];
            requests.Add(bundle.LoadAsync(name, typeof(Object)));

            if (requests.Count == nAssets || i == names.Length - 1)
            {
                while (!AreAssetsLoaded(requests))
                {
                    yield return null;
                }
                foreach (var request in requests)
                {
                    Object obj = request.asset;
                    TryAddAsset(obj.name, obj, objects);
                }
                Debug.Log("Loaded " + requests.Count + " assets from the bundle");
                requests = new List<AssetBundleRequest>();
            }
        }
    }
Ejemplo n.º 13
0
        static IEnumerator AyncLoadAsset(AssetBundle bundle, Action<UnityObject> onFinish, String path)
        {
			CheckDependBundlesInCache(path);
            AssetBundleRequest request = bundle.LoadAsync("1", typeof(UnityObject));
            if (request == null)
            {
                if (onFinish != null)
                    onFinish(null);
                yield break;
            }

            while (!request.isDone)
                yield return null;

            if (onFinish != null)
                onFinish(request.asset);
        }
Ejemplo n.º 14
0
    /// <summary>
    /// In this function we can do whatever we want with the freshly downloaded bundle.
    /// In this example we will cache it for later use, and we will load a texture from it.
    /// </summary>
    IEnumerator ProcessAssetBundle(AssetBundle bundle)
    {
        if (bundle == null)
            yield break;

        // Save the bundle for future use
        cachedBundle = bundle;

        // Start loading the asset from the bundle
        var asyncAsset = 
#if UNITY_5
            cachedBundle.LoadAssetAsync("9443182_orig", typeof(Texture2D));
#else
        
            cachedBundle.LoadAsync("9443182_orig", typeof(Texture2D));
#endif

        // wait til load
        yield return asyncAsset;

        // get the texture
        texture = asyncAsset.asset as Texture2D;
    }