Unity3d Right-click to open the file quickly

Source: Internet
Author: User

In development, if you just want to quickly view a file (such as a. Lua), you can utilize the right-click function, which is slightly more efficient when you open multiple projects and debug.

wrote a tool class and added two methods: You can use notepad++ or Notepad to quickly open the file.

The code is as follows:

using unityengine;using system.collections;using unityeditor;using thisobject =  unityengine.object;using system.threading;using system;public class easytool{     const int openmax = 10; //Maximum number of open files at once     const  string notepadjj_app_name =  "Notepad++.exe";    const string  notepad_app_name =  "notepad.exe";    /// <summary>     ///  Open file with notepad++     /// </summary>    [ MenuItem ("assets/easytool/open_notepad++")]    static public void  OPENFORNOTEPADJJ ()     {        int count  = 0;        foreach  (var go in  Getselectobject ())         {            if  (go  != null)             {                 string dir_path =  GetPath (GO);                 Invokecmd (Notepadjj_app_name, dir_path);             }            count++;             if  (Count > openmax)              {                 break;             }        }    }    // <summary>     ///  open file with Notepad     /// </summary>     [menuitem ("Assets/easytool/open_notepad")]    static public void  Openfornotepad ()     {        int count =  0;        foreach  (Var go in getselectobject ())         {             if  (go != null)              {                 String dir_path = getpath (GO);               &nbsP; invokecmd (Notepad_app_name, dir_path);                 count++;                 if  (Count > openmax)                  {                     break;                 }             }        }    }     /// <summary>    ///  Call cmd  Command      /// </summary>    public static void invokecmd ( string cmd, string d ir_path)     {        unityengine.debug.log (CMD);         assetdatabase.refresh ();         new thread (New threadstart ()  =>         {            try             {                 System.Diagnostics.Process p = new  System.Diagnostics.Process ();                 p.StartInfo.FileName = cmd;                 p.StartInfo.Arguments = dir_path;                  p.start ();                 p.waitforexit ();                 p.close ();             }            catch  (Exception e)             {                 debug.log (e.message);             }        })). Start ();     }    /// <summary>    ///   Get selected Files     /// </summary>    /// <returns> </returns>    Static public thisobject[] getselectobject ()     {         if  (selection.objects.length == 0)          {            return new  thisobject[0];        }         return Selection.objects;    }    /// <summary>     ///  Get file path     /// </summary>     /// <param name= "Go" ></param>    /// <returns></ Returns>    static public string getpath (ThisObject go)      {        string str =  Application.dataPath.Replace ("Assets",  "");        string path = assetdatabase.getassetpath (GO);         string dir_path = system.io.path.getfullpath ( Str + path);        return dir_path;     }}


This article is from the "Wo Love Money" blog, please be sure to keep this source http://mozhenrui.blog.51cto.com/11845221/1976771

Unity3d Right-click to open the file quickly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.