Search Unity

Using Unity with Sublime Text 2 (How to get everything set up)

Discussion in 'Scripting' started by JacobPennock, Mar 19, 2012.

  1. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    Well done pabu!

    Any chance you can share the source or host it on Git or something? Will be good to have it around for people to tweak, add to etc. I'm happy to host it on Git together with my TM JS bundle I already have up there. Feel free to PM to discuss.

    Cheers.
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I can verify 10.7.x does not like this app, and it tells me to upgrade to 10.8.

    Great work, though! I may just upgrade ...
     
  3. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    I tired with OS 10.8, Unity 3.5.2, Sublime 2.0.1 and it's not working. The wrapper seems to be able to locate the correct line or errors but when the file is open it always display a blank window.

    Still waiting for the solution to enable sublime jump to the line number of problems found by the Unity debugger.
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I was setting up a theme for Unity Plugin "ScriptInspector", so I thought I'd hack one together for SM2:

    http://pastebin.com/SdMxzCad

    (SM2)


    I find that MD is pretty granular about how it defines the code, so the SM2 version is not as varied, but it's close enough.

    (MD)
     
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Heresy! A white background!!! ;) BTW, didn't know about ScriptInspector: cool :)
     
  6. devain

    devain

    Joined:
    Jul 7, 2012
    Posts:
    14
    Hey everyone! Looks like there's a lot of progress with Sublime's Unity integration. But in all honesty, without a debugger, I can't see it as anything more than a curiosity. A neat, beautiful and nicely featured curiosity, but a curiosity nonetheless.

    It would be great if we could get Unity to make an official integration of Sublime, hooking it in properly.
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I find that for normal editing, dark backgrounds tire my eyes. In the pro-skin, tho' I found the light background jarring so I did make one with a dark background (see script inspector). Reminds me of working on those old green vector line monitor when the bg is too dark. (^_^)

    -

    Oddly, I'm finding that SublimeText2 doesn't seem to fold comments or commented code, nor does is recognize #regions. Mmmm.
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Ehe I can't work on a white background, while my partner can't work on a dark one. Maybe reasons for eye tiring are all psychological :D

    And yup, no comment folding on Sublime. Also, it's very annoying that you have to customize it to add a "close all tabs" option :p I love it, but it still has a long way to go.
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    A little folding trick that seems to be proving true:

    If you have a single comment, you can use it to trigger the folding behavior, but you must indent the following code one level for it to work, which may drive you nuts:

    No Folding:


    Folding:


    As SM2 seems to be detecting the indent level, and allows folding from the start to end of every indent level, you can use this for some pseudo-regions. It may get very indenty very fast, tho'.
     
  10. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Oh hey I had no idea people were tinkering with SM2 plugins here. Awesome stuff :)

    I have a plugin project which has been laying dorment for a while now, but I'd like to boot it back up when I get back from Unite 12.

    The concept is simple: I love SM2 distraction free and I hate having to switch out of it to check for compiler errors in Unity. This plugin wires the Unity compiler log to a view in SM2, so I never ever have to leave ;)

    Also, could OP compile a list of links in the first post to the plugins which have been built so far?
     
  11. pabu

    pabu

    Joined:
    Mar 17, 2010
    Posts:
    30
    Perhaps this works better in 10.7

    http://buckadero.se/unity/SublimeWrapper101.zip

    Cheers,
    pabu
     
  12. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    pabu hello! Can you put the source code of Sublime Wrapper?
     
  13. pabu

    pabu

    Joined:
    Mar 17, 2010
    Posts:
    30
    Hi Zlou!

    I would rather bury this little hack as soon as UT adds proper support for external editors where you can construct your own command line with some macros for filename and row/col number.

    Cheers,
    pabu
     
  14. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    Anybody earned Sublime Wrapper for Mac OS 10.7?
     
  15. whazlewo

    whazlewo

    Joined:
    May 17, 2012
    Posts:
    6
    Hey pabu,

    That wrapper works really well most of the time, but at some point it pops open a blank version of the script in ST2. I downloaded the first version you posted, changed MonoDevelop to something else, and changed your app to MonoDevelop, and initially it worked great.

    But after a bit of time all the sudden it opens up blank files. The title is set correctly, but shows no code. Luckly the code is still there when i go look in the finder :)

    Anyone else noticed this?

    Great hack by the way, i don't know why Unity has not incorporated ST2 over Textmate as of yet.
     
  16. pabu

    pabu

    Joined:
    Mar 17, 2010
    Posts:
    30
    Hey whazlewo,

    Does it start behaving correctly again after you restart Unity or Sublime text or is the problem permanent? Does the second version work for you (not that I expect it to make a difference with regards to your problem, just curious)?

    Cheers,
    pabu
     
  17. fredpointzero

    fredpointzero

    Joined:
    May 24, 2011
    Posts:
    9
    Hi !

    I've made a simple package for sublime text 2 to build unity3d projects : https://github.com/fredpointzero/UnityBuild

    If you did not succeed to build, check out the path of your Unity installation in the sublime-build file.

    Enjoy !
    :cool:

    NB: The CompleteSharp package has been updated with this feature, you'il hust have to update this package
     
    Last edited: Sep 28, 2012
  18. fredpointzero

    fredpointzero

    Joined:
    May 24, 2011
    Posts:
    9
    If you have sublime text 2 with CompleteSharp, you may want to setup your assemblies to have correct autocompletion.

    Once builded, they are located in : ${project}/Temp/bin/Debug/*.dll.

    I've just made a fork of CompleteSharp on github to support globs for assemblies. You can use those settings in your sublime-project file :

    Code (csharp):
    1. "settings": {
    2.         "completesharp_assemblies": [
    3.             "${project_path:Temp\\bin\\Debug\\*.dll}"
    4.         ]
    5.     }
    Have fun !
    :cool:
     
  19. whale

    whale

    Joined:
    Jan 21, 2012
    Posts:
    10

    Hey Pabu,

    I just wanted to add my 2 cents- Setting up both versions of your wrapper, OSX 10.8, ST2, Unity 3.5.5.6- sublime opens up but for some reason opens a blank version of the file! No idea whats up, would love this feature :)

    thanks

    d
     
  20. DMinsky

    DMinsky

    Joined:
    May 20, 2012
    Posts:
    30
    Hi, Jacob! Thanks for your tools for sublime and unity! But I have a trouble with building. I try to build project with Sublime xbuild like here http://forum.unity3d.com/threads/12...ything-set-up)?p=943608&viewfull=1#post943608

    When I build with MonoDevelop all is OK. But with xbuild I get this:
    "warning: *Reference 'Assets/Plugins/Prime31/P31RestKit' not resolved"
    And as result:
    "error:CS0246 * The type or namespace name `Prime31' could not be found. Are you missing a using directive or an assembly reference?
    Compilation FAILED! Errors:1 Warnings:2"

    Assembly references (including Prime31) in MonoDevelop looks ok. Maybe you can help?
     
  21. whazlewo

    whazlewo

    Joined:
    May 17, 2012
    Posts:
    6
    I can't believe how difficult this turned out to be. Pabu's method seems to have worked for just a bit for me, and stopped completely, and I'm not sure what the bad factors are.

    I really wish Unity would open this up so we could have more control over what editor we use., but I hear that they are working on their own editor in one of the future releases.
     
  22. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    I finally got Sublime setup so it recognizes Unity and displays methods as auto completion.

    However i still have 2 problems and don't know how to fix those, wondering if any of you guys found a solution for thisl

    1) The top level completion doesn't seem to work. If i start typing "Trans" it won't suggest Transform. However, if you "Transform." it lists me every possible method for Transform correctly

    2) Auto Completion does not seem to consider every script in your Project. So if i try to access a different script, i won't see any suggestion in the auto completion list

    I suppose the last one is more of a sublime problem? Not sure though, couldn't find much about it :/
     
  23. JacobPennock

    JacobPennock

    Joined:
    Jul 7, 2011
    Posts:
    31
    I don't know a good solution to #1, I just sort of deal with that, I have most of the top level stuff memorized by now anyway.

    As for question number 2, I solved that with a little plugin I found on the sublime text forums, I forget what its called sorry,
    but what it does is concatenates all the auto-completes from all the currently open files. Not quite as good as a real project wide auto-completes, but works well enough for me. If that sounds good enough to you just look around the sublime forums and you should find it fairly easily.
     
  24. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    Thanks for your reply.
    Yeah #1 is not too bad, more of a convenience thing.
    #2 is pretty critical though. I saw the script you mentioned but unfortunately it's not enough. It makes it really hard if you work with libraries like EZGui, you don't really want to open every single script to figure out which methods you can use :/
    I'll keep trying to find a solution for this and post it if i can find anything.
     
  25. JacobPennock

    JacobPennock

    Joined:
    Jul 7, 2011
    Posts:
    31
    Yeah when I use EZGUI, I just have the ezgui wiki open in another window. I use auto-completes more for spelling then anything else.

    If you really wanted to you could take EZGUI out of your project, and compile it to a dll in monodevelop, then import that dll to your project, and point the
    complete-sharp plugin at the dll. Thats a lengthy process, but would give you the autocompletes you want if you really cannot live without them.
     
  26. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    1) The top level completion doesn't seem to work. If i start typing "Trans" it won't suggest Transform. However, if you "Transform." it lists me every possible method for Transform correctly
    Hello! Found a solution?
     
  27. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
  28. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    Has anyone had more luck with Pabu's bridge? I've got the same issue mentioned by whazelwo, where it worked at first but now opens (around 90% of the time) to a blank file. I've briefly fiddled with rolling my own solution, though I'm not quite sure how to extract the arguments that Unity passes.
     
  29. bngames

    bngames

    Joined:
    Jul 3, 2012
    Posts:
    67
    I've been using Sublime for months with Unity and just LOVE this editor, please, please, please Unity support this editor more.
     
    Last edited: Dec 15, 2012
  30. McKrackeN

    McKrackeN

    Joined:
    Oct 28, 2009
    Posts:
    51
    Is there any chance of Unity *officially* support ST?
     
  31. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    +
     
  32. karl_

    karl_

    Joined:
    Mar 4, 2010
    Posts:
    464
    I just added a Sublime-Project wizard to a set of extensions I use, and put it on GitHub. This lets you create and open a sublime-project from within Unity. It's pretty limited at the moment, though maybe in the future I'll expand it.

    link to my github here, with all the extensions:

    https://github.com/karl-/utility-belt

    direct link: Sublime-Project Utilty

     
    Last edited: Jan 9, 2013
  33. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hey Dudes!,

    Sublime text 2 is ace! Thanks to Jacob and everyone who helped getting it working with unity it RoCks!

    Just wonderuing has anyone got "goto anything" working with an entire project? Looks like it could be pretty sweet!
    Thanks,
    Pete
     
  34. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hi all,

    Just thought I'd mention that if you want to get "goto anything" working with Sublime and your unity project, just go File/Open... i sublime and choose your unity project's scripts folder and Sublime will have access to all your scripts (so goto anything works).
    I'm still trying to find a way to get ST2 to open on the right line (from the unity error in console) but that seems to be a tricky one on OSX.
    If anyone else is after that feature maybe vote t this page - http://sublimetext.userecho.com/top...specific-line-from-external-applications-osx/

    Pete
     
  35. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Hello!

    I would like to give my 5 cents on the issue.

    I had a configuration fine which should have worked correctly almost from start and, after some debugging, I found out it was not managing to read the DLLs, even though paths were correct. All I had to do in order to fix that was to recompile the .pys into .pycs, such as in:


    Code (csharp):
    1. fgielow@Macintosh:~/Library/Application Support/Sublime Text 2/Packages/CompleteSharp$ python -m compileall .
    2. Listing . ...
    3. Compiling ./completesharp.py ...
    4. Listing ./sublimecompletioncommon ...
    5. Compiling ./sublimecompletioncommon/__init__.py ...
    6. Compiling ./sublimecompletioncommon/completioncommon.py ...
    7. Listing ./sublimecompletioncommon/parsehelp ...
    8. Compiling ./sublimecompletioncommon/parsehelp/__init__.py ...
    9. Compiling ./sublimecompletioncommon/parsehelp/parsehelp.py ...
    After that, the .dlls were correctly scanned. You can try to debug what is going on by enabling the SublimeText console and just watching the output, several error messages will appear when you trigger auto completion, if something is misconfigured.


    As a further note, you sublime project MUST be pointing to the root of your unity3d project *or else you should adapt the path given on the CompleteSharp config file, but pointing to root folder really is easier*. Previously I had it created on the scripts folder so I had less garbage on my sidebar, it would not work the way I wanted.

    I will also leave my CompleteSharp configuration file here, if you are still having trouble with that *note that is is for OSX*:



    Code (csharp):
    1. {
    2.     "completesharp_assemblies": [
    3.         "/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll",
    4.         "/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll",
    5.         "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/unity/UnityScript.dll",
    6.         "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/unity/System.Core.dll",
    7.         "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono/unity/System.dll",
    8.         "/Applications/Unity/Unity.app/Contents/Frameworks/Managed/nunit.framework.dll",
    9.         "${project_path:Library}/ScriptAssemblies/Assembly-CSharp.dll",
    10.         "${project_path:Library}/ScriptAssemblies/Assembly-CSharp-Editor.dll",
    11.         "${project_path:Library}/ScriptAssemblies/Assembly-UnityScript-Editor.dll",
    12.         "${project_path:Library}/ScriptAssemblies/Assembly-CSharp-firstpass.dll"
    13.     ],
    14.  
    15.     // this line MUST be deleted on windows
    16.     "completesharp_mono_path" : "/Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop",
    17.  
    18.     "completioncommon_inhibit_sublime_completions": true,
    19.  
    20.     "completioncommon_shorten_names": true
    21. }
    22.  
     
  36. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hey Just wondering, Is there an official Unity 4 keywords list? (for unityscript).
    I'd like to see how hard it would be to convert to a sublime completion file.
    I couldn't find anything but I reckon there must be something out there.
     
    Last edited: Feb 4, 2013
  37. lzt120

    lzt120

    Joined:
    Apr 13, 2010
    Posts:
    93
    Under installed path Unity4\Data\Tools\UniSciTE, there is one file : unitykeywords.properties. all key works is in that file. And attached here for easy reference.
     

    Attached Files:

  38. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hey Thanks lzt120!
    I'm not sure i'll be able to get it working but at least that's a great start!
     
  39. lzt120

    lzt120

    Joined:
    Apr 13, 2010
    Posts:
    93
    When using sublime2, why I can not toggle comments!!
     
  40. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122

    I adapted the file "UnityJavaScript.tmLanguage" from "Unity3D" package with the zip file send by @lzt120, you can find it here: http://cl.ly/0b0a221l1K1Z

    I tested it for like.... 15 seconds, and it seemed alright, you can check if it is ok (by replacing Sublime Text 2/Packages/Unity3D/UnityJavaScript.tmLanguage" with the file on the link), just backup the older one before because my procedure was simply changing the original keywords with the new ones from the file above, I did not notice any change, I do not even know which keywords are new in Unity4 actually hahah I've just updated to Unity4...


    Well, that's all.
     
  41. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Thanks for posting this, fgielow! I tried using your CompleteSharp config file, but I'm getting this error when Sublime tries to autocomplete something:

    Code (csharp):
    1. stderr: /bin/sh: /Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop: No such file or directory
    I opened up that directory in Finder, and all I see are two aliases: one called 'mdtool' and another called 'monodevelop' (all lowercase). The 'monodevelop' alias is referencing /Applications/Unity/MonoDevelop.app/Contents/MacOS/bin/MonoDevelop, but that file doesn't exist on my machine.

    Did you have to do something special to build the MonoDevelop binary?

    Thanks again for posting! :)
     
  42. lzt120

    lzt120

    Joined:
    Apr 13, 2010
    Posts:
    93
    I wonder if the toggle comment command does not work for Unity ??
     
  43. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hey lzt120!

    Grab the package from this thread ---> How to hide comments and copy it to your packages folder.
    (Get there through - SublimeText2/Preferences/Browse Packages)

    Then you can press Command+Shift+p and start typing "Fold Comments" (or "Unfold Comments").

    I didn't really like the way it auto folded comments on load so i changed the fold comments.py and got rid of the first function (with def on_load).
     
  44. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Hi! You are welcome, I hope it can help you too, after those initial configurations, my workflow became really nice.

    Welll, here that file references "/Library/Frameworks/Mono.framework/Versions/Current/bin/mono", you could try using that one directly. But in the end, I think that that line can be omitted, I do not know why it didn't work without me explicitly setting it, if you do not set it and CompleteSharp manages to use mono, that's fine (here it did not haha).
     
  45. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    That's so strange. I checked in my /Library/Frameworks folder, and Mono.framework doesn't exist. I also tried removing the "completesharp_mono_path" line from my config file, but I still get the missing mono error.

    I'm running OS X 10.8.2, and Unity 4.0.1f2. Are you on different versions, maybe?
     
  46. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    I have OS X 10.8.2 and Unity 4.0.0f7, latest XCode too.

    I think I may have installed mono a looong time ago, which should create that Framework folder (I am not sure if it was that, though). What is even stranger is that there SHOULD be a mono binary in the... MONOdevelop folder haha. What is the content of the "MonoDevelop.app/Contents/MacOS/bin/" folder?

    Well, I found out that the MonoDevelop.app comes with an embedded Mono.Framework folder in /Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework, you could try the binary "/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Versions/Current/bin/mono" or something like that.

    From the commandline you can find a path to an executable "mono" file through:

    Code (csharp):
    1. $ find /Applications/Unity/MonoDevelop.app/ -perm +u=x -type f -name "mono"
     
  47. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Ahh! That worked!! Here's the path I ended up using:

    Code (csharp):
    1. "completesharp_mono_path" : "/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Versions/Current/bin/mono"
    Weird, though, that our /MonoDevelop.app/Contents/MacOS/bin/ folders are different. Mine contains only 2 aliases: 'mdtool' and 'monodevelop.' They both reference files that don't exist in my filesystem :)

    Were you also able to setup a working build system in Sublime? Or do you have to tab back to Unity to compile your scripts?

    Thanks so much for the help, fgielow!! :)
     
  48. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Yeap, that broken symbolic link is really strange o_O

    I am using the "Unity3D Build System" package, it works flawlessly. I just have to set it on Tools->Build System. However, for it to work, I must create the Sublime project in the root of my project (that meaning the folder that contains the Assets/Library/ProjectSettings folders), saving the sublime project file in that root folder and with the same name of the root folder! hahaha. For example, as in the following image:



    That is the necessary due to the build rules defined in the "Unity.sublime-build" file from the "Unity3d Build System" package:

    Code (csharp):
    1. "osx": {
    2.         "cmd": [
    3.             "/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Commands/xbuild",
    4.             "${project_path}/${project_base_name}-csharp.sln",
    5.             "/noconsolelogger",
    6.             "/logger:${packages}/Unity3D Build System/SublimeLogger.dll"
    7.         ],
    8.         "file_regex": "^([\\d\\w:/\\.]*)\\((\\d+),(\\d+)\\)\\s*(.*)$"
    9.     }
    It searches for a "${project_path}/${project_base_name}-csharp.sln" file in order to build with xbuild.
     
  49. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    fgielow, you've changed my life :) That package worked flawlessly, as you said. Thank you so much for the super clear instructions!! :)
     
  50. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    You are welcome! :)

    I actually had myself read some nice tutorials on the topic, they deserve credit, so I'll leave their links here.

    http://blog.xdegtyarev.com/2012/11/perfect-workflow.html
    http://www.holoville.com/blog/?p=512
    http://www.jacobpennock.com/Blog/?p=647 (author of many of those Unity3d packages)
    http://blog.fredericvauchelles.com/2012/09/sublime-text-2-package-for-unity3d-builds/ (this one regards that specific topic of building)