コード例 #1
0
ファイル: ProtoBufNetMenus.cs プロジェクト: fuboss/aiProject
 public static void CompileSerializationDLL()
 {
     string text = "ProtoBufNetPrecompiledSeriaizer";
     string text2 = text + ".dll";
     string text3 = "Assets/" + text2;
     RuntimeTypeModel.CompilerOptions options = new RuntimeTypeModel.CompilerOptions
     {
         TypeName = text,
         OutputPath = text2,
         ImageRuntimeVersion = Assembly.GetExecutingAssembly().ImageRuntimeVersion,
         MetaDataVersion = 131072,
         Accessibility = RuntimeTypeModel.Accessibility.Public
     };
     RuntimeTypeModel runtimeTypeModel = TypeModelCreator.CreateModel();
     try
     {
         runtimeTypeModel.Compile(options);
     }
     catch (Exception)
     {
         Debug.LogError("Make sure to compile to protobuf-net DLL while the editor is not in AOT mode");
         throw;
     }
     try
     {
         File.Delete(text3);
     }
     catch (Exception)
     {
     }
     try
     {
         File.Move(text2, text3);
     }
     catch (Exception)
     {
         Debug.LogWarning(string.Format("Unable to move {0} to {1}", text2, text3));
     }
     AssetDatabase.ImportAsset(text3, ImportAssetOptions.ForceUpdate);
     StringBuilder stringBuilder = new StringBuilder();
     foreach (object current in runtimeTypeModel.GetTypes())
     {
         stringBuilder.AppendLine(current.ToString());
     }
     Debug.Log("Finished compiling protobuf-net serialization DLL (at " + text3 + "). It contains serialization data for the following types:\n\n" + stringBuilder.ToString());
 }
コード例 #2
0
        public static void PrecompileSerializer(string outputPath) {
            if (EditorApplication.isCompiling) {
                Debug.LogWarning("The precompiled serializer canot be created while Unity is " +
                    "compiling code. Please try again once compilation has finished.");
                return;
            }
            if (_decompilationProcess != null) {
                Debug.LogWarning("A prior precompiled serializer process is still running.");
                return;
            }

            string TypeName = ProtoBufNetSettings.PrecompiledSerializerTypeName;
            string DllPath = TypeName + ".dll";

            var options = new RuntimeTypeModel.CompilerOptions {
                TypeName = TypeName,
                OutputPath = DllPath,
                ImageRuntimeVersion = Assembly.GetExecutingAssembly().ImageRuntimeVersion,
                MetaDataVersion = 0x20000, // use .NET 2 onwards
                Accessibility = RuntimeTypeModel.Accessibility.Public
            };

            // Create the precompiled serializer
            var model = TypeModelCreator.CreateModel();
            try {
                model.Compile(options);

                var output = new StringBuilder();
                output.AppendLine("Created protobuf-net serialization DLL (at " +
                    Path.GetFullPath(DllPath) + "). It contains serialization data for the " +
                    "following types:");
                foreach (var modelType in model.GetTypes()) {
                    output.Append('\t');
                    output.AppendLine(modelType.ToString());
                }
                Debug.Log(output.ToString());
            }
            catch (Exception) {
                Debug.LogError("Make sure to compile to protobuf-net DLL while the editor is " +
                    "not in AOT mode");
                throw;
            }

            // Run the decompiler
            var searchPaths = new List<string>() {
                Path.GetDirectoryName(typeof(CommonBaseBehavior).Assembly.Location), // Scripts (Assembly-CSharp and the like)
                Path.GetDirectoryName(typeof(UnityEngine.Object).Assembly.Location), // UnityEngine.dll
            };
            searchPaths.AddRange(from string directory in Directory.GetDirectories("Assets" + Path.DirectorySeparatorChar, "*", SearchOption.AllDirectories)
                                 where (directory.Contains("/.") || directory.Contains("\\.")) == false
                                 where Directory.GetFiles(directory, "*.dll").Count() > 0
                                 select Path.GetFullPath(directory));

            DllPath = Path.GetFullPath(DllPath);
            outputPath = Path.GetFullPath(outputPath);

            RunDecompiler(outputPath, DllPath, searchPaths.ToArray());
        }