6

Monodevelop can auto-complete code, but it can't auto-complete key functions like Start, Update, FixedUpdate, OnCollisionEnter and so on, as such I often misspell the key functions.

Is there a way to add auto-complete or spell-check entries for these common functions?

Nick Udell
  • 2,420
  • 5
  • 44
  • 83
Jonguo
  • 681
  • 1
  • 10
  • 17
  • I don't think it is possible, because those methods are usually private and MonoDeveloper has no way to guess that you'd like to create those methods. I am not sure it that would work but you could probably create a class that derives from MonoBehaviour, mark those methods as virtual in that class and always derive from that class instead of MonoBehaviour. But even if it works, i think that the gains are not worth the effort. – AndreySarafanov May 29 '14 at 09:59
  • @AndreySarafanov: I thought about that too, but I have a feeling that the Unity runtime/engine might see all those blank virtual methods as something to be executing all the time even though nothing is happening/implemented; it could have an adverse effect on performance. – Chris Sinclair May 29 '14 at 10:13
  • @AndreySarafanov create a class derives from MonoBehaviour maybe the only solution, but it not a elegant solution. Thank you – Jonguo May 30 '14 at 03:21
  • @Chris Sinclair In Android Activity, functions like "onCreate" "onStart" , the Acitivty class have implemented it. I don't know why MonoBehaviour haven't implement these functions. – Jonguo May 30 '14 at 03:38

4 Answers4

3

While you can't create autocorrect entries in MonoDevelop, you can create Code Snippets (called Code Templates in MonoDevelop).

A code snippet is a chunk of code that is automatically created when you type an id string (e.g. start) and hit tab. It could be a function, a property, a bit of boilerplate you always find yourself writing (e.g. GetComponent calls). It even shows up in the autocorrect list.

Code snippets are quite powerful, and even allow you to tab over boilerplate and change important things like types and variable names easily and quickly.

Simply create a code snippet (MonoDevelop-> Tools -> Options -> Text Editor -> Code Templates-> Add) for each of the items you typically have problems with.

Monster Brain
  • 1,950
  • 18
  • 28
Nick Udell
  • 2,420
  • 5
  • 44
  • 83
2

Well, you can use the Unity Snippets for MonoDevelop for your problem. It has got a lot of useful snippets in it, works really great. When the Code Snippet Code appears, Double Tap TAB key to insert the template.

Image

Download the Unity.template.xml and create a folder called Snippets inside the C:\Users{your_pc_name_here}\AppData\Roaming\MonoDevelop-Unity-5.0 (or in Windows Press Win+R -> %appdata%) and Copy this file to that folder. On Restarting Monodevelop, the code snippets will be working.

Monster Brain
  • 1,950
  • 18
  • 28
0

As Andrey said, I believe Unity accesses those methods by naming/signature convention and not by any compile-time identity.

What you could do is define an interface that represents these methods:

public interface IStart
{
    void Start();
}

public interface IUpdate
{
    void Update();
}

Then in your script classes, you can inherit from the interfaces you intend to implement:

public class MyScript : MonoBehaviour, IStart, IUpdate
{
    public void Start()
    {

    }

    public void Update()
    {

    }
}

Downside is that these methods become public. I've never tried, but I assume that Unity would support these methods being implemented via explicit interface implementation which might help hide those method calls from typical API access:

public class MyScript : MonoBehaviour, IStart, IUpdate
{
    void IStart.Start()
    {

    }

    void IUpdate.Update()
    {

    }
}

Once you have these, if you typo the method signature you will get a compiler error.

As an added bonus, I don't know if MonoDevelop has this option, but in Visual Studio, when you add the interface inheritance in the class declaration, you get a context option to have Visual Studio automatically implement the interface method signatures (either implicitly or explicitly).

Chris Sinclair
  • 22,858
  • 3
  • 52
  • 93
0

this problem take me hours too and didn't fix ant the end. BUT i found out we can integrate Microsoft visual studio code IDE simply whit Unity since 5.5 version. need no more plugins and easily set is as default IDE in preferences setting. then just you need to install unity snippets plugin by searching it as extension and then every thing is done.

NoOne
  • 1