当前位置:   article > 正文

SublimeText3配置UnityShader编辑环境_unity shader 格式化

unity shader 格式化

参考: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文件

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. public class LuaTxtEditor
  5. {
  6. //http://www.xuanyusong.com/archives/3702
  7. [UnityEditor.Callbacks.OnOpenAssetAttribute(1)]
  8. public static bool step1(int instanceID, int line)
  9. {
  10. return false;
  11. }
  12. [UnityEditor.Callbacks.OnOpenAssetAttribute(2)]
  13. public static bool step2(int instanceID, int line)
  14. {
  15. string strFilePath = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));
  16. string strFileName = System.IO.Directory.GetParent(Application.dataPath) + "/" + strFilePath;
  17. if (strFileName.EndsWith(".shader"))
  18. {
  19. string strSublimeTextPath = Environment.GetEnvironmentVariable("SublimeText_Path");
  20. if (strSublimeTextPath != null && strSublimeTextPath.Length > 0)
  21. {
  22. System.Diagnostics.Process process = new System.Diagnostics.Process();
  23. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  24. startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  25. startInfo.FileName = strSublimeTextPath + (strSublimeTextPath.EndsWith("/") ? "" : "/") + "sublime_text.exe";
  26. startInfo.Arguments = "\"" + strFileName + "\"";
  27. process.StartInfo = startInfo;
  28. process.Start();
  29. //Debug.Log(startInfo.FileName + " \t " + startInfo.Arguments);
  30. return true;
  31. }
  32. else
  33. {
  34. Debug.Log("Not Found Enviroment Variable 'SublimeText_Path'.");
  35. return false;
  36. }
  37. }
  38. return false;
  39. }
  40. }

配置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,设置如下

  1. {
  2. // must set the path and version u5 or u4
  3. "Unity_Version":"U5",
  4. "Shader_path": "D:/Software/Unitys/Unity/Editor/Data/CGIncludes",
  5. "U5_Shader_path":"D:/Software/Unitys/Unity/Editor/Data/CGIncludes"
  6. }

4.设置个人快捷键,可操作preferences ->Packages settting -> Unity-Shader - >Keybinding 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/810544
推荐阅读
相关标签
  

闽ICP备14008679号