protected bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result)
        {
            if (type == typeof(ScenarioData))
            {
                string scenarioPath = Path.Combine(scenarioDir, Path.Combine(assetBundleName, $"{assetName}.csv")).Replace('/', '\\').Replace(".unity3d", "").Replace(@"adv\scenario\", "");

                if (File.Exists(scenarioPath))
                {
                    var rawData = ManualLoadAsset <ScenarioData>(assetBundleName, assetName, manifestAssetBundleName);

                    rawData.list.Clear();

                    foreach (IEnumerable <string> line in SplitAndEscape(File.ReadAllText(scenarioPath, Encoding.UTF8)))
                    {
                        string[] data = line.ToArray();

                        string[] args = new string[data.Length - 4];

                        Array.Copy(data, 4, args, 0, args.Length);

                        ScenarioData.Param param = new ScenarioData.Param(bool.Parse(data[3]), (Command)int.Parse(data[2]), args);

                        param.SetHash(int.Parse(data[0]));

                        rawData.list.Add(param);
                    }

                    result = new AssetBundleLoadAssetOperationSimulation(rawData);
                    return(true);
                }
            }
            else if (type == typeof(ExcelData))
            {
                string communicationPath = Path.Combine(communicationDir, Path.Combine(assetBundleName.Replace("communication/", ""), $"{assetName}.csv")).Replace('/', '\\').Replace(".unity3d", "");


                if (File.Exists(communicationPath))
                {
                    var rawData = ManualLoadAsset <ExcelData>(assetBundleName, assetName, manifestAssetBundleName);

                    rawData.list.Clear();

                    foreach (IEnumerable <string> line in SplitAndEscape(File.ReadAllText(communicationPath, Encoding.UTF8)))
                    {
                        ExcelData.Param param = new ExcelData.Param()
                        {
                            list = line.ToList()
                        };

                        rawData.list.Add(param);
                    }

                    result = new AssetBundleLoadAssetOperationSimulation(rawData);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
Beispiel #2
0
        public static bool RedirectHook(string assetBundleName, string assetName, Type type, string manifestAssetBundleName, out AssetBundleLoadAssetOperation result)
        {
            string TranslationPath = Path.Combine(DynamicTranslator.dirTranslation, Path.Combine(assetBundleName, assetName)).Replace('/', '\\').Replace(".unity3d", "");

            if (type == typeof(ScenarioData))
            {
                if (Directory.Exists(TranslationPath) || File.Exists(TranslationPath + ".csv"))
                {
                    var rawData = ManualLoadAsset <ScenarioData>(assetBundleName, assetName, manifestAssetBundleName);

                    //Clear the data and load the new data from the .csv, if there is one.
                    if (File.Exists(TranslationPath + ".csv"))
                    {
                        rawData.list.Clear();

                        foreach (var line in SplitAndEscape(File.ReadAllText(TranslationPath + ".csv", Encoding.UTF8)))
                        {
                            var data = line.ToArray();
                            var args = new string[data.Length - 4];

                            Array.Copy(data, 4, args, 0, args.Length);

                            var param = new ScenarioData.Param(bool.Parse(data[3]), (Command)int.Parse(data[2]), args);

                            param.SetHash(int.Parse(data[0]));

                            rawData.list.Add(param);
                        }
                    }

                    //Read any .txt translations and substitute translated text
                    if (Directory.Exists(TranslationPath))
                    {
                        foreach (var param in rawData.list)
                        {
                            if (param.Command == Command.Text)
                            {
                                for (int i = 0; i < param.Args.Count(); i++)
                                {
                                    param.Args[i] = TranslateTextFromFolder(param.Args[i], TranslationPath);
                                }
                            }
                        }
                    }

                    result = new AssetBundleLoadAssetOperationSimulation(rawData);
                    return(true);
                }
            }
            else if (type == typeof(ExcelData))
            {
                if (Directory.Exists(TranslationPath) || File.Exists(TranslationPath + ".csv"))
                {
                    var rawData = ManualLoadAsset <ExcelData>(assetBundleName, assetName, manifestAssetBundleName);

                    //Clear the data and load the new data from the .csv, if there is one.
                    if (File.Exists(TranslationPath + ".csv"))
                    {
                        rawData.list.Clear();

                        foreach (var line in SplitAndEscape(File.ReadAllText(TranslationPath + ".csv", Encoding.UTF8)))
                        {
                            var list  = line.ToList();
                            var param = new ExcelData.Param();
                            param.list = list;

                            rawData.list.Add(param);
                        }
                    }

                    //Read any .txt translations and substitute translated text
                    if (Directory.Exists(TranslationPath))
                    {
                        foreach (var param in rawData.list)
                        {
                            for (int i = 0; i < param.list.Count; i++)
                            {
                                param.list[i] = TranslateTextFromFolder(param.list[i], TranslationPath);
                            }
                        }
                    }

                    result = new AssetBundleLoadAssetOperationSimulation(rawData);
                    return(true);
                }
            }

            result = null;
            return(false);
        }