简体   繁体   中英

Sublime doesn't auto-complete the unity code

I decided to use sublime text 3 on windows programming on unity. I installed everything correctly, according to this video: https://youtu.be/z7na1MuMDRg . That is, I installed Mono, Omnisharp, unity3d package. The c# code is highlighted and autocomplete, and the unity syntax is also highlighted, BUT not autocomplete. Why? According to the tutorials, everything should work.

Instead of installing all of this, try to only install Unity Completions package: https://packagecontrol.io/packages/Unity%20Completions

In my case I use the light version, and it works. BUT I prefer to use VisualStudio in any case.

NOTE: I will refer to Sublime Text 3 as “Sublime” during this instructions reading

Prerequisites:

-Have Unity Downloaded and Installed.

-Have created a Unity 3D project which you are willing to allocate to these set of instructions.

-This Unity 3D project should preferably be a test project, so as to not ruin something important.

Be careful and follow the instructions exactly. You might have problems along the way but hold on as best you can!

  1. Download and Install Sublime Text 3 for OS X/Windows

  2. Download the latest version of the Mono Package(Do Not Use Homebrew,). using the official site, The link goes to the windows download, so if you have a 32 bit computer. download from the 32 bit link vice versa.

  3. For step 2, If you have a mac, click macOS and download the Visual Studio Channel(I haven't tried the stable channel and don't plan to, should work ok).

  4. Once you think Mono is completely installed, please check through the command prompt(windows) or terminal(mac) that Mono actually exists locally.

  5. To do so, in the Mac/Windows you can type mono in the terminal or command prompt to see the file structure, which should be good. If you are more comfortable using the finder or file explorer, use that find mono in your computer.

  6. Reminder - to find terminal or command prompt, search with the spotlight feature(mac - cmd+space), or the search for apps feature(windows 10 - bottom right corner)

  7. In the Sublime Text editor, press the sequence of keys cmd+shift+p or ctrl+shift+p to open up the command palette. (You can click the esc key anytime to exit from the palette). Type Install Package Control and then press enter (return key on Mac).

  8. Quit Sublime and open it again. This will refresh the changes.

  9. Open command palette once more and type Package Control: Install Package

  10. Enter and then type Unity3D and press enter.

  11. Repeat steps 6 and 7 to install Omnisharp and Unity3D Shader Highlighter and Snippets and Tabnine

(Omnisharp is a tools kit and system that allows for c# error checking and auto completion etc. We need mono for this, which is why we installed it earlier)

(Tabnine is a wonderful Artificial Intelligence based tool that from my knowledge analyzes the code you have written and quickly concludes methods and attributes you can add based on what you have. In this case, it will immediately know that the syntax is C# with Unity based methods. It is awesome that it caters to Sublime, and it is free for what we need!)

  1. Once you have completed installing these packages, quit(completely) and refresh Sublime. When you reopen sublime, you should see a blank, untitled file. If not, just create a new file, you will be fine.

  2. Click File > Open > Your Unity Project Folder > Open(This is mac based - windows should be self explanatory)

  3. You should see all your assets and scripts folders, but will have a blank unedited text file in front of you. Click save as and the name this file as “SLN_PROJECT_NAME".sublime-editor(More in the next sentence). There should ideally be a YOUR_PROJECT_NAME.sln file in your Unity Project Folder, so please rename the provided “SLN_PROJECT_NAME” as YOUR_PROJECT_NAME.

  4. Save the.sublime-project file that you just renamed and place it into the Library folder of your Unity project

  5. Go into the “SLN_PROJECT_NAME".sublime-editor file in Sublime and paste the following text(You NEED to do this for EVERY Unity project you port in Sublime):

     { "folders": [ { "follow_symlinks": true, "path": "Assets/Scripts", "file_exclude_patterns": [ "*.dll", "*.meta" ] } ], "solution_file": "./ProjName.sln" }
  6. Change ProjName part to the exact name of the.sln you are working with from the unity folder you are using(similar to when you create that untitled file to write this in).

  7. Close Sublime and Quit It. Open up your desired project that you want to use Sublime with in Unity

  8. Click Unity > Preferences > External Script Editor > Change the Script editor to the Sublime Text Application(Mac) or the Sublime Text.exe(Windows)

  9. In the tab with the Unity Preferences, find External Script Editor Args with a text box to its right. Paste "$(File)":$(Line) inside it.

  10. Close Unity and re-open your Unity project in Sublime Text 3. Now at the bottom of the Sublime Text 3 Window, you should (ideally) see something like “Omnisharp Server Starting” or “Omnisharp Project Loaded,” with “Tabnine” written next to it.

A good idea to do is to click in Sublime Text > Preferences > Settings - Syntax Specific and paste the following text to allow for autocompletion after punctuation symbols.

{
    "auto_complete": true,
    "auto_complete_selector": "source - comment",
    "auto_complete_triggers":
    [
        {
            "characters": ".<",
            "selector": "source.cs"
        }
    ],
    "extensions":
    [
        "cs"
    ]
}

Now you should be able to get seamless code completion with error detection facilities without Omnisharp overriding Unity Specific Methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM