public void TestCallback1()
        {
            Action <CodegenTextWriter> callback = (w) => w.WriteLine("Hello3");

            _w
            // Inside indented block we call anonymous Action
            .WithCurlyBraces("void MyMethod1()", () =>
            {
                _w.WriteLine("Hello");
            })

            // Inside indented block we call anonymous Action<CodegenTextWriter>
            .WithCurlyBraces("void MyMethod2()", (w) =>
            {
                w.WriteLine("Hello2");
            })

            // Inside indented block we call a named Action<CodegenTextWriter>
            .WithCurlyBraces("void MyMethod3()", callback)

            // After (outside) the indented block we call a named Action<CodegenTextWriter>
            .Write(callback)
            ;

            string expected = @"
void MyMethod1()
{
    Hello
}
void MyMethod2()
{
    Hello2
}
void MyMethod3()
{
    Hello3
}
Hello3
";

            Assert.AreEqual(_w.ToString(), expected.TrimStart());
        }
        public void TestMultilineBlock()
        {
            _w
            .WithCurlyBraces("namespace MyNameSpace", (w) =>
            {
                _w.WithCurlyBraces("class MyClass", (w2) =>
                {
                    _w.WriteLine(@"
                         This is a multi-line block
                         This is a multi-line block
                         This is a multi-line block
                         This is a multi-line block
                        ");
                    _w.WriteLine(@"
                             This is a multi-line block
                             This is a multi-line block
                             This is a multi-line block
                             This is a multi-line block
                            ");
                    _w.WriteLine(@"
                                 This is a multi-line block
                                 This is a multi-line block
                                 This is a multi-line block
                                 This is a multi-line block
                            ");
                    _w.WriteLine(@"
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
                            ");
                });
            })
            ;
            string expected = @"
namespace MyNameSpace
{
    class MyClass
    {
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block

        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block

        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block

        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
        This is a multi-line block
                            
    }
}
";

            Assert.AreEqual(_w.ToString(), expected.TrimStart());
        }
Пример #3
0
        static void BuildDLCConfigInternal(DLCItem dlcItem)
        {
            var    builds       = AssetBundleBuildsCache = GenerateAssetBundleBuildData(dlcItem);
            string constPath    = dlcItem.GetConst();
            string manifestPath = dlcItem.GetManifest();
            string dlcItemPath  = dlcItem.GetConfig();

            List <string> bundles = new List <string>();
            List <string> assets  = new List <string>();

            if (builds.Count > 0)
            {
                foreach (var item in builds)
                {
                    bundles.Add(item.assetBundleName);
                    foreach (var assetPath in item.assetNames)
                    {
                        assets.Add(assetPath + ":" + (bundles.Count - 1));
                    }
                }
            }

            #region 创建Manifest文件
            if (File.Exists(manifestPath))
            {
                File.Delete(manifestPath);
            }
            DLCManifest dlcManifest = new DLCManifest();
            foreach (var item in builds)
            {
                BundleData tempData = new BundleData();
                tempData.DLCName = dlcItem.Name;
                if (AllBundles.ContainsKey(item.assetBundleName))
                {
                    tempData.BundleName = item.assetBundleName;
                    if (AllSharedBundles.Contains(item.assetBundleName))
                    {
                        tempData.IsShared = true;
                    }
                }
                else
                {
                    CLog.Error("没有包含:" + item.assetBundleName);
                }
                foreach (var asset in item.assetNames)
                {
                    AssetPathData pathData = new AssetPathData();
                    pathData.FullPath = asset;
                    pathData.FileName = Path.GetFileNameWithoutExtension(asset);
                    if (AllAssets.ContainsKey(asset))
                    {
                        pathData.SourceBundleName = AllAssets[asset];
                    }
                    tempData.AssetFullPaths.Add(pathData);
                }
                dlcManifest.Data.Add(tempData);
            }
            FileUtil.SaveJson(manifestPath, dlcManifest, true);
            #endregion

            #region dlcitem
            if (File.Exists(dlcItemPath))
            {
                File.Delete(dlcItemPath);
            }
            FileUtil.SaveJson(dlcItemPath, dlcItem.Config, true);
            #endregion

            #region const
            if (File.Exists(constPath))
            {
                File.Delete(constPath);
            }
            var cultureInfo = new System.Globalization.CultureInfo("en-us");
            var w           = new CodegenTextWriter(constPath, System.Text.Encoding.UTF8);
            w.WithCurlyBraces("namespace CYM", () =>
            {
                w.WithCurlyBraces("public partial class Const", () =>
                {
                    foreach (var bundleData in dlcManifest.Data)
                    {
                        string newBundleName = "";
                        foreach (var pathData in bundleData.AssetFullPaths)
                        {
                            if (pathData.SourceBundleName.IsInv())
                            {
                                continue;
                            }
                            //跳过指定的Bundle资源
                            if (pathData.SourceBundleName == Const.BN_System ||
                                pathData.SourceBundleName == Const.BN_Shared)
                            {
                                continue;
                            }
                            //获得相应的Bundle名称
                            if (pathData.SourceBundleName.StartsWith(Const.BN_Scene))
                            {
                                newBundleName = Const.BN_Scene;
                            }
                            else
                            {
                                newBundleName = pathData.SourceBundleName;
                            }
                            //保证变量名称有效
                            var fileName = pathData.FileName.Replace(".", "_").Replace("(", "_").Replace(")", "").Trim();
                            //加上前缀
                            fileName = newBundleName.ToUpper() + "_" + fileName;
                            //忽略不需要的Const
                            if (DLCConfig.IsInIgnoreConst(fileName))
                            {
                                continue;
                            }
                            if (Consts.Contains(fileName))
                            {
                                continue;
                            }
                            Consts.Add(fileName);
                            w.WriteLine($"public const string {fileName} = \"{pathData.FileName}\";");
                        }
                    }
                });
            });
            w.Flush();
            w.Dispose();
            #endregion

            CLog.Info("[Builder][{0}] BuildManifest with " + assets.Count + " assets and " + bundles.Count + " bundels.", dlcItem.Name);
        }