Beispiel #1
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, string name, bool loadDeps = false)
        {
            int index = bunInst.file.GetFileIndex(name);

            if (index < 0)
            {
                return(null);
            }

            return(LoadAssetsFileFromBundle(bunInst, index, loadDeps));
        }
Beispiel #2
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, string name, bool loadDeps = false)
        {
            var dirInf = bunInst.file.bundleInf6.dirInf;

            for (int i = 0; i < dirInf.Length; i++)
            {
                if (dirInf[i].name == name)
                {
                    return(LoadAssetsFileFromBundle(bunInst, i, loadDeps));
                }
            }
            return(null);
        }
        public BundleFileInstance LoadBundleFile(FileStream stream)
        {
            BundleFileInstance instance;
            int index = bundles.FindIndex(f => f.path.ToLower() == Path.GetFullPath(stream.Name).ToLower());

            if (index == -1)
            {
                instance = new BundleFileInstance(stream, "");
                bundles.Add(instance);
            }
            else
            {
                instance = bundles[index];
            }
            return(instance);
        }
Beispiel #4
0
        public BundleFileInstance LoadBundleFile(FileStream stream, bool unpackIfPacked = true)
        {
            BundleFileInstance bunInst;
            int index = bundles.FindIndex(f => f.path.ToLower() == Path.GetFullPath(stream.Name).ToLower());

            if (index == -1)
            {
                bunInst = new BundleFileInstance(stream, "", unpackIfPacked);
                bundles.Add(bunInst);
            }
            else
            {
                bunInst = bundles[index];
            }
            return(bunInst);
        }
Beispiel #5
0
        public BundleFileInstance LoadBundleFile(Stream stream, string path, bool unpackIfPacked = true)
        {
            BundleFileInstance bunInst;
            int index = bundles.FindIndex(f => f.path.ToLower() == path.ToLower());

            if (index == -1)
            {
                bunInst = new BundleFileInstance(stream, path, "", unpackIfPacked);
                bundles.Add(bunInst);
            }
            else
            {
                bunInst = bundles[index];
            }
            return(bunInst);
        }
Beispiel #6
0
        public void LoadBundleDependencies(AssetsFileInstance ofFile, BundleFileInstance ofBundle, string path)
        {
            for (int i = 0; i < ofFile.dependencies.Count; i++)
            {
                string depPath = ofFile.file.dependencies.dependencies[i].assetPath;
                if (files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(depPath).ToLower()) == -1)
                {
                    string bunPath  = Path.GetFileName(depPath);
                    int    bunIndex = Array.FindIndex(ofBundle.file.bundleInf6.dirInf, d => Path.GetFileName(d.name) == bunPath);

                    //by default, the directory of an assets file is the bundle's file path (somepath\bundle.unity3d\file.assets)
                    //we back out again to get the directory the bundle is in
                    string noBunPath      = Path.Combine(path, "..");
                    string nbAbsPath      = Path.Combine(noBunPath, depPath);
                    string nbLocalAbsPath = Path.Combine(noBunPath, Path.GetFileName(depPath));

                    //if the user chose to set the path to the directory the bundle is in,
                    //we need to check for that as well
                    string absPath      = Path.Combine(path, depPath);
                    string localAbsPath = Path.Combine(path, Path.GetFileName(depPath));

                    if (bunIndex != -1)
                    {
                        LoadAssetsFileFromBundle(ofBundle, bunIndex, true);
                    }
                    else if (File.Exists(absPath))
                    {
                        LoadAssetsFile(File.OpenRead(absPath), true);
                    }
                    else if (File.Exists(localAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(localAbsPath), true);
                    }
                    else if (File.Exists(nbAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(nbAbsPath), true);
                    }
                    else if (File.Exists(nbLocalAbsPath))
                    {
                        LoadAssetsFile(File.OpenRead(nbLocalAbsPath), true);
                    }
                }
            }
        }
Beispiel #7
0
        public bool UnloadBundleFile(string path)
        {
            int index = bundles.FindIndex(f => f.path.ToLower() == Path.GetFullPath(path).ToLower());

            if (index != -1)
            {
                BundleFileInstance bunInst = bundles[index];
                bunInst.file.Close();

                foreach (AssetsFileInstance assetsInst in bunInst.assetsFiles)
                {
                    assetsInst.file.Close();
                }

                bundles.Remove(bunInst);
                return(true);
            }
            return(false);
        }
Beispiel #8
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, int index, bool loadDeps = false)
        {
            string assetMemPath = Path.Combine(bunInst.path, bunInst.file.GetFileName(index));

            int listIndex = files.FindIndex(f => f.path.ToLower() == Path.GetFullPath(assetMemPath).ToLower());

            if (listIndex == -1)
            {
                if (bunInst.file.IsAssetsFile(index))
                {
                    bunInst.file.GetFileRange(index, out long offset, out long length);
                    SegmentStream      stream     = new SegmentStream(bunInst.stream, offset, length);
                    AssetsFileInstance assetsInst = LoadAssetsFile(stream, assetMemPath, loadDeps, bunInst: bunInst);
                    bunInst.loadedAssetsFiles.Add(assetsInst);
                    return(assetsInst);
                }
            }
            else
            {
                return(files[listIndex]);
            }
            return(null);
        }
Beispiel #9
0
        public AssetsFileInstance LoadAssetsFileFromBundle(BundleFileInstance bunInst, int index, bool loadDeps = false)
        {
            var    dirInf       = bunInst.file.bundleInf6.dirInf[index];
            string assetMemPath = Path.Combine(bunInst.path, dirInf.name);

            int listIndex = files.FindIndex(f => f.path.ToLower() == Path.GetFullPath(assetMemPath).ToLower());

            if (listIndex == -1)
            {
                if (bunInst.file.IsAssetsFile(bunInst.file.reader, dirInf))
                {
                    byte[]             assetData  = BundleHelper.LoadAssetDataFromBundle(bunInst.file, index);
                    MemoryStream       ms         = new MemoryStream(assetData);
                    AssetsFileInstance assetsInst = LoadAssetsFile(ms, assetMemPath, loadDeps, bunInst: bunInst);
                    bunInst.assetsFiles.Add(assetsInst);
                    return(assetsInst);
                }
            }
            else
            {
                return(files[listIndex]);
            }
            return(null);
        }
Beispiel #10
0
        public AssetsFileInstance LoadAssetsFile(Stream stream, string path, bool loadDeps, string root = "", BundleFileInstance bunInst = null)
        {
            AssetsFileInstance instance;
            int index = files.FindIndex(f => f.path.ToLower() == Path.GetFullPath(path).ToLower());

            if (index == -1)
            {
                instance = new AssetsFileInstance(stream, path, root);
                files.Add(instance);
            }
            else
            {
                instance = files[index];
            }

            if (loadDeps)
            {
                if (bunInst == null)
                {
                    LoadDependencies(instance, Path.GetDirectoryName(path));
                }
                else
                {
                    LoadBundleDependencies(instance, bunInst, Path.GetDirectoryName(path));
                }
            }
            if (updateAfterLoad)
            {
                UpdateDependencies(instance);
            }
            return(instance);
        }