Background/Situation
ReSharper handles file layouts for C# and Unity projects slightly differently. For Unity C# code, the file layout includes specific considerations for Unity-specific attributes and serialization behaviors, which do not apply to standard C# code.
Question
How can the file layout be set to handle Unity C# projects in ReSharper?
Answer
To configure a file layout for Unity code in ReSharper, follow these steps:
-
Open the File Layout Settings:
- Press Alt + R, O in Visual Studio or (Extensions) | ReSharper | Options.
- Navigate to Code Editing | C# | File Layout.
-
Switch to XAML Mode: In the file layout editor, switch to edit mode to modify the layout directly in XAML.
-
Add the Combined File Layout Pattern: Copy and paste the following pattern into the XAML editor:
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns" xmlns:unity="urn:schemas-jetbrains-com:member-reordering-patterns-unity"> <!-- Pattern to match classes used by Unity that contain serialised fields and event function methods. Based on the standard "Default Pattern", this will also order event functions before normal methods, and does not reorder serialised fields, as this order is reflected in the Unity editor's Inspector --> <TypePattern DisplayName="Unity classes" Priority="100"> <TypePattern.Match> <unity:SerializableClass /> </TypePattern.Match> <Entry DisplayName="Public Delegates" Priority="100"> <Entry.Match> <And> <Access Is="Public" /> <Kind Is="Delegate" /> </And> </Entry.Match> <Entry.SortBy> <Name /> </Entry.SortBy> </Entry> <Entry DisplayName="Public Enums" Priority="100"> <Entry.Match> <And> <Access Is="Public" /> <Kind Is="Enum" /> </And> </Entry.Match> <Entry.SortBy> <Name /> </Entry.SortBy> </Entry> <Entry DisplayName="Static Fields and Constants"> <Entry.Match> <Or> <Kind Is="Constant" /> <And> <Kind Is="Field" /> <Static /> </And> </Or> </Entry.Match> <Entry.SortBy> <Kind> <Kind.Order> <DeclarationKind>Constant</DeclarationKind> <DeclarationKind>Field</DeclarationKind> </Kind.Order> </Kind> </Entry.SortBy> </Entry> <Entry DisplayName="Serialized Fields"> <Entry.Match> <!-- Keep serialised fields and auto-properties with serialised backing fields together, unsorted, to maintain order in the Inspector window --> <Or> <unity:SerializedField /> <unity:AutoPropertyWithSerializedBackingField /> </Or> </Entry.Match> <!-- No sorting --> </Entry> <Entry DisplayName="Non-serialised Fields"> <Entry.Match> <And> <Kind Is="Field" /> <Not> <unity:SerializedField /> </Not> </And> </Entry.Match> <Entry.SortBy> <Readonly /> <Name /> </Entry.SortBy> </Entry> <Entry DisplayName="Constructors"> <Entry.Match> <Kind Is="Constructor" /> </Entry.Match> <Entry.SortBy> <Static/> </Entry.SortBy> </Entry> <Entry DisplayName="Properties, Indexers"> <Entry.Match> <Or> <Kind Is="Property" /> <Kind Is="Indexer" /> </Or> </Entry.Match> </Entry> <Entry DisplayName="Event Functions"> <Entry.Match> <unity:EventFunction /> </Entry.Match> <Entry.SortBy> <!-- Prioritises common event functions. For alphabetical, replace with <Name /> --> <unity:EventFunctionName /> </Entry.SortBy> </Entry> <Entry DisplayName="Interface Implementations" Priority="100"> <Entry.Match> <And> <Kind Is="Member" /> <ImplementsInterface /> </And> </Entry.Match> <Entry.SortBy> <ImplementsInterface Immediate="true" /> </Entry.SortBy> </Entry> <Entry DisplayName="All other members" /> <Entry DisplayName="Nested Types"> <Entry.Match> <Kind Is="Type" /> </Entry.Match> </Entry> </TypePattern> </Patterns> -
Save the Changes: Click on Save To | Solution personal or Solution team-shared, based on your requirements
Comments
0 comments
Please sign in to leave a comment.