Skip to content

Instantly share code, notes, and snippets.

@neon-izm
Last active November 23, 2016 16:12
Show Gist options
  • Save neon-izm/1a4da1e2702090e29485512ba3019b44 to your computer and use it in GitHub Desktop.
Save neon-izm/1a4da1e2702090e29485512ba3019b44 to your computer and use it in GitHub Desktop.
Unity Serialized propety()
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Propety</Title>
<Author>izm</Author>
<Description>AccessCache</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
<Shortcut>props</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Tooltip</ID>
<Default>Description Here</Default>
</Literal>
<Literal>
<ID>target</ID>
<Default>target</Default>
</Literal>
<Literal>
<ID>Component</ID>
<Default>Transform</Default>
</Literal>
<Literal>
<ID>Name</ID>
<Default>Name</Default>
</Literal>
</Declarations>
<Code Kind="any" Language="CSharp"><![CDATA[[SerializeField]
[Tooltip("$Tooltip$")]
private $Component$ _$target$;
public $Component$ $target$
{
get {
if(_$target$ ==null){
_$target$= GameObject.Find("$Name$").GetComponent<$Component$>();
}
return this._$target$; }
set { this._$target$ = value; }
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
@neon-izm
Copy link
Author

[SerializeField]
[Tooltip("Description Here")]
private Transform _target;
public Transform target
{
    get
    {
        if (_target == null)
        {
            _target = GameObject.Find("Name").GetComponent<Transform>();
        }
        return this._target;
    }
    set { this._target = value; }
}

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