Example #1
0
        public override IEnumerator Load()
        {
            SuitAsset Suit       = mInstance.mCurrentLoading as SuitAsset;
            Exosuit   suitToLoad = GameData.getExosuit(Suit.mSuitID);

            myWWW = new WWW(GameData.BUNDLE_PATH + Suit.myFilename);
            // Logger.trace("LoadSuitAsset " + myWWW.url);
            yield return(myWWW);

            if (myWWW.error == null)
            {
                yield return(myWWW);

                if (myWWW == null)
                {
                    Logger.trace("www is null");
                    yield break;
                }
                if (myWWW.assetBundle != null)
                {
                    AssetBundle        assetBundle = myWWW.assetBundle;
                    string             fileName    = suitToLoad.mSuitFileName;
                    AssetBundleRequest abr4        = assetBundle.LoadAsync(fileName + "_" + Suit.mModelType + "_pre", typeof(GameObject));
                    yield return(abr4);

                    GameObject suitModel = abr4.asset as GameObject;
                    if (Suit.mModelType == SuitType.low)
                    {
                        string textureName = fileName + "_sheet_1";
                        abr4 = assetBundle.LoadAsync(textureName, typeof(Material));
                        yield return(abr4);

                        GameData.setLowPolySuitIsLoaded(texture: abr4.asset as Material, suitId: Suit.mSuitID, model: suitModel);
                    }
                    else
                    {
                        object[] arry  = assetBundle.LoadAll();
                        object[] array = arry;
                        foreach (object obj in array)
                        {
                            if (obj is Texture2D)
                            {
                            }
                            abr4 = assetBundle.LoadAsync(fileName + "_mask_1", typeof(Material));
                            yield return(abr4);

                            Material MaskMat = abr4.asset as Material;
                            abr4 = assetBundle.LoadAsync(fileName + "_armor_1", typeof(Material));
                            yield return(abr4);

                            GameData.setHighPolySuitIsLoaded(armor: abr4.asset as Material, suitId: Suit.mSuitID, model: suitModel, mask: MaskMat);
                        }
                    }
                    assetBundle.Unload(unloadAllLoadedObjects: false);
                }
            }
            mInstance.mCurrentLoading = null;
        }
Example #2
0
        IEnumerator AsyncAb(string filename, Action <UObj, string> finished)
        {
            yield return(null);

            bool cached = false;
            UObj obj    = lstRefAsset.Get(filename);

            cached = obj != null;

            if (!cached)
            {
                //TODO : 后期合成真实的本地路劲
                string      path  = ResourceSetting.ConvertToABPath(filename);
                AssetBundle asset = AssetBundle.CreateFromFile(path);

                AssetBundleRequest request = asset.LoadAsync(filename, typeof(UObj));
                yield return(request);

                //加入引用列表的同时,释放资源
                releaseRes(lstRefAsset.Add(filename, request.asset));
                obj = request.asset;
            }

            if (finished != null)
            {
                finished(obj, filename);
            }
        }
Example #3
0
    IEnumerator LoadLevelName(string level)
    {
        //加载场景
        string url = Util.DataPath + "Scene/" + level + ".unity3d";

        AssetBundle bundle = SimpleFramework.Util.LoadSceneAssetBundle(url);

        if (bundle == null)
        {
            yield break;
        }

        //loadAsync
        AssetBundleRequest req = bundle.LoadAsync(level, typeof(Object));

        while (req.isDone == false)
        {
            yield return(null);
        }

        Object asset = req.asset;

        yield return(Application.LoadLevelAsync(level));

        Debug.Log(level);
    }
    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>();
            }
        }
    }
Example #5
0
    private IEnumerator WaitForPickupRequest(WWW www)
    {
        yield return(www);

        if (www.error == null)
        {
            yield return(www);

            AssetBundle assetBundle = www.assetBundle;
            string[]    pickupList  = GameData.PickupList;
            Logger.trace("<< num pickups: " + pickupList.Length);
            foreach (string str in pickupList)
            {
                AssetBundleRequest abr = assetBundle.LoadAsync(str, typeof(GameObject));
                yield return(abr);

                GameData.Pickups.Add(abr.asset as GameObject);
            }
            mStatus         += "  ... Pickups Loaded!";
            mBundleIsLoading = false;
        }
        else
        {
            Logger.trace("Pickup List Failed " + www.error);
        }
    }
Example #6
0
    private IEnumerator WaitForLowSuitsRequest(WWW www)
    {
        yield return(www);

        if (www.error == null)
        {
            yield return(www);

            Logger.trace("<< Loading Suits . . .");
            AssetBundle          assetBundle = www.assetBundle;
            UnityEngine.Object[] suits       = assetBundle.LoadAll(typeof(GameObject));
            for (int i = 0; i < suits.Length; i++)
            {
                foreach (Exosuit Suit in GameData.MasterSuitList.Values)
                {
                    if (suits[i].name.Contains(Suit.mSuitFileName))
                    {
                        string             textureName = Suit.mSuitFileName + "_sheet_1";
                        AssetBundleRequest abr         = assetBundle.LoadAsync(textureName, typeof(Material));
                        yield return(abr);

                        GameData.setLowPolySuitIsLoaded(texture: abr.asset as Material, suitId: Suit.mSuitId, model: suits[i] as GameObject);
                    }
                }
            }
            mStatus         += " ... Suits Loaded!";
            mBundleIsLoading = false;
        }
    }
Example #7
0
        public IEnumerator preloadAsync(string resourceName, System.Type type)
        {
            var obj = loadChecking(resourceName, type);

            if (obj != BundleLoadManager.Instance)
            {
                yield break;
            }

            //从AssetBundle中加载资源并且缓存起来
            var _asyncOp = assetBundle.LoadAsync(resourceName, type);

            yield return(_asyncOp);

            if (assetBundle == null)
            {
                yield break;
            }
            obj = _asyncOp.asset;
            if (obj == null)
            {
#if UNITY_EDITOR
                Debug.LogError("加载资源失败,AssetBundle(" + assetBundle + ")中并不包含资源:" + resourceName + "(" + type.Name + ")");
#else
                Debug.LogError("Load resource:" + resourceName + "(" + type.Name + ") from AssetBundle(" + assetBundle + ")got a null value");
#endif
                yield break;
            }
            objects.Add(obj);
        }
Example #8
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);
    }
Example #9
0
    public IEnumerator LoadAssetAsync(string package, string asset, System.Type type, AssetLoadDelegate loadCallBack)
    {
#if UNITY_EDITOR
        if (EditorDirectLoad)
        {
            string assetPath = string.Format("{0}{1}/{2}.prefab", packPath, package, asset);
            Debug.Log(assetPath);
            Object assetObject = Resources.LoadAssetAtPath(assetPath, type);
            loadCallBack(assetObject as GameObject);
            yield break;
        }
#endif
        if (!assetBundleDict.ContainsKey(package))
        {
            yield return(StartCoroutine(LoadAssetBundle(package)));
        }

        AssetBundle assetBundle = null;
        assetBundleDict.TryGetValue(package, out assetBundle);
        if (assetBundle == null)
        {
            yield break;
        }

        AssetBundleRequest asyncRequest = assetBundle.LoadAsync(asset, type);
        yield return(asyncRequest);

        loadCallBack(asyncRequest.asset);
    }
Example #10
0
        public static IEnumerator LoadAsyncFromAssetBundle(AssetBundle assetbundle, string name, System.Type type, HandleFinishLoadAsyncFromAssetBundle handle)
        {
            AssetBundleRequest request = assetbundle.LoadAsync(name, type);

            yield return(request);

            handle(request);
        }
    private IEnumerator WaitForSuitRequest(WWW www, Exosuit suit, string model_type)
    {
        yield return(www);

        float LastProgress = 0f;

        loadProgress -= LastProgress;
        LastProgress  = (float)www.size * www.progress;
        loadProgress += LastProgress;
        Logger.trace("my load progress = " + loadProgress);
        Logger.trace("WWW load progress = " + www.progress);
        if (www.error == null)
        {
            yield return(www);

            AssetBundle assetBundle = www.assetBundle;
            string      fileName    = suit.mSuitFileName;
            Logger.trace("Load Model : " + fileName + "_" + model_type + "_pre");
            AssetBundleRequest abr2 = assetBundle.LoadAsync(fileName + "_" + model_type + "_pre", typeof(GameObject));
            Logger.trace("loading... " + abr2.progress);
            yield return(abr2);

            GameObject suitModel = abr2.asset as GameObject;
            if (suitModel != null)
            {
                Logger.trace("Model Loaded! " + suitModel.name);
            }
            else
            {
                Logger.trace("Could not load suit");
            }
            string textureName = fileName + "_sheet_1";
            Logger.trace("Load Texture : " + textureName);
            abr2 = assetBundle.LoadAsync(textureName, typeof(Material));
            Logger.trace("loading..." + abr2.progress);
            yield return(abr2);

            Logger.trace("Texture Loaded!");
            GameData.setLowPolySuitIsLoaded(texture: abr2.asset as Material, suitId: suit.mSuitId, model: suitModel);
        }
        else
        {
            Logger.trace("<< there was an error " + www.error);
        }
    }
Example #12
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);
    }
Example #13
0
 protected void downloadDelegate(System.Object obj, AssetBundle asset)
 {
     _resetObject();
     if (asset == null)
     {
         return;
     }
     mAssetLoadRequest = asset.LoadAsync((string)obj, typeof(GameObject));
 }
Example #14
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;
    }
Example #15
0
    IEnumerator LoadGame()
    {
        string path = "file://" + Application.dataPath + "/bundle/PlopBubbles.unity3d";

        using (WWW www = new WWW(path)) {
            yield return(www);

            if (www.error != null)
            {
                throw new Exception("WWW download had an error:" + www.error);
            }

            // load and retrieve the AssetBundle
            AssetBundle bundle = www.assetBundle;

            // load the objects asynchronously
            AssetBundleRequest request = bundle.LoadAsync("bkg", typeof(GameObject));
            yield return(request);

            bkgPrefab = Instantiate(request.asset) as GameObject;

            request = bundle.LoadAsync("ball", typeof(GameObject));
            yield return(request);

            ballPrefab = request.asset as GameObject;

            request = bundle.LoadAsync("particles", typeof(GameObject));
            yield return(request);

            particlesPrefab = request.asset as GameObject;

            request = bundle.LoadAsync("theme", typeof(AudioClip));
            yield return(request);

            themeMusic = request.asset as AudioClip;

            // Unload the AssetBundles compressed contents to conserve memory
            bundle.Unload(false);

            Application.LoadLevel(1);
        }
    }
Example #16
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);
    }
Example #17
0
    private static int LoadAsync(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        AssetBundle        assetBundle = (AssetBundle)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AssetBundle");
        string             luaString   = LuaScriptMgr.GetLuaString(L, 2);
        Type               typeObject  = LuaScriptMgr.GetTypeObject(L, 3);
        AssetBundleRequest o           = assetBundle.LoadAsync(luaString, typeObject);

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Example #18
0
// ReSharper disable UnusedMember.Local
// ReSharper disable InconsistentNaming
    void OnGUI()
// ReSharper restore InconsistentNaming
// ReSharper restore UnusedMember.Local
    { // 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;

#if UNITY_5_0_OR_NEWER || UNITY_2017_1_OR_NEWER
                AssetBundleRequest assetBundleRequest = _bundle.LoadAssetAsync(AssetName, typeof(GameObject));
#else
                AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
#endif
                _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;
                    }
                }
                                       );
            }
                              );
        }
    }
Example #19
0
    static int LoadAsync(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        AssetBundle        obj  = LuaScriptMgr.GetUnityObject <AssetBundle>(L, 1);
        string             arg0 = LuaScriptMgr.GetLuaString(L, 2);
        Type               arg1 = LuaScriptMgr.GetTypeObject(L, 3);
        AssetBundleRequest o    = obj.LoadAsync(arg0, arg1);

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Example #20
0
        private IEnumerator LoadAsset(AssetBundle bundle, XResPackage package, HandleLoadAsset callback)
        {
            this._assetloader = bundle.LoadAsync(base.name, XUpdater.Ass.GetType(package.type));
            yield return(this._assetloader);

            if (callback != null)
            {
                callback(package, this._assetloader.asset);
            }
            this._assetloader = null;
            yield break;
        }
Example #21
0
    private void BundleLoadedHandler(WWW request)
    {
        Debug.Log("Bundle loaded: " + request.url);
        _bundle = request.assetBundle;

#if UNITY_5_0_OR_NEWER || UNITY_2017_1_OR_NEWER
        AssetBundleRequest assetBundleRequest = _bundle.LoadAssetAsync(AssetName, typeof(GameObject));
#else
        AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
#endif
        _assetBundleQueue.Send(assetBundleRequest, AssetLoadedHandler);
    }
Example #22
0
    /// <summary>
    /// грузим музыку
    /// </summary>
    IEnumerator LoadSound()
    {
        WWW www = WWW.LoadFromCacheOrDownload(soundUrl, 1);

        yield return(www);

        AssetBundle bundle = www.assetBundle;

        AssetBundleRequest request = bundle.LoadAsync("Nintendo-Super-Mario-Theme-Song", typeof(AudioClip));

        yield return(request);

        MarioTheme = request.asset as AudioClip;

        request = bundle.LoadAsync("waterballoon", typeof(AudioClip));
        yield return(request);

        PewPew = request.asset as AudioClip;

        bundle.Unload(false);
        www.Dispose();
    }
    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);
        }
    }
Example #24
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;

            GameObject.Destroy(this);
        }
Example #25
0
    /// <summary>
    /// грузим эффект
    /// </summary>
    IEnumerator LoadEffects()
    {
        WWW www = WWW.LoadFromCacheOrDownload(effectUrl, 1);

        yield return(www);

        AssetBundle        bundle  = www.assetBundle;
        AssetBundleRequest request = bundle.LoadAsync("Smoke", typeof(GameObject));

        yield return(request);

        Smoke = request.asset as GameObject;
        bundle.Unload(false);
        www.Dispose();
    }
Example #26
0
    private IEnumerator LoadAsync(string path, AssetFunc callback = null)
    {
        if (GameSetting.isEditorModel)
        {
            loadingList.Add(path);
            string fullpath = FullPath(path);
            Object obj      = Resources.LoadAssetAtPath(fullpath, typeof(Object));
            yield return(obj);

            loadedList[path] = obj;

            if (callback != null)
            {
                callback(loadedList[path]);
            }

            loadingList.Remove(path);
        }
        else
        {
            loadingList.Add(path);
            string fullpath = FullPath(path);

            /*
             * WWW bundle = WWW.LoadFromCacheOrDownload(fullpath, 1);
             * yield return bundle;
             * AssetBundle asset = bundle.assetBundle;
             */
            AssetBundle asset = AssetBundle.CreateFromFile(fullpath);
            yield return(asset);

            AssetBundleRequest req = asset.LoadAsync(GetAssetName(path), typeof(Object));
            yield return(req);

            loadedList[path] = req.asset;
            StartCoroutine(UnloadAssetBundle(asset));
            //bundle = null;

            if (callback != null)
            {
                callback(loadedList[path]);
            }

            loadingList.Remove(path);
        }
    }
Example #27
0
        public override bool ProcessRequest(Request req)
        {
            RequestInternal ireq = (RequestInternal)req;

            string path = GetUnityPath(req.path, false);

            if (!mAssetBundle.Contains(path))
            {
                ireq.Error(ErrorCode.FileNotExist);
                return(false);
            }

            AssetBundleRequest resReq = mAssetBundle.LoadAsync(path, req.type);

            ireq.processor = new RequestProcessBundle(resReq);
            return(true);
        }
Example #28
0
 /// <summary>
 /// 用于检测资源是否加载完成.
 /// </summary>
 /// <returns>
 /// 是否加载完成.
 /// </returns>
 /// <param name='requestSubData'>
 /// 是否有附加数据,一般无附加数据.
 /// </param>
 public bool isDone(bool requestSubData = false)
 {
     if (!requestSubData)
     {
         return(load_type == LOAD_TYPE.LOADED);
     }
     else
     {
         if (null == bundle)
         {
             return(false);
         }
         if (null == subRequest)
         {
             subRequest = bundle.LoadAsync("binddata", typeof(EditorObjectData));
         }
         return(subRequest.isDone);
     }
 }
    public static IEnumerator DownLoadAsset <T>(string url, string assetName, int version, Action <T> OnDownloadComplete) where T : UnityEngine.Object
    {
                #if UNITY_EDITOR
        Caching.CleanCache();
                #endif
        WWW www = WWW.LoadFromCacheOrDownload(url, version);

        // Wait for download to complete
        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            OnDownloadComplete(null);
        }
        else
        {
            // Load and retrieve the AssetBundle
            AssetBundle bundle = www.assetBundle;

            // Load the object asynchronously
            // UnityEngine.Object[] objects = bundle.LoadAll();

            // foreach(var item in objects)
            //	F2ULogManager.F2ULog("Downloaded " + item.name + " of type " + item.GetType().FullName, F2ULogManager.Type.Notice);

            AssetBundleRequest request = bundle.LoadAsync(assetName, typeof(T));

            // Wait for completion
            yield return(request);

            // Get the reference to the loaded object
            T obj = request.asset as T;

            OnDownloadComplete(obj);

            // Unload the AssetBundles compressed contents to conserve memory
            bundle.Unload(false);

            // Frees the memory from the web stream
            www.Dispose();
        }
    }
Example #30
0
        protected IEnumerator initAssetByCoroutine()
        {
            if (!string.IsNullOrEmpty(m_path))
            {
#if UNITY_5
                // Unity5
                AssetBundleRequest req = m_bundle.LoadAssetAsync(m_path);
#elif UNITY_4_6 || UNITY_4_5
                // Unity4
                AssetBundleRequest req = m_bundle.LoadAsync(m_prefabName, typeof(GameObject));
#endif
                yield return(req);

                //GameObject.Instantiate(req.asset);
                //m_bundle.Unload(false);
            }
            refCountResLoadResultNotify.loadResEventDispatch.dispatchEvent(this);

            yield return(null);
        }