你可以这样做,但你必须知道两件事
1.Unity的framework dll所在位置:
当“脚本运行时版本”在编辑器中设置为“.NET 3.5 等效”时,使用的 C# DLL API 位于:
<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\unity
当编辑器中的“Scripting Runtime Version”设置为“.NET 4.x Equivalent”时,使用最新的框架,路径以框架版本结尾:
<UnityInstallationDirecory>\Editor\Data\MonoBleedingEdge\lib\mono\<API-version>
此路径将来可能会更改。要查找 Unity 正在使用的 dll 的当前路径,只需在 “解决方案资源管理器”选项卡中展开“程序集和引用”然后在 Visual Studio 中选择 C# DLL 之一。在下面的例子中,System.dll被选中,路径将显示在属性下。
2.C#标准框架dll所在位置:
在 Unity 编辑器中使用“.NET 3.5 Equivalent”时,使用的对应 C# 框架 API 位于:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client
在 Unity 编辑器中使用“.NET 4.x Equivalent”时,使用的对应 C# 框架 API 位于:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<API-version>
在 Visual Studio 中显示 C# 核心文档:
现在您已经知道了位置,请注意 #2 的标准框架位置 中的每个 dll 都有一个以 .xml 扩展名结尾的互补 xml 文件。例如,System.Core.dll dll 在同一文件夹中有名为 System.Core.xml 的补充文件。每个xml 文件都包含每个相应dll 文件的文档。
您所要做的就是将每个dll 文件的xml 文件从标准框架位置 复制到Unity 的框架dll 位置。重新启动 Visual Studio,文档应该可以正常工作。
手动操作很耗时,所以我制作了一个编辑器插件来处理它。通过转到 Programmer-->Enable Core Documentation 菜单启用它并通过转到 Programmer-->Disable 禁用它核心文档 菜单。您必须重新启动 Visual Studio 才能使其生效。
using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class DocEnabler : MonoBehaviour
{
//Replace both with the proper paths on your system
static string unityFrameworkPath = @"G:\Applications\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unity";
static string stdCoreFrameworkPath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client";
[MenuItem("Programmer/Enable Core Documentation")]
static void EnableCoreDoc()
{
CopyFilesByExt(stdCoreFrameworkPath, unityFrameworkPath, "xml");
}
[MenuItem("Programmer/Disable Core Documentation")]
static void DisableCoreDoc()
{
DeleteFilesByExt(unityFrameworkPath, "xml");
}
static void DeleteFilesByExt(string path, string ext)
{
DirectoryInfo drctyInfo = new DirectoryInfo(path);
FileInfo[] files = drctyInfo.GetFiles("*." + ext)
.Where(p => p.Extension == "." + ext).ToArray();
foreach (FileInfo file in files)
{
try
{
file.Attributes = FileAttributes.Normal;
file.Delete();
//File.Delete(file.FullName);
}
catch (Exception e)
{
Debug.Log("Error while deleting file: " + file.Name + "\r\n" + e.Message);
}
}
DoneMessage();
}
static void CopyFilesByExt(string source, string destPath, string ext)
{
DirectoryInfo drctyInfo = new DirectoryInfo(source);
FileInfo[] files = drctyInfo.GetFiles("*." + ext)
.Where(p => p.Extension == "." + ext).ToArray();
foreach (FileInfo file in files)
{
try
{
string fromPath = file.FullName;
string toPath = Path.Combine(destPath, file.Name);
file.CopyTo(toPath, true);
//File.Copy(fromPath, toPath, true);
}
catch (Exception e)
{
Debug.Log("Error while Copying file: " + file.Name + "\r\n" + e.Message);
}
}
DoneMessage();
}
static void DoneMessage()
{
Debug.Log("Action complete. Restart Visual Studio for the changes to take effect");
}
}