Exemplo n.º 1
0
 private void Update()
 {
     if (this.assetsToLoad.Count > 0)
     {
         for (int i = this.assetsToLoad.Count - 1; i >= 0; i--)
         {
             LoadAssetFromBundle loadAssetFromBundle = this.assetsToLoad[i];
             if (loadAssetFromBundle.IsDownloadDone)
             {
                 loadAssetFromBundle.InstantiateAsset();
                 this.assetsToLoad.RemoveAt(i);
                 UnityEngine.Object.Destroy(loadAssetFromBundle);
                 this.isDownloaded = true;
             }
         }
         if (this.isDownloaded)
         {
             foreach (LoadAssetFromBundle current in this.assetsToLoad)
             {
                 if (!current.HasDownloadStarted)
                 {
                     current.DownloadAsset();
                     this.isDownloaded = false;
                     break;
                 }
             }
         }
     }
     else
     {
         UnityEngine.Object.Destroy(base.gameObject);
     }
 }
Exemplo n.º 2
0
    void Start()
    {
        //be sure to use the same location you specified as Export Location in the Bundle Creator
        // or if this is in the web player, direct the path to your online folder where the bundles are uploaded
        baseURL = Application.dataPath + "/../AssetBundles/";

        //Load the bundles
        if (File.Exists(baseURL + "logobundle_01.unity3d")) //Check if the asset bundle is built
        {
            //Load the two logo files stored in the bundle
            LoadAssetFromBundle cryWolfLogo = this.gameObject.AddComponent <LoadAssetFromBundle>();
            cryWolfLogo.QueueBundleDownload("pre_cryWolfLogo", "logobundle_01.unity3d", 1);
            cryWolfLogo.baseURL = filePrefix + baseURL;

            LoadAssetFromBundle cryWolfLogoURL = this.gameObject.AddComponent <LoadAssetFromBundle>();
            cryWolfLogoURL.QueueBundleDownload("pre_cryWolfLogo_url", "logobundle_01.unity3d", 1);
            cryWolfLogoURL.baseURL = filePrefix + baseURL;

            //Add them to the download list
            assetsToLoad.Add(cryWolfLogo);
            assetsToLoad.Add(cryWolfLogoURL);
        }
        else
        {
            //The file does not exist, you need to build the bundle first
            Debug.LogError("Bundles are not built! Open the Bundle Creator in Assets->BundleCreator>Asset Bundle Creator to build your bundles.");
        }
    }
Exemplo n.º 3
0
    private string filePrefix = "file://"; // I use this prefix to show that i'm currently loading the bundle from my
    //local computer, if i were to load it from the web - this wouldn't be necessary.


    void Start()
    {
        //This command ONLY works if you run in the editor, because i'm just getting whatever value I got stored in
        // the AssetBundleCreator as export folder.
        //If I would want to load this from let's say an iPhone,
        // I would have to store them in a specific folder on the phone(Which wouldn't make any sense because I could just use Resources.Load instead.
        // So the option on testing on the iOS device itself would either be from the editor like this,
        // OR store them online on a server and set the baseURL to its http address.
        baseURL = filePrefix + Application.dataPath + PlayerPrefs.GetString("cws_exportFolder");

        //So.. on to the loading of the bundles.
        //When loading them this way, I put each "loading command" in a list
        // That list is being checked and maintained in the Update() method.
        //Whenever a download is complete, it instantiates it as a gameobject
        // and proceeds to the next bundle to download.

        //To do that, I create a new LoadAssetFromBundle component
        LoadAssetFromBundle myAssetToLoad = this.gameObject.AddComponent <LoadAssetFromBundle>();

        //I set the asset name, the name of the bundle, and the current version of the bundle
        myAssetToLoad.QueueBundleDownload("MY_ASSET_NAME", "MY_BUNDLE_NAME.unity3d", 1);

        //Then, I set the URL from where it should download the bundle
        //with the value I set in the beginning of Start()
        myAssetToLoad.baseURL = baseURL;

        //To start the download, I add them to the "things to download list"
        // and it will start the download in the Update() method.
        assetsToLoad.Add(myAssetToLoad);

        //To load more than on asset this way, just create another LoadAssetFromBundle component
        // and make sure to add it to the assetsToLoad list.
    }
Exemplo n.º 4
0
    private void Start()
    {
        this.baseURL = this.filePrefix + Application.dataPath + PlayerPrefs.GetString("cws_exportFolder");
        LoadAssetFromBundle loadAssetFromBundle = base.gameObject.AddComponent <LoadAssetFromBundle>();

        loadAssetFromBundle.QueueBundleDownload("MY_ASSET_NAME", "MY_BUNDLE_NAME.unity3d", 1);
        loadAssetFromBundle.baseURL = this.baseURL;
        this.assetsToLoad.Add(loadAssetFromBundle);
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (assetsToLoad.Count > 0)
        {
            for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
            {
                LoadAssetFromBundle asset = assetsToLoad[i];
                if (asset.IsDownloadDone)
                {
//					string fileName = Application.persistentDataPath + "/" + FILE_NAME;
//					fileWriter = File.CreateText(fileName);
//					fileWriter.WriteLine("Hello world");
//					fileWriter.Close();

                    //The download is done, instantiate the asset from the bundle
                    asset.InstantiateAsset();
                    //Remove the asset from the loading list
                    assetsToLoad.RemoveAt(i);
                    //Destroy the LoadAssetFromBundle Script
                    Destroy(asset);
                    //This means an asset is downloaded, which means you can start on the next one
                    isDownloaded = true;
                }
            }

            if (isDownloaded)             //The download is complete
            {
                //Start the next download
                foreach (LoadAssetFromBundle asset in assetsToLoad)
                {
                    if (!asset.HasDownloadStarted)
                    {
                        //Start the download
                        asset.DownloadAsset();

                        //set the isDownloaded to false again
                        isDownloaded = false;

                        //break the loop
                        break;
                    }
                }
            }
        }
        else         //If there is nothing left to load, then destroy this game object
        {
            //Destroy(this.gameObject);
        }
    }
Exemplo n.º 6
0
    void Update()
    {
        if (assetsToLoad.Count > 0)
        {
            for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
            {
                LoadAssetFromBundle asset = assetsToLoad[i];
                if (asset.IsDownloadDone)
                {
                    //The download is done, instantiate the asset from the bundle
                    asset.InstantiateAsset();
                    //Remove the asset from the loading list
                    assetsToLoad.RemoveAt(i);
                    //Destroy the LoadAssetFromBundle Script
                    Destroy(asset);
                    //This means an asset is downloaded, which means you can start on the next one
                    isDownloaded = true;
                }
            }

            if (isDownloaded) //The download is complete
            {
                //Start the next download
                foreach (LoadAssetFromBundle asset in assetsToLoad)
                {
                    if (!asset.HasDownloadStarted)
                    {
                        //Start the download
                        asset.DownloadAsset();

                        //set the isDownloaded to false again
                        isDownloaded = false;

                        //break the loop
                        break;
                    }
                }
            }
        }
        else         //If there is nothing left to load, then destroy this game object
        {
            Destroy(this.gameObject);
        }
    }
Exemplo n.º 7
0
 private void Start()
 {
     this.baseURL = Application.dataPath + "/../AssetBundles/";
     if (File.Exists(this.baseURL + "logobundle_01.unity3d"))
     {
         LoadAssetFromBundle loadAssetFromBundle = base.gameObject.AddComponent <LoadAssetFromBundle>();
         loadAssetFromBundle.QueueBundleDownload("pre_cryWolfLogo", "logobundle_01.unity3d", 1);
         loadAssetFromBundle.baseURL = this.filePrefix + this.baseURL;
         LoadAssetFromBundle loadAssetFromBundle2 = base.gameObject.AddComponent <LoadAssetFromBundle>();
         loadAssetFromBundle2.QueueBundleDownload("pre_cryWolfLogo_url", "logobundle_01.unity3d", 1);
         loadAssetFromBundle2.baseURL = this.filePrefix + this.baseURL;
         this.assetsToLoad.Add(loadAssetFromBundle);
         this.assetsToLoad.Add(loadAssetFromBundle2);
     }
     else
     {
         Debug.LogError("Bundles are not built! Open the Bundle Creator in Assets->BundleCreator>Asset Bundle Creator to build your bundles.");
     }
 }
Exemplo n.º 8
0
    void OnGUI()
    {
        GUILayout.Label("Caching.enabled" + Caching.enabled.ToString());
        GUILayout.Label("Caching.ready" + Caching.ready.ToString());
        GUILayout.Label("Caching.expirationDelay" + Caching.expirationDelay.ToString());
        GUILayout.Label("Caching.maximumAvailableDiskSpace" + Caching.maximumAvailableDiskSpace.ToString());
        GUILayout.Label("Caching.spaceFree" + Caching.spaceFree.ToString());
        GUILayout.Label("Caching.spaceOccupied" + Caching.spaceOccupied.ToString());

        if (GUILayout.Button("Load url"))
        {
            //StartCoroutine (DownloadAndCache());

            LoadAssetFromBundle cryWolfLogo = this.gameObject.AddComponent <LoadAssetFromBundle>();
            cryWolfLogo.QueueBundleDownload("pre_cryWolfLogo", "android_logobundle_01.unity3d", 1);
            cryWolfLogo.baseURL = "https://googledrive.com/host/0B0zQPJH0W58oRVpsUXUyUS13OFk/";
            //https://googledrive.com/host/0B0zQPJH0W58oRVpsUXUyUS13OFk/android_logobundle_01.unity3d
            assetsToLoad.Add(cryWolfLogo);
        }

        if (GUILayout.Button("Res load"))
        {
            Object     obj = Resources.Load("pre_cryWolfLogo");
            GameObject gob = (GameObject)Instantiate(obj);
        }

        if (GUILayout.Button("Alert"))
        {
            ShowAlertBox("Alert", "Hello");
            Debug.Log("Alert!");
        }

//		if (GUILayout.Button("Inst test"))
//		{
//
//			GameObject obj = (GameObject)Resources.Load("pre_cryWolfLogo");
//			Instantiate(obj);
//		}
    }