Пример #1
0
        private IEnumerator loadWithResources(
            string[] bundle_names, OnPrefabGameObject cb, OnProgress op)
        {
            op(0, false);
            yield return(new WaitForEndOfFrame());

            float total   = bundle_names.Length;
            float process = 0;

            int len = bundle_names.Length;

            for (int i = 0; i < len; ++i)
            {
                GameObject obj = Resources.Load <GameObject>(bundle_names[i]);
                if (obj == null)
                {
                    cb(null, bundle_names[i]);
                }
                else
                {
                    cb(Instantiate(obj), bundle_names[i]);
                }
                op((++process) / total, false);
                yield return(new WaitForEndOfFrame());
            }
            op(1, true);
        }
Пример #2
0
 public void loadPrefabs(string[] bundle_names, OnPrefabGameObject cb, OnProgress op)
 {
     if (useResource)
     {
         StartCoroutine(loadWithResources(bundle_names, cb, op));
     }
     else
     {
         StartCoroutine(loadWithBundles(bundle_names, cb, op));
     }
 }
Пример #3
0
 public void loadPrefab(string bundle_name, OnPrefabGameObject cb)
 {
     if (useResource)
     {
         StartCoroutine(loadWithResources(new string[] { bundle_name }, cb, onProgressEmpty));
     }
     else
     {
         StartCoroutine(loadWithBundles(new string[] { bundle_name }, cb, onProgressEmpty));
     }
 }
Пример #4
0
        // 加载prefab队列
        private IEnumerator loadWithBundles(
            string[] bundle_names, OnPrefabGameObject cb, OnProgress op)
        {
            op(0, false);
            float total   = bundle_names.Length;
            float process = 0;

            if (_dependencies_manifest == null)
            {
                yield return(loadDependenciesManifest());
            }

            int len = bundle_names.Length;

            for (int i = 0; i < len; ++i)
            {
                string name = bundle_names[i] + ".prefab.unity3d";
                WWW    www  = new WWW(Config.PathInfo.BUNDLE_URL + name.ToLower());
                yield return(www);

                List <AssetBundle> _bundles_to_unload = new List <AssetBundle>();
                AssetBundle        _load_target       = null;
                visitBundle(www, (AssetBundle bundle) =>
                {
                    _load_target = bundle;
                    _bundles_to_unload.Add(bundle);
                });

                yield return(loadDependencies(name, (AssetBundle bundle) =>
                {
                    _bundles_to_unload.Add(bundle);
                }));

                GameObject obj =
                    _load_target.LoadAsset <GameObject>("Assets/" + bundle_names[i]);
                if (obj == null)
                {
                    cb(null, bundle_names[i]);
                }
                else
                {
                    cb(Instantiate(obj), bundle_names[i]);
                }
                op((++process) / total, false);

                foreach (AssetBundle bundle in _bundles_to_unload)
                {
                    bundle.Unload(false);
                }
            }
            op(1, true);
        }