Following are instructions for adding to the TextMate Javascript bundle so that you can assign a shortcut key in TM to bring up Unity docs in a TM browser, or select a Class or Class.function and go directly to its corresponding Unity docs. The process for C#/etc should be quite similar. Tweak the path to Unity.app if you have installed to somewhere non-standard.
If you look at the Unity documentation folder in the Finder, it should be quite easy to modify this (if you have a favorite page to start from for “Root Unity Documentation” below, for example).
These commands will also implicitly install a menu item in Bundles->JavaScript->
Root Unity documentation
within TM, open the bundle editor (ctl-opt-cmd)
Using “Show All” filter, find the JavaScript hierarchy and open it
Highlight the hiearchy root (JavaScript) and click the ±down arrow menu in the bottom left corner
select “New Command”
name the new command something like “Unity Documentation”
paste the following code in the “Command(s)” text area
UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/index.html"
if [[ -f $UNITYDOC ]]
then echo "<meta http-equiv=\"refresh\" content=\"0; tm-file://$UNITYDOC\">"
else echo "
Couldn't find Unity documentation."
fi
set “Input” as None
set “Output” as “Show as HTML”
set your shortcut key to whatever you like (I used ctl-opt-h)
set the “Scope Selector” to source.js
Docs for selected text
follow directions above up to creating the “New Command” and name something like “Documentation for Unity Word / Selection”
paste the following code in the “Command(s)” text area:
ref=${TM_SELECTED_TEXT}
UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/$ref.html"
if [[ -f "$UNITYDOC" ]]
then [[ -n "$UNITYDOC" ]] exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://$UNITYDOC'>"
else echo "No Unity documentation found for: $TM_SELECTED_TEXT"
fi
set “Input” to “Selected Text” or “Word”
set “Output” to “Show as Tool Tip”
shortcut key to what you like (I did ctl-opt-cmd)
set “Scope Selector” to “source.js”
Note that this currently only works by directly looking up what you have selected. It cannot currently look up a function which is associated with an instantiated class for example. So you could look up “GameObject” or “GameObject.transform” by highlighting it, but it could not look up “myVar.transform”.[/code]
This is a really nice addition to TextMate (recently picked it up for Unity, works great). Anyone with ideas on using selected text to search Unity docs?
I’ve tried the follow, but it always returns the ‘not found’ despite working fine in my browser :
ref=${TM_SELECTED_TEXT}
UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/30_search.html?q=$ref"
if [[ -f "$UNITYDOC" ]]
then [[ -n "$UNITYDOC" ]] exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://localhost/$UNITYDOC'>"
else echo "Unity documentation not found"
fi
ref=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/$ref.html"
UNITYSEARCH="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/30_search.html?q=$ref"
if [[ -f "$UNITYDOC" ]]
then [[ -n "$UNITYDOC" ]] exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://$UNITYDOC'>"
else exit_show_html "<meta http-equiv='Refresh' content='0;URL=file://localhost$UNITYSEARCH'>"
fi
This script will look for an exact match with the selected text or word, and fall back to a search. Note that you don’t actually need to set anything below the script field. exit_show_html always shows HTML, and ${TM_SELECTED_TEXT:-$TM_CURRENT_WORD} will always use the currently selected text or the closest word to the caret. The input/output options are for scripts that use stdin/out.