Created
August 3, 2019 13:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How To
Simply create a folder called Editor inside your Project window and add this script inside it.