Skip to content

Instantly share code, notes, and snippets.

@yasirkula
Created August 3, 2019 13:14
Show Gist options
  • Save yasirkula/304cbae5087991237f739bff8c7a654c to your computer and use it in GitHub Desktop.
Save yasirkula/304cbae5087991237f739bff8c7a654c to your computer and use it in GitHub Desktop.
An editor script for Unity 3D to open shaders in Notepad++ or the default text editor
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
public class OpenShaderInNotepad
{
private const string NPP1 = @"C:\Program Files\Notepad++\notepad++.exe";
private const string NPP2 = @"C:\Program Files (x86)\Notepad++\notepad++.exe";
[OnOpenAsset]
#if UNITY_2019_2_OR_NEWER
public static bool OpenInNotepad( int instanceID, int line, int column )
#else
public static bool OpenInNotepad( int instanceID, int line )
#endif
{
Object asset = EditorUtility.InstanceIDToObject( instanceID );
if( asset != null && !asset.Equals( null ) && asset is Shader && AssetDatabase.Contains( asset ) )
{
string shaderPath = Path.GetFullPath( AssetDatabase.GetAssetPath( instanceID ) );
string args = "\"" + shaderPath + "\"";
if( line >= 0 )
args += " -n" + line;
#if UNITY_2019_2_OR_NEWER
if( column >= 0 )
args += " -c" + column;
#endif
if( File.Exists( NPP1 ) )
Process.Start( NPP1, args );
else if( File.Exists( NPP2 ) )
Process.Start( NPP2, args );
else
Process.Start( shaderPath );
return true;
}
return false;
}
}
@yasirkula
Copy link
Author

yasirkula commented Aug 3, 2019

How To

Simply create a folder called Editor inside your Project window and add this script inside it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment