Open C# file in External Script Editor

I can log something by Debug.Log("test"). I see this string at tab Console. If click at this string, will be open script editor (VS or Mono) with script file and line number with log command.

How I can this implement manual in code? For example, if catch log message by Application.LogCallback.

AssetDatabase.OpenAsset should do it for you. Will even tell the application to go to a specific line number.

If you’re looking to open in VS, I found this approach to be better.

string lPath = "SomeClass.cs";
foreach (var lAssetPath in AssetDatabase.GetAllAssetPaths())
{
    if (lAssetPath.EndsWith(lPath))
    {
        var lScript = (MonoScript)AssetDatabase.LoadAssetAtPath(lAssetPath, typeof(MonoScript));
        if (lScript != null)
        {
            AssetDatabase.OpenAsset(lScript);
            break;
        }
    }
}

This looks for the file matching the script name (“SomeClass.cs”) and opens the default script editor (ie Visual Studio).