Exemple #1
0
        // 指定路径读取
        public byte[] LoadBytesFromDir(string dir, string path)
        {
            if (ZipEntries.ContainsKey(dir) && ZipEntries[dir].ContainsKey(path))
            {
                return(GetDataFromZip(ZipEntries[dir][path]));
            }

            string modPath = Path.Combine(dir, path);

            if (!File.Exists(modPath))
            {
                modPath = modPath.Replace("/" + GameConfig.Language, "");
                if (!File.Exists(modPath))
                {
                    return(null);
                }
            }
            return(GetDataFromFile(modPath));
        }
Exemple #2
0
        public ModResourceProvider(ICoroutineRunner runner, string modBaseDir, string[] modPaths) : base(runner)
        {
            for (int i = 0; i < modPaths.Length; ++i)
            {
                string dir = Path.Combine(modBaseDir, modPaths[i]);
                if (Directory.Exists(dir))
                {
                    Console.WriteLine("检测到Mod路径: " + dir);
                    ModDirectories.Add(dir);

                    string zip = Path.Combine(dir, "Config.zip");
                    if (File.Exists(zip))
                    {
                        Console.WriteLine("检测到压缩格式Mod档案: " + zip);
                        ZipFile zipFile = ZipFile.Read(zip);
                        ZipEntries.Add(dir, zipFile.ToDictionary((ZipEntry x) => x.FileName.ToLower(), (ZipEntry x) => x));
                    }

                    // 扩展AssetBundleSheet
                    string extraSheetFile = Path.Combine(dir, "AssetBundleSheet.sheet");
                    if (File.Exists(extraSheetFile))
                    {
                        Console.WriteLine("检测到扩展AssetBundleSheet: " + extraSheetFile);
                        byte[]           array       = File.ReadAllBytes(extraSheetFile);
                        AssetBundleSheet modSheet    = JsonConvert.DeserializeObject <AssetBundleSheet>(Encoding.UTF8.GetString(array));
                        AssetBundleSheet sourceSheet = Traverse.Create(BundleManagerBySheet.Instance()).Field("bundleSheet").GetValue <AssetBundleSheet>();
                        Console.WriteLine(string.Format("扩展Sheet bundle={0}, file={1}", modSheet.BundleList.Count, modSheet.FilesInfo.Count));
                        Console.WriteLine(string.Format("原始Sheet bundle={0}, file={1}", sourceSheet.BundleList.Count, sourceSheet.FilesInfo.Count));
                        foreach (var bundle in modSheet.BundleList)
                        {
                            sourceSheet.BundleList.Add(bundle.Key, bundle.Value);
                        }
                        foreach (var file in modSheet.FilesInfo)
                        {
                            sourceSheet.FilesInfo.Add(file.Key, file.Value);
                        }
                        Console.WriteLine(string.Format("合并Sheet bundle={0}, file={1}", sourceSheet.BundleList.Count, sourceSheet.FilesInfo.Count));
                    }
                }
            }
        }