AutoWiring View on Asset Store (opens in new tab)

Package details

Latest version
1.1
Last updated
First released
Unity version
2019.4.33 or later
Package size
6.6 MB
Files
139
Favorites
10
Views in the past week
9

Price tracking

Last checked
Tracked since
Lowest recorded
$4.99 on

Keywords

AutoWiring

by A Monkey Made This (opens in new tab)

No ratings yet

  • Price drop

The dependency-injection style alternative to GetComponent()! Similar to [RequireComponent] but actually goes and gets the component, resource or streaming asset for you, automatically.

Discount -90% Previous price $50.00 Price $4.99

Lowest recorded price

Get 90% off on Asset Store (opens in new tab)

Affiliate link · Purchases support this site

Price history

Last 6 months

USD
Price history for AutoWiring, 6 months Current $4.99; lowest $4.99; highest $4.99 in this period. $0 $2.5 $5 Jun Jul Aug Sep Oct Nov

Asset preview

1 / 1

AutoWiring screenshot 1

AutoWiring screenshot 1

About this asset

Note: This is the 'source' version, there is a 'Lite' version of this asset which is available for FREE which doesn't contain the source code, both are the same so you can use either. Whether you are curious about how it works or if your project requires the source code for all assets or if you want to support development of this or other assets then this is the version for you. For a free version to use as you like, be that you just want it for free or evaluation / try-before-you-buy or a pre-compiled DLL to save a couple of seconds on each build there is the 'Lite' version https://u3d.as/2TQ7

Uses attributes and reflection to automatically search for components, rather than having to create the definition then later use one of the GetComponent<T>(). Simply write your definition, annotate it with some [GetComponentInParent] metadata then hit AutoWiring.ApplyTo(this); when you instantiate your component and AutoWiring will do the rest for you!

The tags are customisable too- whether you just want to write [GetComponent] and let the code figure it out that you actually meant [GetComponents] or get super specific with [GetComponent(typeof(ISomethingOrOther), In.Children)].

Most streamlined boilerplate implementation?

  1. Collect underpants.
  2. Add a [Configure] annotation to a MonoBehaviour class definition. (It makes the reflection more efficient!)
  3. Add a GameObject field and let's call it Bob. Bob can be public, private, internal or protected, whatever they want.
  4. Annotate Bob with a [Find("Bob")].
  5. Add AutoWiring.ApplyTo(this); to OnEnable(), Awake() or Start(). Then add Debug.Log($"Hello {Bob}!"); on the next line.
  6. Make two GameObjects in a scene, call one of them Bob. You can decide what to call the other one, but add your test MonoBehaviour to it too.
  7. Press "Play" then say "Hello Bob!" when you see it in the Console.
  8. Profit!

See, wasn't that easy? In eight steps you did what could be done in about two lines of code! Lolz. OK, fine ... but now you have the context that the field or property definition has an annotation right next to it that describes how it is used, rather than potentially being several hundreds of lines or more apart (it happens, I've seen it).

Think of these attributes as being similar to the [RequireComponent] attribute but ones that actually goes and gets the component, resource or streaming asset. Cool Eh? Some of them will even also add a component if it doesn't find one, so adds a bit more resillience too.

AutoWiring's examples uses the following assets under Creative Commons BY license.

Shared

- "House" by Justin Roberts (A Monkey Made This).

Example 05 Resources

- "Desist" by Giant Robotic Ant (Justin Roberts / A Monkey Made This).

- "Probe" by Giant Robotic Ant (Justin Roberts / A Monkey Made This).

- "Shark" by Justin Roberts (A Monkey Made This).

- "UniCow" by Justin Roberts (A Monkey Made This).

Example 06 StreamingAssets

- "Cheap attack droid" by Giant Robotic Ant (Justin Roberts / A Monkey Made This).

- "Directional impulse controller #32" by Giant Robotic Ant (Justin Roberts / A Monkey Made This).

- "Cabin" by Justin Roberts (A Monkey Made This).

- "LTank" by Justin Roberts (A Monkey Made This).

See-

See Third-Party Notices.txt file in package for details.

From the publisher's Asset Store listing.

Technical details

Types

AutoWiring will automatically collect these items for you:

  • GameObjects
  • Components
  • Resources
  • StreamingAssets

GameObject attributes (vs equivalent / underlying functionality)

  • [Find(string name)] == GameObject.Find(string name)

Component attributes (vs equivalent / underlying functionality)

  • [GetComponent(Type type)] == GetComponent<T>()
  • [GetComponentInParent(Type type)] == GetComponentInParent<T>()
  • [GetComponentInChildren(Type type)] == GetComponentInChildren<T>()
  • [GetComponents(Type type)] == GetComponents<T>()
  • [GetComponentsInParent(Type type)] == GetComponentsInParent<T>()
  • [GetComponentsInChildren(Type type)] == GetComponentsInChildren<T>()

Note: you can also use overloads such as [GetComponent(Type type, In searchLocation)] to turn a [GetComponent] into [GetComponentInChildren] by adding the argument [GetComponent(In.Children)]. Also, there is no difference between [GetComponent] and the [GetComponents] equivalents so can be used interchangeably without errors or any additional effort.

Resource attributes (vs equivalent / underlying functionality)

  • [GetResource(string path)] == Resources.Load(string path)

StreamingAssets attributes (vs equivalent / underlying functionality)

Compatibility

Render pipelines supported in each Unity version
Unity version Built-in URP HDRP Custom
2021.3.1f1 Compatible Compatible Compatible Compatible
2019.4.33f1 Compatible Compatible Compatible Compatible

As listed on the Asset Store.