Ejemplo n.º 1
0
    public IEnumerator LoadLevelBundle(string bundleName)
    {
        AssetBundle bundle = null;

        if (AssetBundleManager.GetAssetBundle(bundleName))
        {
            bundle = AssetBundleManager.GetAssetBundle(bundleName);
        }
        else
        {
            string          uri     = "file:///" + Application.dataPath + "/../" + bundleName;
            UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri, 0);
            yield return(request.Send());

            try
            {
                bundle = DownloadHandlerAssetBundle.GetContent(request);
            }
            catch (Exception e)
            {
                Debug.LogError("Level loading failed " + e.Message);
            }
            AssetBundleManager.AddAssetBundle(bundleName, bundle);
        }

        string LevelName = bundle.GetAllScenePaths()[0];

        SceneManager.LoadScene(LevelName);
        yield return(null);
    }
Ejemplo n.º 2
0
    public IEnumerator LoadBlocks()
    {
        string[]          blockFileNames = Directory.GetFiles(Directories.BLOCK_BUNDLES_DIRECTORY, "*.manifest");
        List <GameObject> blockList      = new List <GameObject>();

        foreach (string fileName in blockFileNames)
        {
            string      bundleName = fileName.Replace(".manifest", "");
            AssetBundle bundle     = null;
            if (AssetBundleManager.GetAssetBundle(bundleName))
            {
                bundle = AssetBundleManager.GetAssetBundle(bundleName);
            }
            else
            {
                string          uri     = "file:///" + Application.dataPath + "/../" + bundleName;
                UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri, 0);
                yield return(request.Send());

                try
                {
                    bundle = DownloadHandlerAssetBundle.GetContent(request);
                }
                catch (Exception e)
                {
                    Debug.LogError("Block loading failed " + e.Message);
                }
                if (bundle == null)
                {
                    Debug.LogError("Failed loading blocks");
                    yield return(null);
                }
                AssetBundleManager.AddAssetBundle(bundleName, bundle);
            }


            GameObject[] gos = bundle.LoadAllAssets <GameObject>();
            foreach (GameObject go in gos)
            {
                if (go.GetComponent <Block>())
                {
                    if (blockList.Find(x => x.GetComponent <Block>().Id == go.GetComponent <Block>().Id))
                    {
                        continue;
                    }
                    blockList.Add(go);
                }
            }
        }
        blockList.Sort(CompareBlockById);
        Blocks = blockList.ToArray();
        if (OnBlocksInitialised != null)
        {
            OnBlocksInitialised();
        }
        blocksInitialised = true;
    }
Ejemplo n.º 3
0
    public void InstantiateStoryAndAddtoList(AssetBundle myLoadedAssetBundle, int index)
    {
        var prefab = myLoadedAssetBundle.LoadAsset(assetName);

        Stories[index].SetActive(true);
        Instantiate(prefab, Stories[index].transform);
        ARBtn.gameObject.SetActive(true);

        AssetBundleManager.AddAssetBundle(myLoadedAssetBundle, BaseURL + assetName, assetName, myLoadedAssetBundle.LoadAsset(assetName) as GameObject);
    }
Ejemplo n.º 4
0
    public IEnumerator ShowProgress(string uriAR, UnityEngine.Networking.UnityWebRequest requestAR)
    {
        while (!requestAR.isDone)
        {
            Debug.Log(string.Format("Downloaded {0:P1}", requestAR.downloadProgress));
            ProgressSlider.value = requestAR.downloadProgress;
            ProgressText.text    = Math.Round(requestAR.downloadProgress * 100) + "% loaded...";
            yield return(new WaitForSeconds(.1f));
        }

        if (ProgressSlider.gameObject.activeSelf)
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene("3-AR-Character");
        }
        ProgressSlider.value = 1;
        ProgressSlider.gameObject.SetActive(false);

        var bundlePath = Path.Combine(Path.Combine(Application.persistentDataPath, "AssetData"), assetName + "-ar" + ".unity3d");

        AssetBundleManager.Save(requestAR.downloadHandler.data, bundlePath);
        AssetBundle myLoadedAssetBundleAR = AssetBundle.LoadFromFile(bundlePath);

        AssetBundleManager.AddAssetBundle(myLoadedAssetBundleAR, uriAR, assetName + "-ar", myLoadedAssetBundleAR.LoadAsset(assetName) as GameObject);
    }
Ejemplo n.º 5
0
 public void AddARAssetBundleToList(AssetBundle myLoadedAssetBundleAR)
 {
     AssetBundleManager.AddAssetBundle(myLoadedAssetBundleAR, BaseURL + assetName + "-ar", assetName + "-ar", myLoadedAssetBundleAR.LoadAsset(assetName) as GameObject);
 }