Skip to content

Instantly share code, notes, and snippets.

@TobiasPott
Created June 24, 2021 07:57
Show Gist options
  • Save TobiasPott/658d35a24fd827e2de1bb0fc062da865 to your computer and use it in GitHub Desktop.
Save TobiasPott/658d35a24fd827e2de1bb0fc062da865 to your computer and use it in GitHub Desktop.
Visual Studio Custom Unity Code Snippets
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propcached</Title>
<Shortcut>propcached</Shortcut>
<Description>Code snippet for a cached property and backing field in Unity behaviour code</Description>
<Author>Tobias Pott</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>object</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>_myPropertyField</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[private $type$ $field$;
public $type$ $property$
{
get
{
if ($field$ == null)
$field$ = this.GetComponent<$type$>();
return $field$;
}
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment