赞
踩
参考:https://www.cnblogs.com/meteoric_cry/p/7880514.html
工具Unity-Shader:https://github.com/cjsjy123/Unity-Shader
实现功能
1.Unity编辑中双击.shader文件自动用Sublime Text打开
2.Sublime Text编辑Unity Shader,实现高亮和自动提示等功能
第一步:安装SublimeText,网上搜索即可
第二部:实现使用SublimeText打开.shader文件
- using UnityEngine;
- using UnityEditor;
- using System;
-
- public class LuaTxtEditor
- {
-
- //http://www.xuanyusong.com/archives/3702
- [UnityEditor.Callbacks.OnOpenAssetAttribute(1)]
- public static bool step1(int instanceID, int line)
- {
- return false;
- }
-
- [UnityEditor.Callbacks.OnOpenAssetAttribute(2)]
- public static bool step2(int instanceID, int line)
- {
- string strFilePath = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));
- string strFileName = System.IO.Directory.GetParent(Application.dataPath) + "/" + strFilePath;
-
- if (strFileName.EndsWith(".shader"))
- {
- string strSublimeTextPath = Environment.GetEnvironmentVariable("SublimeText_Path");
- if (strSublimeTextPath != null && strSublimeTextPath.Length > 0)
- {
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
- startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
- startInfo.FileName = strSublimeTextPath + (strSublimeTextPath.EndsWith("/") ? "" : "/") + "sublime_text.exe";
- startInfo.Arguments = "\"" + strFileName + "\"";
- process.StartInfo = startInfo;
- process.Start();
-
- //Debug.Log(startInfo.FileName + " \t " + startInfo.Arguments);
-
- return true;
- }
- else
- {
- Debug.Log("Not Found Enviroment Variable 'SublimeText_Path'.");
-
- return false;
- }
- }
-
- return false;
- }
-
- }
配置SublimeText_Path为本地SublimeText安装路径。配置后重启SublimeText即可实现功能1.
功能2:
1.下载Unity-Shader zip包解压,重命名为Unity-Shader
2.依次点击Sublime Text菜单 Preferences –> Browse Packages,将步骤1中解压后的Unity-Shader复制到该目录
3.修改UnityShader.sublime-settings,设置如下
- {
- // must set the path and version u5 or u4
- "Unity_Version":"U5",
- "Shader_path": "D:/Software/Unitys/Unity/Editor/Data/CGIncludes",
- "U5_Shader_path":"D:/Software/Unitys/Unity/Editor/Data/CGIncludes"
- }
4.设置个人快捷键,可操作preferences ->Packages settting -> Unity-Shader - >Keybinding
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。