Shader编辑器

VS对Shader的支持太弱了,一直在寻找一个靠谱的shader编辑器,终于Sublime Text被我找到了。
Unity中双击xxx.shader打开Sublime Text,可在Sublime Text中对常用的函数进行提示,并支持函数的跳转。
这就分为二个功能:

1、双击shader文件打开Sublime Text;

2、使用Sublime Text来编辑shader;

一:双击shader文件打开Sublime Text
在Assets目录下建立“Editor”目录,编写ShaderEditor.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ShaderEditor : MonoBehaviour
{
    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;
    }
}

然后,你需要设置 Sublime Text的环境变量 SublimeText_Path
Sublime Text的环境变量
此时,双击 shader 可能仍无法直接打开 Sublime Text。你需要关闭 Unity

二:使用Sublime Text来编辑shader

下载插件包,前往https://gitee.com/GAXM/ShaderIDE/tree/master 直接下载zip文件
安装 package,Sublime Text菜单 Preferences –> Browse Packages,将zip文件解压到该目录下,重命名文件夹为 Unity-Shader
修改Sublime Text Setting
Preferences—>Settings

//UnityShader编辑器设置
"Unity_Version":"U5",
"Shader_path": "D:/Unity5.6.5/Editor/Data/CGIncludes",
"U5_Shader_path":"D:/Unity5.6.5/Editor/Data/CGIncludes",

—D:/Unity5.6.5/Editor/Data/CGIncludes是你Unity安装目中CGIncludes文件夹的路径

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值