Beispiel #1
0
        public static string LoadAssembly()
        {
            string error = "";

            if (_setting.Entity.IsScript)
            {
                ScriptCompiler.ClearTemp("smstemp");
                var refAsm = new string[] {
                    "NLog.dll",
                    "Newtonsoft.Json.dll",
                    "protobuf-net.dll",
                    "ZyGames.Framework.dll",
                    "ZyGames.Framework.Common.dll",
                    "ZyGames.Framework.Game.dll"
                };

                AppDomain.CurrentDomain.AppendPrivatePath(Path.Combine(MathUtils.RuntimePath, "smstemp"));
                var files = Directory.GetFiles(_setting.Entity.ScriptPath, "*.cs", SearchOption.AllDirectories);
                var cr    = ScriptCompiler.Compile(files, refAsm, "Entity.Model", false, false, "smstemp");
                if (cr != null)
                {
                    var assembly = cr.CompiledAssembly;
                    _setting.Entity.DymincEntity = assembly;
                }
                else
                {
                    error = "Compile fail";
                }
            }
            else
            {
                AppDomain.CurrentDomain.AppendPrivatePath(Path.GetFullPath(_setting.Entity.AssemblyPath));
                _setting.Entity.DymincEntity = AssemblyBuilder.ReadAssembly(_setting.Entity.AssemblyPath, null);
            }
            try
            {
                ProtoBufUtils.LoadProtobufType(_setting.Entity.DymincEntity);
            }
            catch (Exception)
            {
            }
            return(error);
        }