AutoWiring

$49
Publisher A Monkey Made This
File size 6.73MB
Number of files 121
Latest version 1
Latest release date 2022-07-04 10:06:12
First release date 2022-07-04 10:06:12
Supported Unity versions 2018.4.2 or higher

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.

Top Publisher Assets