Пример #1
0
    IEnumerator LoadAssetBundle(string name)
    {
        //AssetBundle manifestBundle = AssetBundle.LoadFromFile("file://" + Application.streamingAssetsPath + "/Android/Android");
        string Path = AssetPath.AssetBundleManifestPath();
        WWW    www  = new WWW(Path);

        yield return(www);

        if (www.error == null)
        {
            AssetBundle manifestBundle = www.assetBundle;
            manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
            manifestBundle.Unload(false);

            string[] depNames = manifest.GetAllDependencies(name);
            Debug.Log("depNames length = " + depNames.Length.ToString());
            AssetBundle[] dependsAssetbundle = new AssetBundle[depNames.Length];
            string        Path2 = "";
            for (int index = 0; index < depNames.Length; index++)
            {
                Debug.Log("depNames---" + depNames[index]);
                string ABname = depNames[index].Replace(".myab", "");
                Debug.Log("ABname---" + ABname);
                Path2 = AssetPath.AssetBundlePath() + depNames[index];
                StartCoroutine(LoadAssetBundle(Path2, dependsAssetbundle[index], ABname));
            }
            //string Path3 = AssetPath.AssetBundlePath() + "cube03.myab";
            //  StartCoroutine(LoadAssetBundle1(Path3));
        }
        else
        {
            Debug.Log("www====" + www.error.ToString());
            t.text = "wwwh =" + www.error.ToString();
        }
    }
    public AssetBundle GetBundle(string _ABname)
    {
        WWW wAssetBundle = null;

        // try
        //{
        if (manifest == null)
        {
            string Pant = AssetPath.AssetBundleManifestPath();
            AppStart.Instance.tt.text = AppStart.Instance.tt.text + "Pant --" + Pant + "---";
            // WWW manifestWWW = GetLoadWWW(Pant);

            WWW manifestWWW = resload.getww(Pant);
            AppStart.Instance.tt.text = AppStart.Instance.tt.text + "manifestWWW --" + manifestWWW + "---";
            if (manifestWWW == null)
            {
                AppStart.Instance.tt.text = AppStart.Instance.tt.text + "manifestWWW --null--";
            }
            if (manifestWWW.error == null)
            {
                AssetBundle manifestBundle = manifestWWW.assetBundle;
                manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
                manifestBundle.Unload(false);
                AppStart.Instance.tt.text = AppStart.Instance.tt.text + "  manifestBundle.Unload(false); ---";
                wAssetBundle = SetBundleDependence(_ABname);
                if (wAssetBundle == null)
                {
                    Debug.LogError("GetBundle wAssetBundle   null ");
                    return(null);
                }
                if (wAssetBundle.error != null)
                {
                    Debug.LogError("GetBundle wAssetBundle.error -- " + wAssetBundle.error.ToString());
                    return(null);
                }
                return(wAssetBundle.assetBundle);
            }
            else
            {
                AppStart.Instance.tt.text = AppStart.Instance.tt.text + "manifestWWW --" + manifestWWW.error.ToString() + "---";
            }
        }
        else
        {
            wAssetBundle = SetBundleDependence(_ABname);
            if (wAssetBundle == null)
            {
                Debug.LogError("GetBundle wAssetBundle   null ");
                return(null);
            }
            if (wAssetBundle.error != null)
            {
                Debug.LogError("GetBundle wAssetBundle.error -- " + wAssetBundle.error.ToString());
                return(null);
            }
            return(wAssetBundle.assetBundle);
        }
        return(wAssetBundle.assetBundle);
        //  }
        //catch (Exception e)
        // {
        //    AppStart.Instance.tt.text = AppStart.Instance.tt.text + "eee--" + e.ToString();
        //    return wAssetBundle.assetBundle;
        // }
    }