Beispiel #1
0
 public void AddParent(BundleLoader parent)
 {
     if (null != parent)
     {
         m_parents.Add(parent);
     }
 }
Beispiel #2
0
        public AssetBundle LoadAssetBundle(string bundleName, bool cache = true)
        {
            if (assetBundleCache.ContainsKey(bundleName))
            {
                return(assetBundleCache[bundleName]);
            }
            AssetBundle bundle = null;

            var memory = BundleLoader.LoadFileMemory(LocalVersionConfig.bundleRelativePath + "/" + bundleName + BundleConfig.suffix);

            using (var bundleStream = BundleEncode.DeompressAndDecryptLZMA(memory, password))
            {
                if (bundleStream == null)
                {
                    return(bundle);
                }
                bundle = AssetBundle.CreateFromMemoryImmediate(bundleStream.ToArray());
                if (bundle == null)                             // 如果没有则直接返回
                {
                    return(bundle);
                }
            }
            if (cache)
            {
                assetBundleCache.Add(bundleName, bundle);
            }
            return(bundle);
        }
    public bool Load(string bundleName, bool loadAssets)
    {
        try
        {
            mBundleName  = bundleName;
            mAssetBundle = BundleLoader.LoadBundleFromSDCard(mBundleName);
            if (mAssetBundle == null)
            {
                //Logger.ErrorLog("SharedLoaderObject.Load Error!!! LoadFromFile Fild: Path:{0}", bundlePath);
                return(false);
            }
            int startIdx = mBundleName.LastIndexOf("/");
            int endIdx   = mBundleName.LastIndexOf(".");
            assName = mBundleName.Substring(startIdx + 1, endIdx - startIdx - 1);

            if (loadAssets)
            {
                mMainObject = mAssetBundle.LoadAsset(assName);
            }

            return(true);
        }
        catch
        {
            return(false);
        }
    }
Beispiel #4
0
    private void ToNode(int n)
    {
        if (n == 0 && currentNode.id != 0)
        {
            Finish();
            return;
        }

        if (currentSpeechPanel)
        {
            currentSpeechPanel.gameObject.SetActive(false);
        }

        currentNode = story.Nodes[n];
        var charName = currentNode.character;

        if (charName == "...")
        {
            currentSpeechPanel = tutorialSpeechPanel;
        }
        else
        {
            currentSpeechPanel = charName == "player" ? playerSpeechPanel : neutralSpeechPanel;
            if (!characterDict.ContainsKey(charName))
            {
                characterDict.Add(charName, BundleLoader.LoadCharacter(charName));
            }
        }

        currentSpeechPanel.SetNode(currentNode);
        currentSpeechPanel.gameObject.SetActive(true);
    }
Beispiel #5
0
    void Start()
    {
        BundleLoader bundleLoader = new BundleLoader();

        bundleLoader.Init();
        CheckAssetsInScreamBundle(bundleLoader);
        CheckValidJsonData(bundleLoader);
    }
    private void Start()
    {
        bundleLoader = new BundleLoader(loadBundleFrom);
        string zeusBeardUrl =
            "https://www.stubuchbinder.com/groomify/ios/zeus_beard.unity3d";

        LoadUrl(zeusBeardUrl);
    }
Beispiel #7
0
    public BundleLoader GetBundleLoader(string abName)
    {
        BundleLoader cache = null;

        m_BundleLoaders.TryGetValue(abName, out cache);

        return(cache);
    }
 public void TryRelease(BundleLoader assetLoader, bool unloadFlag)
 {
     if (0 >= --mReferance)
     {
         assetLoader.RemoveAssetBundle(mBundleName);
         mAssetBundle.Unload(unloadFlag);
         CleanUp();
     }
 }
Beispiel #9
0
    private Dictionary <string, BundleLoader> m_BundleLoaders = new Dictionary <string, BundleLoader>();  //记录所有加载中的包

    public void AddBundleLoader(string abName, BundleLoader loader)
    {
        if (m_BundleLoaders.ContainsKey(abName))
        {
            Util.LogError("包已经在加载中了,你又重复加载了,包名:" + abName);
        }

        m_BundleLoaders.Add(abName, loader);
    }
Beispiel #10
0
    // Use this for initialization
    void Start()
    {
        Dictionary <string, HashSet <string> > map = new Dictionary <string, HashSet <string> >();

        BundleLoader bundleLoader = new BundleLoader();

        bundleLoader.Init();
        getStatistic(map, bundleLoader);
        extraxt(map, bundleLoader);
    }
Beispiel #11
0
    void Start()
    {
        this.bundleLoader = new BundleLoader();
        this.bundleLoader.Init();
        this.sceneLoader = new SceneLoader(this.bundleLoader);
        this.sceneLoader.LoadScene("Garage");

        this.InitHullDb();
        this.StartCoroutine(this.AwaitLoadMap());
    }
        public void SetUp()
        {
            _cachedLoader = Substitute.For <IBundleCachedLoader>();

            // Mock bundleManifest
            _bundleManifestLoader = Substitute.For <IBundleManifestLoader>();
            _bundleManifest       = Substitute.For <IBundleManifest>();
            _bundleManifestLoader.Load().Returns(Observable.Return(_bundleManifest));

            _fixture = new BundleLoader(_cachedLoader, _bundleManifestLoader);
        }
Beispiel #13
0
    private void OnBundleLoaded(BundleLoader obj)
    {
        var prefabs = new List <PlainObject>();

        foreach (var bundlePref in obj.Prefabs)
        {
            prefabs.Add(bundlePref.GetComponent <PlainObject>());
        }

        _prefabs = prefabs.ToArray();
    }
Beispiel #14
0
 private void Start()
 {
     this.bundleLoader = new BundleLoader();
     this.bundleLoader.Init();
     this.sceneLoader = new SceneLoader(this.bundleLoader);
     this.scenePatchs = this.sceneLoader.GetScenePatchs();
     this.scenePatchs.ForEach(scenePatch => this.Dropdown.AddOptions(
                                  new List <Dropdown.OptionData> {
         new Dropdown.OptionData(System.IO.Path.GetFileNameWithoutExtension(scenePatch))
     }
                                  ));
 }
Beispiel #15
0
    protected override void Awake()
    {
        base.Awake();
        if (Instance == this)
        {
            DontDestroyOnLoad(gameObject);
            bundleQueue  = new Queue <BundleQueueItem>();
            bundleLoader = gameObject.GetOrAddComponent <BundleLoader>();
#if UNITY_EDITOR
            //bundleLoader.isUsingLocalBundle = true;
#endif
        }
    }
Beispiel #16
0
    // 加载资源清单
    void LoadManifest(ManifestType mType)
    {
        if (m_manifests.ContainsKey(mType) && m_manifests[mType] != null)
        {
            DestroyImmediate(m_manifests[mType], true);
            m_manifests.Remove(mType);
        }

        string manifestName = mType.ToString();

        Util.Log("LoadManifest manifestName " + manifestName);

        m_manifestNames.Add(manifestName);
        string strFullPath = FileHelper.SearchFilePath(GetManifestType(manifestName).ToString(), manifestName);

        Util.Log("strFullPath: " + strFullPath);

        BundleLoader bLoader = LoaderPool.Instance.GetLoader <BundleLoader>();

        bLoader.Init(strFullPath, manifestName, delegate(object data) {
            LoadedBundle ab = data as LoadedBundle;
            if (ab != null)
            {
                m_manifests[mType]   = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                m_bundleHeads[mType] = mType.ToString().ToLower().Split('_')[0];

                Util.Log("manifest ab in not null over----");
            }
            else
            {
                Util.LogError("manifest ab is null---------");
            }

            LoadedBundleCtrl.Instance.UnReferenceLoadedBundle(manifestName);  // 不走统一接口是因为manifest文件没有后缀
            LoadedBundleCtrl.Instance.HandRemoveBundle(manifestName);

            if (m_manifests[mType] != null)
            {
                string[] bundles = m_manifests[mType].GetAllAssetBundles();

                for (int i = 0; i < bundles.Length; ++i)
                {
                    if (m_bundleNames.Contains(bundles[i]))
                    {
                        Util.LogError(string.Format("别的清单已同名的包名,{0} {1}", manifestName, bundles[i]));
                    }
                    m_bundleNames.Add(bundles[i]);
                }
            }
        }, false, null, true);
    }
Beispiel #17
0
    void Awake()
    {
        stories = new List <Story>();
        var allStoriesTexts = BundleLoader.LoadAllStories();

        foreach (var storyText in allStoriesTexts)
        {
            Node[] nodes = JsonHelper.FromJson <Node>(storyText.ToString());
            Story  story = new Story();
            story.Nodes = nodes;

            stories.Add(story);
        }
    }
Beispiel #18
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Unity content (*.unity3d;*.assets)|*.unity3d;*.assets|Bundle file (*.unity3d)|*.unity3d|Assets file (*.assets)|*.assets|All types (*.*)|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //try
                //{
                //todo, use using
                FileStream       stream     = new FileStream(ofd.FileName, FileMode.Open, FileAccess.ReadWrite);
                AssetsFileReader tempReader = new AssetsFileReader(stream);     //todo .assets sanity check
                if (tempReader.ReadStringLength(7) != "UnityFS")
                {
                    tempReader.Position = 0;
                    AssetViewer av = new AssetViewer(stream, Path.GetDirectoryName(stream.Name), Path.GetFileName(stream.Name));
                    av.ShowDialog();
                }
                else
                {
                    tempReader.Position = 0;
                    BundleLoader bl = new BundleLoader(stream);
                    bl.ShowDialog();
                    if (bl.loaded)
                    {
                        bundleContents.Enabled = true;
                        exportButton.Enabled   = true;
                        importButton.Enabled   = true;
                        infoButton.Enabled     = true;
                        foreach (AssetsBundleDirectoryInfo06 di in bl.bundle.bundleInf6.dirInf)
                        {
                            bundleContents.Items.Add(di.name);
                        }
                        bundleContents.SelectedIndex = 0;
                        bundlePath    = bl.bundleFilename;
                        fileName.Text = Path.GetFileName(bundlePath);
                        bundle        = bl.bundle;
                    }
                }
                tempReader = null;
                //} catch (Exception ex)
                //{
                //    MessageBox.Show("Unable to open the file!\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //}
            }
        }
Beispiel #19
0
 private static void extraxt(Dictionary <string, HashSet <string> > map, BundleLoader bundleLoader)
 {
     bundleLoader.GetLoadedAssetBundles()
     .Where(bundle => bundle != null && !bundle.isStreamedSceneAssetBundle)
     .Take(40)
     .ToList()
     .ForEach(bundle => {
         bundle.GetAllAssetNames()
         .ToList()
         .ForEach(assetName => {
             Object asset = bundle.LoadAsset(assetName);
             if (assetName.Split('.').Last().Equals("png") && asset as UnityEngine.Texture2D)
             {
             }
         });
     });
 }
Beispiel #20
0
    public SceneLoader(BundleLoader bundleLoader)
    {
        this.bundleLoader = bundleLoader;

        this.bundleLoader.loadedBundles.Values
        .Where(assetBundle => assetBundle != null)
        .Where(assetBundle => assetBundle.isStreamedSceneAssetBundle)
        .ToList()
        .ForEach(assetBundle => {
            assetBundle.GetAllScenePaths()
            .ToList()
            .ForEach(scenePath => {
                this.scenes.Add(scenePath, assetBundle.name);
                Debug.Log(scenePath + "------" + assetBundle.name);
            });
        });
    }
Beispiel #21
0
    public BundleLoader.BundleState LoadAssetBundle(string path, LoadedCallback onLoaded, bool async = true, BundleLoader parent = null)
    {
        string abName = FileHelper.CheckBundleName(path);

        if (!ManifestHasBundleInfo(abName))
        {
            if (onLoaded != null)
            {
                onLoaded(null);
            }
            return(BundleLoader.BundleState.NotExist);
        }

        LoadedBundle loadedCache = LoadedBundleCtrl.Instance.ReferenceLoadedBundle(abName);

        if (loadedCache != null)
        {
            if (onLoaded != null)
            {
                onLoaded(loadedCache);
            }
            return(BundleLoader.BundleState.Loaded);
        }

        BundleLoader loadingCache = BundleLoaderCtrl.Instance.GetBundleLoader(abName);

        if (loadingCache != null)
        {
            loadingCache.AddHandleCallBack(onLoaded);
            loadingCache.AddParent(parent);
            return(BundleLoader.BundleState.Loading);
        }

        string fullpath = FileHelper.SearchFilePath(GetManifestType(abName).ToString(), abName);           //包最终加载路径

        BundleLoader bLoader = LoaderPool.Instance.GetLoader <BundleLoader>();

        bLoader.Init(fullpath, abName, onLoaded, async, parent);

        return(BundleLoader.BundleState.JustLoad);
    }
        public AssetBundleManager(AssetBundleManagerConfig cfg, GameObject owner)
        {
            config      = cfg;
            freeStreams = config.numBundleLoaders;

            streams      = new List <Coroutine>();
            loadHandlers = new Dictionary <string, Action <string> >();

            cache  = new AssetBundleCache();
            loader = owner.AddComponent <BundleLoader>();

            updater = owner.AddComponent <BundleManagerUpdate>();
            updater.Init(this);

            loadOps = new ObjectPool <BundleLoadOperation>(16, true)
            {
                OnInstantiate = () => new BundleLoadOperation(this)
            };
            loadOps.Fill();
            // check cfg.bundleTarget and start local server if necessary.
        }
Beispiel #23
0
    internal static bool Exist(string aniFile)
    {
        //先判断自动更新目录
        string noUse;

        if (BundleLoader.BundleExistInUpdatePath(aniFile, out noUse))
        {
            return(true);
        }

#if UNITY_ANDROID && !UNITY_EDITOR
        var    bundlePath = BundleNameSplit(aniFile);
        string realpath, nouse;
        var    needUpdate = BundleLoader.Instance.GetBundleRealPath(AddBundleExt(bundlePath[0]), out realpath, out nouse);
        if (needUpdate)
        {
            return(true);
        }
        var filepath = realpath.Substring(realpath.IndexOf("assets/"));
        var item     = BundleLoader.Instance.ZipFile.GetEntry(filepath);
        return(item != null);
#else
        if (sInstance.UseAssetBundle)
        {
            aniFile = aniFile.Replace("\\", "/");
            var fileName = aniFile.Replace("/", "_");
#if UNITY_EDITOR
            var path = Path.Combine(
                Path.Combine(Path.Combine(Application.dataPath, "BundleAsset"), Path.GetDirectoryName(aniFile)),
                Path.GetFileNameWithoutExtension(fileName)) + ".unity3d";
#else
            var path = Path.Combine(
                Path.Combine(Application.streamingAssetsPath, Path.GetDirectoryName(aniFile)),
                Path.GetFileNameWithoutExtension(fileName)) + ".unity3d";
#endif
            return(File.Exists(path));
        }
        return(File.Exists(Path.Combine(Path.Combine(Application.dataPath, "Res"), aniFile)));
#endif
    }
Beispiel #24
0
    private static void CheckValidJsonData(BundleLoader bundleLoader)
    {
        int count = bundleLoader.GetLoadedAssetBundles()
                    .Where(assetBundle => assetBundle != null)
                    .Where(assetBundle =>
        {
            List <BundleInfo> bunleList = bundleLoader.db.bundles
                                          .Where(bundleInfo => bundleInfo.bundleName == assetBundle.name)
                                          .ToList();
            if (assetBundle.isStreamedSceneAssetBundle)
            {
                Debug.Log(bunleList[0].assets.Length == assetBundle.GetAllScenePaths().Length);
            }
            else
            {
                Debug.Log(bunleList[0].assets.Length == assetBundle.GetAllAssetNames().Length);
            }

            return(true);
        }).ToList().Count;

        Debug.Log(count);
    }
Beispiel #25
0
        // \IGameService

        /// <summary>
        /// Получить загрузчик бандла.
        /// </summary>
        /// <param name="bundleName">Имя бандла, для которого получается загрузчик.</param>
        /// <returns>Загрузчик бандла.</returns>
        public BundleLoader GetBundleLoader(string bundleName)
        {
            if (!Ready.Value)
            {
                Debug.LogError("BundleManager is not initialized yet.");
                return(null);
            }

            if (BundleLoadersMap.TryGetValue(bundleName, out var loader))
            {
                return(loader);
            }

            if (!_bundleDataMap.TryGetValue(bundleName, out var data))
            {
                Debug.LogErrorFormat("There is no data for bundle {0} in manifest.", bundleName);
                return(null);
            }

            loader = new BundleLoader(data, _audioManager);
            BundleLoadersMap.Add(bundleName, loader);
            return(loader);
        }
Beispiel #26
0
    private static void CheckAssetsInScreamBundle(BundleLoader bundleLoader)
    {
        bool v = bundleLoader.db.bundles.Length == bundleLoader.loadedBundles.Keys.Count;

        Debug.Log(v);
        List <AssetBundle> list = bundleLoader.loadedBundles.Values
                                  .Where(bundle => bundle != null)
                                  .Where(bundle =>
        {
            return(bundle.AllAssetNames().Length == 0 ||
                   bundle.isStreamedSceneAssetBundle);
        })
                                  .ToList();

        Debug.Log(list.Count);
        foreach (AssetBundle assetBundle in list)
        {
            Debug.Log(assetBundle.name);
        }
        foreach (AssetBundle assetBundle in list)
        {
            Debug.Log(assetBundle.isStreamedSceneAssetBundle);
        }
    }
Beispiel #27
0
    private static void getStatistic(Dictionary <string, HashSet <string> > map, BundleLoader bundleLoader)
    {
        bundleLoader.GetLoadedAssetBundles()
        .Where(bundle => bundle != null && !bundle.isStreamedSceneAssetBundle)
        .Take(40)
        .ToList()
        .ForEach(bundle => {
            bundle.GetAllAssetNames()
            .ToList()
            .ForEach(assetName => {
                Object asset = bundle.LoadAsset(assetName);
                if (asset == null)
                {
                    Debug.LogError(assetName);
                    return;
                }
                if (!map.ContainsKey(assetName.Split('.').Last()))
                {
                    map.Add(assetName.Split('.').Last(), new HashSet <string>());
                }
                map[assetName.Split('.').Last()].Add(asset.GetType() + "");
            });
        });

        string t = "";

        map.Keys.ToList()
        .ForEach(key => {
            t += key + "\n";
            map[key].ToList()
            .ForEach(value => {
                t += ("----" + value + "\n");
            });
        });
        Debug.LogError(t);
    }
    public IEnumerator LoadAsync(BundleLoader bundleloader, BundleLoaderSharedObject blso, string bundleResName, LoadCallBackHandler loadCallBack, ResourceCallBackHander resCallBack, HandlerParam HP, bool loadAssets)
    {
        mBundleName = bundleResName;
        AssetBundleCreateRequest bundleRequest;
        string path = BundleLoader.LoadBundleAsyncFromSDCard(mBundleName);

        if (File.Exists(path))
        {
            bundleRequest = AssetBundle.LoadFromFileAsync(path);
            yield return(bundleRequest);

            mAssetBundle = bundleRequest.assetBundle;
        }

        if (mAssetBundle == null)
        {
                        #if UNITY_ANDROID && !_TEST
            if (BundleLoader.mStreamBundleList.Contains(mBundleName))
                        #endif
            {
                bundleRequest = BundleLoader.LoadBundleAsyncFromStreamingAssets(mBundleName);
                yield return(bundleRequest);

                mAssetBundle = bundleRequest.assetBundle;
            }

#if UNITY_ANDROID
            if (mAssetBundle == null)
            {
                bundleRequest = BundleLoader.LoadBundleAsyncFromApkStreamingAssets(mBundleName);
                yield return(bundleRequest);

                mAssetBundle = bundleRequest.assetBundle;
            }
#endif

            if (mAssetBundle == null)
            {
                // DebugConsole.sendmsgServer(mBundleName + "not loaded!");
                bundleloader.RemoveAssetBundle(mBundleName);
                BundleManager.Instance.StartCoroutine(BundleLoader.LoadBundleFromWWW(bundleResName));
            }
        }

        int startIdx = mBundleName.LastIndexOf("/");
        int endIdx   = mBundleName.LastIndexOf(".");
        try
        {
            assName = mBundleName.Substring(startIdx + 1, endIdx - startIdx - 1);
        }
        catch (System.Exception e)
        {
        }

        if (loadAssets && loadCallBack != null)
        {
            mMainObject = mAssetBundle.LoadAsset(assName);
        }

        if (resCallBack != null)
        {
            resCallBack(blso, bundleResName, mAssetBundle, loadCallBack, HP, loadAssets);
        }
    }
Beispiel #29
0
 public static void RemoveFinishedLoader(BundleLoader l, string bundleName, Object[] assets, AssetBundle bundle)
 {
     InsertAssetToMap(bundleName, assets, bundle);
     LoadingList.Remove(l);
 }
Beispiel #30
0
 public static void AddLoadingLoader(BundleLoader l)
 {
     LoadingList.Add(l);
 }