Skip to content

Instantly share code, notes, and snippets.

@fredimachado
Created July 3, 2017 05:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredimachado/34fdb0203892279c7cc6a00fcce76137 to your computer and use it in GitHub Desktop.
Save fredimachado/34fdb0203892279c7cc6a00fcce76137 to your computer and use it in GitHub Desktop.
Visual Studio snippet to create a Unity serializable field
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>field</Title>
<Shortcut>field</Shortcut>
<Description>Code snippet for a Unity serializable field
Language Version: C# 3.0 or higher</Description>
<Author>Fredi Machado</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Field type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>Field name</ToolTip>
<Default>fieldName</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[[SerializeField] $type$ $field$;$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
@fredimachado
Copy link
Author

fredimachado commented Jul 13, 2017

In case you're wondering: To make Visual Studio aware of the snippet you should save this content as a file named field.snippet in this folder: C:\Users\YOUR_USER\Documents\Visual Studio 2017\Code Snippets\Visual C#\My Code Snippets
After that, restart Visual Studio, open any C# file, type "field" (the name of the snippet without double quotes) and press TAB twice. :)

@fredimachado
Copy link
Author

fredimachado commented Jul 13, 2017

A very nice thing about VS snippets is that after you expand it using TAB, you can navigate through the literal declarations (In this snippet they are the field type, which defaults to int, and the field name which defaults to fieldName) using TAB and when you're done, just press ENTER. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment