Beispiel #1
0
        public static IEnumerator CreateAsync(string name)
        {
            if (string.IsNullOrEmpty(name))//空场景
            {
                GameObject obj = new GameObject("AssetScene");
                if (Application.isPlaying)
                {
                    GameObject.DontDestroyOnLoad(obj);
                }
                AssetScene assetScene = obj.AddComponent <AssetScene>();
                m_current = assetScene;

                yield return(null);
            }
            else
            {
                GameObject obj = new GameObject("AssetScene");//需要加载资源
                if (Application.isPlaying)
                {
                    GameObject.DontDestroyOnLoad(obj);
                }
                AssetScene assetScene = obj.AddComponent <AssetScene>();
                assetScene.assetBundleName = GetAssetBundleNameOfScene(name);
                yield return(ABsManager.LoadAsync(assetScene.assetBundleName));

                m_current = assetScene;
            }
        }
Beispiel #2
0
            public AsyncABLoader(string path)
            {
                orgPath         = path;
                path            = string.Format("assets/resources/{0}", path.Replace("\\", "/"));
                this.path       = path;
                assetBundleName = AssetBundleAssetRecord.GetAssetBundleName(path);

                if (assetBundleName != null && assetBundleName != "")
                {
                    this.assetBundleName = assetBundleName.ToLower();
                    AssetScene.Current.StartCoroutine(ABsManager.LoadAsync(assetBundleName));
                }
            }
Beispiel #3
0
        public IEnumerator LoadAssetAsync(string path, System.Action <Object> callback)
        {
            path = string.Format(basePath, path.Replace("\\", "/"));
            string assetBundleName = AssetBundleAssetRecord.GetAssetBundleName(path);

            ObjectRequest or = FindObjectRequest(path);

            if (or == null)
            {
                or = new ObjectRequest(path, callback);
                ors.Add(or);

                yield return(ABsManager.LoadAsync(assetBundleName));

                string assetName = string.Format("{0}", AssetBundleAssetRecord.GetAssetName(path));
                //yield return ABsManager.Find(assetBundleName).LoadFromMemeroyAsync();
                Object obj = ABsManager.Find(assetBundleName).GetRes(assetName);

                if (or == null)
                {
                    Debug.LogError("or is removed");
                }
                ;

                if (or.callbacks != null)
                {
                    Debug.Log("or callback count = " + or.callbacks.Count + "  " + or.path);
                    foreach (var k in or.callbacks)
                    {
                        k(obj);
                    }
                    or.callbacks.Clear();
                }
                ors.Remove(or);
            }
            else
            {
                or.callbacks.Add(callback);
            }



            //if (callback != null) callback(obj);
        }