private static void GeneratePluginRefStubCs(UnityPlugin plugin) { if (!plugin.enable) { return; } var refs = UnityPluginUtil.GetLib(plugin); if (refs == null || refs.Count == 0) { Debug.Log(plugin.pluginName + ": References C# generating... no references found"); return; } // header var allRefContent = string.Format(topHeader, plugin.pluginName); for (var i = 0; i < refs.Count; i++) { var r = refs[i]; var refName = Path.GetFileNameWithoutExtension(r); Debug.Log(refName); var assembly = Assembly.LoadFile(r); var output = plugin.stubPath.stubRefCSPath; GeneratePluginRefStubCs(plugin.pluginName, output, assembly); var tmp = ""; using (var sr = new StreamReader(output)) { tmp = sr.ReadToEnd(); } // remove #if UNITY_WAGAME // using Bridge; // using System; // at the begining of new ref stub content if (i > 0) { tmp = String.Join("\n", tmp.Split('\n').Skip(4)); } // remove #endif at last line tmp = tmp.Remove(tmp.TrimEnd().LastIndexOf(Environment.NewLine)); // ref header allRefContent += string.Format(refHeader, i, refName); allRefContent += tmp; allRefContent += "\n\n"; } // add #endif at the very last line allRefContent += "#endif"; using (var sw = new StreamWriter(plugin.stubPath.stubRefCSPath, false)) { sw.Write(allRefContent); } }
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(); } }