AutoWiring [Lite]
A Monkey Made This
$0.0
$4.99
100%OFF
(no ratings)
Date |
Price |
---|---|
Date |
Price($) |
08/29(2022) |
4.99 |
08/16(2023) |
0.0 |
11/21(2024) |
0.0 |
Jump AssetStore
The dependency-injection style alternative to GetComponent()! Similar to [RequireComponent] but actually goes and gets the component, resource or streaming asset for you, automatically.Note: This is the 'Lite' version, it contains DLL only (no source code) but has full functionality and FREE to use as you like for as long as you like- think of it as a free evaluation, try-before-you-buy or just use it in your project. If you require the source code or simply want to support development of this or other assets please consider the paid version https://u3d.as/2RrS.Uses attributes and reflection to automatically search for components, rather than having to create the definition then later use one of the GetComponent(). 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?Collect underpants.Add a [Configure] annotation to a MonoBehaviour class definition. (It makes the reflection more efficient!)Add a GameObject field and let's call it Bob. Bob can be public, private, internal or protected, whatever they want.Annotate Bob with a [Find("Bob")].Add AutoWiring.ApplyTo(this); to OnEnable(), Awake() or Start(). Then add Debug.Log($"Hello {Bob}!"); on the next line.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.Press "Play" then say "Hello Bob!" when you see it in the Console.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.TypesAutoWiring will automatically collect these items for you:GameObjectsComponentsResourcesStreamingAssetsGameObject attributes (vs equivalent / underlying functionality)[Find(string name)] == GameObject.Find(string name)Component attributes (vs equivalent / underlying functionality)[GetComponent(Type type)] == GetComponent()[GetComponentInParent(Type type)] == GetComponentInParent()[GetComponentInChildren(Type type)] == GetComponentInChildren()[GetComponents(Type type)] == GetComponents()[GetComponentsInParent(Type type)] == GetComponentsInParent()[GetComponentsInChildren(Type type)] == GetComponentsInChildren()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)[GetStreamingAsset(string path)] == Unity StreamingAssets Documentation