双击shader脚本,用sublinetext打开shader脚本

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

public class ShaderEditor : Editor
{
    [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;
        // Debug.Log(strFileName);
        if (strFileName.EndsWith(".shader"))
        {
            //设置环境变量IDE软件
            string strSublimeTextPath = Environment.GetEnvironmentVariable("Subline_text3");
            //Debug.Log(strSublimeTextPath);
            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";
                //Debug.Log(startInfo.FileName);
                startInfo.Arguments = "\"" + strFileName + "\"";
                process.StartInfo = startInfo;
                process.Start();

                return true;
            }
            else
            {
                Debug.Log("Not Found Enviroment Variable 'SublimeText_Path'.");

                return false;
            }
        }

        return false;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值