Unity生成的c#項目名字默認爲Assembly-CSharp.csproj
和Assembly-CSharp-firstpass.csproj
。
但是最近看到部分項目名字變成了{projectname}.csproj
和{projectname}.Plugins.csproj
。
測試得出,Visual Studio Tools for Unity(VSTU)
會自動修改csproj文件名爲{projectname}
。查閱文檔也發現ChangeLog有相應的記錄說明和Bug修正。
爲了保證csproj的文件名相同,需要讓所有機器都安裝了VSTU
。
VS2015之前的版本,可以通過擴展和更新安裝。
VS2017之後的版本,則需要通過Visual Studio Installer
安裝。
另外在查文檔的時候,看到VSTU
有包含少量可編程方法的說明。
Customize Project Files Created by VSTU
修改VSTU生成出來的csproj文件using System; using System.IO; using System.Linq; using System.Text; using System.Xml.Linq; using UnityEngine; using UnityEditor; using SyntaxTree.VisualStudio.Unity.Bridge; [InitializeOnLoad] public class ProjectFileHook { // necessary for XLinq to save the xml project file in utf8 class Utf8StringWriter : StringWriter { public override Encoding Encoding { get { return Encoding.UTF8; } } } static ProjectFileHook() { ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) => { // parse the document and make some changes var document = XDocument.Parse(content); document.Root.Add(new XComment("FIX ME")); // save the changes using the Utf8StringWriter var str = new Utf8StringWriter(); document.Save(str); return str.ToString(); }; } }
Share the Unity Log Callback with VSTU
共享Visual Studio的輸出到Unityusing System; using UnityEngine; using UnityEditor; using SyntaxTree.VisualStudio.Unity.Bridge; [InitializeOnLoad] public class LogCallbackHook { static LogCallbackHook() { VisualStudioIntegration.LogCallback += (string condition, string trace, LogType type) => { // place code that implements your log callback here }; } }