Skip to content

Instantly share code, notes, and snippets.

@nonathaj
Created March 11, 2016 17:02
Show Gist options
  • Save nonathaj/8058f35da5e9c04adea5 to your computer and use it in GitHub Desktop.
Save nonathaj/8058f35da5e9c04adea5 to your computer and use it in GitHub Desktop.
Code Snippets to quickly fill out Unity serialization or GetComponent properties
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propgetc</Title>
<Shortcut>propgetc</Shortcut>
<Description>Unity Code snippet for property and backing field with lazy GetComponent call</Description>
<Author>Jon Kenkel</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[private $type$ $field$;
public $type$ $property$ { get { return $field$ ?? ($field$ = GetComponent<$type$>());} }
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propgets</Title>
<Shortcut>propgets</Shortcut>
<Description>Unity Code snippet for property and backing field with serialization</Description>
<Author>Jon Kenkel</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[[SerializeField]
private $type$ $field$;
public $type$ $property$ { get { return $field$;} set { $field$ = value; } }
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment