Skip to content

Thundernerd/Unity3D-ComponentAttribute

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
December 20, 2015 20:04
December 14, 2015 22:13
November 15, 2015 16:19
January 4, 2016 23:51

Unity3D-ComponentAttribute

An attribute that let's you auto-load components

  • Works on fields and properties
  • Load components on awake, start, or enable, or whenever else you feel like it
  • Get component from other GameObjects (optional)
  • Add component if missing (optional)
  • Disable component on error (optional)

Credits go to @ChevyRay for inspiring me to make this by this tweet

The way of this.LoadComponents()

The only thing you have to do is add the component attribute to fields and/or properties that you want and call this.LoadComponents(); in the awake, start, on enable, or any other place for that matter and you are good to go.

Pros:

  • You don't have to do all those GetComponent calls to get the components you need
  • The more components you want, the less you have to do

Cons:

  • You have to write [Component] on top the of the Components you want this to work on
  • You also have to call this.LoadComponents();

Fields Example

Imgur

Properties Example

Imgur

About

An attribute that let's you auto-load components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages