IEnumerator Start() { guid = PlayerPrefs.GetString("guid"); remoteURL = PlayerPrefs.GetString("url"); // create download helper dt = gameObject.AddComponent <DownloadTools>() as DownloadTools; dt.message = "loading parts for " + guid; // get platform name platform = dt.GetPlatform(); // try to get manifest WWW www = null; yield return(StartCoroutine(dt.openOrDownloadFile(Application.persistentDataPath + "/" + guid + "/", remoteURL, platform, value => www = value))); //(Application.persistentDataPath + "/" + guid + "/", remoteLocation, platform, value => www = value)); if (www != null) { AssetBundleManifest manifest = (AssetBundleManifest)www.assetBundle.LoadAsset("AssetBundleManifest"); www.assetBundle.Unload(false); foreach (string bundle in manifest.GetAllAssetBundles()) { Debug.Log(bundle); // load bundle WWW bundleWWW = null; yield return(StartCoroutine(dt.openOrDownloadFile(Application.persistentDataPath + "/" + guid + "/", remoteURL, bundle, value => bundleWWW = value))); //(Application.persistentDataPath + "/" + guid + "/", remoteLocation, platform, value => www = value)); if (bundleWWW != null) { AssetBundle ab = bundleWWW.assetBundle; bundleWWW = null; // Load the object asynchronously AssetBundleRequest request = ab.LoadAssetAsync(bundle); // Wait for completion yield return(request); Instantiate(request.asset); Debug.Log(bundle + " loaded"); ab.Unload(false); } else { Debug.Log("Problem accessing bundle: " + bundle); dt.message = "Problem accessing bundle: " + bundle; } } Debug.Log("yay"); dt.message = "yay"; this.enabled = false; } else { Debug.Log("Problem accessing site manifest"); dt.message = "Problem accessing site manifest"; } }
// Use this for initialization void Start() { // create download helper dt = gameObject.AddComponent <DownloadTools>() as DownloadTools; dt.message = "started"; // get platform name platform = dt.GetPlatform(); string remoteLocation = ""; // write "remote" file to local string targetFile = Application.persistentDataPath + "/" + guid + "/remote.txt"; if (!File.Exists(targetFile)) { Directory.CreateDirectory(Application.persistentDataPath + "/" + guid); // write remote URL to file remoteLocation = bundleLocation + guid + "/" + platform + "/"; StreamWriter writer = new StreamWriter(targetFile); writer.WriteLine(remoteLocation); writer.Close(); dt.message = "Initialising Site at " + targetFile; Debug.Log("Initialising Site at " + targetFile); } else { // read remote location StreamReader reader = new StreamReader(targetFile); remoteLocation = reader.ReadLine().TrimEnd(); dt.message = "Pointing to " + remoteLocation; Debug.Log("Pointing to " + remoteLocation); } PlayerPrefs.SetString("url", remoteLocation); // go to main part Application.LoadLevel("Main"); // // check for manifest // AssetPath = Application.persistentDataPath + "/" + guid + "/"; // bundleFilePath = AssetPath + guid; // bundleURL = bundleLocation + guid; // if (!File.Exists(bundleFilePath)) { // // if directory doesn't exist then create it // if (!Directory.Exists(Application.persistentDataPath + "/" + guid)) { // Directory.CreateDirectory(Application.persistentDataPath + "/" + guid); // } // // // // // start downloading // yield return StartCoroutine(startDownload(host, uri, bundleFilePath)); // // } else { // message = "Bundle already downloaded and at " + bundleFilePath; // Debug.Log("Bundle already downloaded and at " + bundleFilePath); // // } }