Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Code Formatting of C# field attributes

Discussion in 'Scripting' started by Wenzil, Nov 17, 2013.

  1. Wenzil

    Wenzil

    Joined:
    Apr 3, 2013
    Posts:
    19
    Hey all,

    I'm trying to get rid of the annoying auto code formatting of C# attributes on my fields which puts a newline before the field name in the new MonoDevelop. Here's an example of what I mean:

    Code (csharp):
    1.  
    2. [Range(0, 100)]
    3. [SerializeField]
    4. private float
    5.     maxSpeed;
    6.  
    I would like to remove the newline before the field name, like so:

    Code (csharp):
    1.  
    2. [Range(0, 100)]
    3. [SerializeField]
    4. private float maxSpeed;
    5.  
    I have looked in Tools->Options->Code Formatting->C# source code. There doesn't seem to be an option to remove the newline. I know this doesn't happen in Xamarin Studio. I would like to keep code formatting enabled for everything else. Anyone can help? If not, unity devs, please consider adding the option!
     
    jpthek9 likes this.
  2. mweldon

    mweldon

    Joined:
    Apr 19, 2010
    Posts:
    109
    The code formatting for the new version of Monodevelop doesn't work at all. You could have done this with the previous version, but now the only policies that work are the built-in ones, none of which do I find remotely usable.
     
  3. Shinzironine

    Shinzironine

    Joined:
    Nov 30, 2013
    Posts:
    32
    I have the same problem. But otherwise the formatting works fine as opposed to Mweldons comment. You just have to configure the code formatting opions in Project -> Solution options.
    I have tried a lot of different options in code formatting of MonoDevelop, but nothings seems to work. It would be cool if anyone has the solution.
     
  4. lazer

    lazer

    Joined:
    Aug 15, 2012
    Posts:
    23
    Last edited: Jan 14, 2014
  5. Callabrator88

    Callabrator88

    Joined:
    Nov 11, 2013
    Posts:
    10
    I'm definitely seeing the same problem on Mono 4.0.1. New lines after Attributes
     
  6. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    How to fix it? This is so annoying -.-
     
  7. Deleted User

    Deleted User

    Guest

    October and still not fixed.
     
  8. Dameon_

    Dameon_

    Joined:
    Apr 11, 2014
    Posts:
    542
    I've been using Visual Studio for my coding, and haven't looked back at Mono once.
     
    landon912 likes this.
  9. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
  10. Deleted User

    Deleted User

    Guest

    @aaro4130 What's "Neither"? What's the "always on top bug"?
     
  11. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    The always on top bug is the one in
    a) Unity 4.6 beta where the standalone player is stuck on top of other windows in windowed mode
    b) MonoDevelop IDE where it gets stuck on top of other windows and requires a restart.
     
  12. Deleted User

    Deleted User

    Guest

    Oh I understand what you're saying now.
     
  13. Deleted User

    Deleted User

    Guest

  14. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
  15. bvesco

    bvesco

    Joined:
    Jul 7, 2013
    Posts:
    3
    Seems no one will ever know how to fix this...
     
  16. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    You can't- it's not about "knowing". It's a bug with Unity's MonoDevelop- it won't be fixed until the Unity devs fix it on their end. Until then, I suggest using Visual Studio with "VSTools For Unity", as it's what I consider the absolute best programming environment currently available.

     
  17. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Have you tried running Visual Studio in Parallels on OSX? for the last 3 months I have been doing this at work and it is working pretty good. Even the debugger still attaches since that uses a udp port. Since parallels provides shortcuts to wndows apps in OSX i was even able to set my VS running in windows to be the default script editor for my instance unity running in OSX.
     
  18. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    It was a year and a half ago- I would've called "necro" instead of politely responding before, but this is still an issue in the current version of Unity/Mono. This is likely the longest-lasting bug in Unity's history because, while annoying, it doesn't actually affect anything beyond aesthetics. *shrugs*

    If nothing else, it pushes more people toward VS, and now that "VSTools for Unity" is owned by M$ and free, there's absolutely no reason not to switch over IMO.
     
  19. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    For the most part the monodev hold overs seem to be mac users, where it is your only option unless you want to run a virtual machine for Visual Studio.

    Its a pain in the ass at work since most of the office is running OSX, and i think im the only one with a parallels license, so im the only one able to use VS
     
  20. TimmermanV

    TimmermanV

    Joined:
    Sep 27, 2014
    Posts:
    4
    This issue is now fixed according to the issue tracker. However, it is not the issue of the OP. I found that MonoDevelop is indeed still adding newlines before field names when using attributes.

    Code (CSharp):
    1.         [Header("Debug Options")]
    2.         public bool overrideDefaults = false;
    still changes into this:
    Code (CSharp):
    1.         [Header("Debug Options")]
    2.         public bool
    3.             overrideDefaults = false;
     
  21. lusas

    lusas

    Joined:
    Mar 18, 2015
    Posts:
    6
    Confirmed. Still facing exactly the same issue. It is very irritating. Hope VS Code is going to be a solution soon..