I searched the forum and found nothing specific. I know about External Tools, I think this is more relevant here.
So I know there is no good support for shader languages, but I hope that my current setup can be improved.
Pretty much the only extension for VS2019 I found was HLSL Tools for Visual Studio. It works, but only with pure *.hlsl code. It highlights red the inclusion of other files and any built-in unity stuff. Long story short, I couldn’t get it to work with *.shader. If anybody knows how to do it, please share your experience.
Then I looked towards VS Code, which has wider choice of extensions. The best was Shader languages support for VS Code. It colorizes everything, knows intrinsic functions and semantics of HLSL. However, to make it fully work in *.shader files, I had to modify settings.json inside VS Code.
{
...
"files.associations": {
"*.shader" : "hlsl"
}
}
But I haven’t been able to make Unity and VS Code friends in the sense of C# programming. So the next problem was how to open different files inside Unity Editor with different IDE’s (default being VS2019). I’ve done it with the editor script, if anyone is interested here it is:
using UnityEditor;
using UnityEditor.Callbacks;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
public static class ExternalToolSelector
{
static readonly ProcessStartInfo vsCodeInfo = new ProcessStartInfo("Your path to /Code.exe"); //insert full path to file
static readonly HashSet<System.Type> vsCodeTypes = new HashSet<System.Type>
{
typeof(UnityEngine.TextAsset), //hlsl is considered text
typeof(UnityEngine.Shader)
};
[OnOpenAsset(1)]
public static bool HandleOpenAsset(int instanceID, int line)
{
var asset = Selection.activeObject;
var assetPath = AssetDatabase.GetAssetPath(asset);
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (vsCodeTypes.Contains(assetType)) //can check file extension instead
{
vsCodeInfo.Arguments = "\"" + Path.GetFullPath(assetPath) + "\""; //without "" will break at spaces
Process.Start(vsCodeInfo);
return true;
}
return false;
}
}
Now scripts and shaders open in different programs. Someone will not like this approach, but I can live with it. The only problem I still have is that VS Code suggests anything but variables and functions I declare. It doesn’t see them and their contents…
By the way, there was no such problem in VS2019 HLSL plugin (except everything else was the problem). I don’t have much experience in this kind of stuff. How can this be fixed? Or, if you know better way to streamline the work with shaders, I will be very grateful.