private static void GeneratePluginStubDLL(UnityPlugin config)
        {
            if (!config.enable)
            {
                return;
            }

            if (references == null)
            {
                references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~"));
            }

            var sources = new List <string>()
            {
                config.stubPath.stubCSPath
            };

            // Add refCS stub file
            var refCS = config.stubPath.stubRefCSPath;

            if (refCS != null && File.Exists(refCS))
            {
                sources.Add(refCS);
            }

            var os = File.Create(config.stubPath.stubDLLPath);

            // var refs = UnityPluginUtil.GetLib(config, true, true);
            var refs = new List <string>()
            {
                references["Bridge"]["Bridge.dll"], UnityPluginUtil.GetUnityEngineStub().stubPath.stubDLLPath
            };

            if (refs == null || refs.Count == 0)
            {
                return;
            }

            EmitResult result;

            try {
                result = DLLProc.BuildDLL(config.pluginName + "-stub", os, sources, config.defineMacros,
                                          refs, true);
            } finally {
                os.Close();
            }
            if (result == null || !result.Success)
            {
                throw new Exception();
            }
        }
        private static void GeneratePluginDLL(UnityPlugin config)
        {
            if (!config.enable)
            {
                return;
            }
            var sources = UnityPluginUtil.GetSource(config);
            var exc     = UnityPluginUtil.GetExclude(config);

            sources = sources.Except(exc).ToList();
            if (sources == null || sources.Count == 0)
            {
                return;
            }

            var refs = UnityPluginUtil.GetLib(config, true, true);

            if (refs == null || refs.Count == 0)
            {
                return;
            }

            // rename dist dll
            var dist = config.stubPath.stubDLLPath.Replace("-stub.dll", "-internal.dll");
            var os   = File.Create(dist);

            EmitResult result;

            try {
                // comment this for TMP issue(internal visibility)
                result = DLLProc.BuildDLL(config.pluginName /* + "-internal" */, os, sources, config.defineMacros,
                                          refs, true);
            } finally {
                os.Close();
            }
            if (result == null || !result.Success)
            {
                throw new Exception();
            }
        }
Beispiel #3
0
        private static Compilation BuildDLL(ProjectExportConfig config)
        {
            // var sources = config.project.AllSources().ToList();
            // var references = config.project.AllReferences().ToList();
            var sources  = ProjectExportUtil.GetProjectSourcesWithoutExcludes(config);
            var excludes = new List <string>();

            excludes.Add("**/*~/**/*.dll");
            excludes.Add("**/[Ee]ditor/**/*.dll");
            excludes.Add("**/script-export/**/*.dll");
            var references = ProjectExportUtil.GetProjectLibs(config, excludes);

            references.AddRange(UnityPluginUtil.GetUnityEngineLibs());
            // references.AddRange(DLLProc.SystemDLLPath());
            // references.AddRange(DLLProc.UnityEngineDLLPath());
            // references.AddRange(DLLProc.SystemDLLPath());
            Debug.Log("Building Assembly for sources[" + sources.Count + "], references[" + references.Count + "]");
            return(DLLProc.BuildDLL("WAGameUnityProject",
                                    sources,
                                    config.defineMacros,
                                    references, true));
        }
        public static void GeneUnityStub(bool overwrite = true)
        {
            var unity = UnityPluginUtil.GetUnityEngineStub();

            if (!overwrite && File.Exists(unity.stubPath.stubCSPath))
            {
                Debug.LogWarning("UnityEngine Stub Exist.");
                return;
            }
            if (unity.stubConfig.generateStub)
            {
                // UnityStubBuilder.Build(unity.stubPath.stubCSPath);
                // 这里改用反射
                // UnityStubBuilder.cs 需要被单独作为c#源文件放出,编DLL时不能耦合
                // Type.GetType("WeChat.UnityStubBuilder").GetMethod("Build").Invoke(null, new object[] { unity.stubPath.stubCSPath });

                // 这里改用回调,DLL里调用反射拿不到C#源文件里定义的类,有空再查
                if (genUnityStubCallback != null)
                {
                    genUnityStubCallback.Invoke(unity.stubPath.stubCSPath);
                }
            }

            // header
            var allRefContent = string.Format(topHeader, unity.pluginName);

            string content = "";

            using (StreamReader sr = new StreamReader(unity.stubPath.stubCSPath)) {
                content = sr.ReadToEnd();
            }
            if (content == null || content == "" || content.Length == 0)
            {
                return;
            }

            using (var sw = new StreamWriter(unity.stubPath.stubCSPath, false)) {
                sw.Write(allRefContent);
                sw.Write(content);
            }

            var sources = new List <string>()
            {
                unity.stubPath.stubCSPath
            };
            var dir = new DirectoryInfo(Path.GetDirectoryName(unity.stubPath.stubDLLPath));

            if (!dir.Exists)
            {
                dir.Create();
            }
            var os = File.Create(unity.stubPath.stubDLLPath);

            if (references == null)
            {
                references = DirectoryBuilder.RegisterDirectory("references", new DirectoryStructure("References~"));
            }
            var refs = new List <string>()
            {
                references["Bridge"]["Bridge.dll"]
            };

            EmitResult result;

            try {
                result = DLLProc.BuildDLL("UnityEngine-stub", os, sources, unity.defineMacros,
                                          refs, true);
            } finally {
                os.Close();
            }
            if (result == null || !result.Success)
            {
                throw new Exception();
            }
            Debug.Log("Generate Stub <UnityEngine>");
        }