示例#1
0
//Added

    IEnumerator DownloadAsse()
    {
        i = 0;
        // Frees the memory from the web stream
        // www.Dispose();
        // Store Previous loaded url
        //url_loaded = url;
        _instance = new GameObject[20];

        //Load "SimpleCloudHandler1" from "CloudRecoBehaviour"
        CloudHandlerScript = CloudRecognitionGameObject.GetComponent <SimpleCloudHandler1>();
        // access "ReadMeta()" function from "SimpleCloudHandler1" script
        url = CloudHandlerScript.ReadMeta();
        Debug.Log("Downloading from yes yes worked:" + url);
        // Update url_loaded to prevent downloading assets again for the reco
        url_loaded = url;
        //download AssetBundle
        www = new WWW(url);
        // using (www = new WWW(url)) -- Or use this
        using (www)
        {
            //wait for download
            yield return(www);

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

            asseBundle = www.assetBundle;

            //load all assets
            _assets = www.assetBundle.LoadAllAssets();
            //load all asset names
            assetNames = www.assetBundle.GetAllAssetNames();

            foreach (UnityEngine.Object eachAsset in _assets)
            {
                // request prefab to load
                asset = asseBundle.LoadAssetAsync <GameObject>(assetNames[i]);
                yield return(asset);

                //load prefab as gameobject
                loadedAsset = asset.asset as GameObject;
                //Instanciate Prefab
                //Instantiate(asseBundle.LoadAsset(assetNames[i]));
                //GameObject clone = (GameObject)Instantiate(asseBundle.LoadAsset(assetNames[i]));
                //_instance[i] = clone;
                //_instance.Add(clone);
                GameObject clone = new GameObject();
                clone        = Instantiate(asseBundle.LoadAsset(assetNames[i])) as GameObject;
                _instance[i] = clone;
                //clone.transform.parent = mTrackableBehaviour.transform;

                //Destory(clone);
                //_instance.Add((GameObject)Instantiate(asseBundle.LoadAsset(assetNames[i])));
                i++;
            }
        }
    }