예제 #1
0
        public override void Work(RuntimeTypeModel model)
        {
            foreach (Type unityObjectType in fiRuntimeReflectionUtility.GetUnityObjectTypes())
            {
                if (TypeModelCreator.IsInIgnoredAssembly(unityObjectType))
                {
                    continue;
                }

                var surrogateType = typeof(UnityObjectSurrogate <>).MakeGenericType(unityObjectType);
                SetSurrogate(model, unityObjectType, surrogateType);
            }
        }
예제 #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());
        }