Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Syrinj
###### **Lightweight dependency injection** & convenient attributes for Unity

### [Release 1.1.1 available here!](https://github.com/mfav/syrinj/releases/tag/1.1.1) (8/1/16)
### Updated to work with Unity 2021.1

---

Expand Down Expand Up @@ -122,7 +122,7 @@ public class GoodHomingMissile {
}
```

Make sense? That's dependency injection. The `GoodHomingMissile` has a dependency of a `Player` target, and the `RocketLauncher` tells it which target to move towards on construction! This is a good practice because you know that if a `GoodHomingMissile` is created, it must have had its target specified.
Makes sense? That's dependency injection. The `GoodHomingMissile` has a dependency of a `Player` target, and the `RocketLauncher` tells it which target to move towards on construction! This is a good practice because you know that if a `GoodHomingMissile` is created, it must have had its target specified.

If you're a Unity developer, you may already notice a slight issue. In Unity, you don't instantiate objects with constructors! Instead, you call `GameObject.Instantiate()`. One workaround is to make an `Initialize()` method:

Expand Down Expand Up @@ -205,6 +205,10 @@ public class ExampleProvider : MonoBehaviour
[Provides]
[FindObjectOfType(typeof(Canvas))]
private Canvas UIRootProvider; // any convenience attribute can be combined with "Provides"

[Provides]
[FindResourceOfType(typeof(GameData))]
private GameData _gameData; // Finds the first asset of type GameData in a 'Resources' folder within your project

[Provides]
public float RandomNumberProvider
Expand Down Expand Up @@ -260,6 +264,7 @@ public class ExampleInjectee : MonoBehaviour
| `[Find]` | `string GameObjectName` | Finds a GameObject in scene with a given name. |
| `[FindWithTag]` | `string Tag` | Finds a GameObject in scene with a given tag. |
| `[FindObjectOfType]` | `System.Type ComponentType` | Finds a component in the scene with a given type. |
| `[FindResourceOfType]` | `System.Type ComponentType` | Finds the first asset of a given type in a 'Resources' folder |

##### Injection attributes:

Expand Down
5 changes: 2 additions & 3 deletions Scripts/Attributes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/AnimatorStringHash.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/FindAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/FindObjectOfTypeAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/FindRelativeAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Scripts/Attributes/FindResourceOfTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using Syrinj.Attributes;

namespace Syrinj
{
public class FindResourceOfTypeAttribute : UnityConvenienceAttribute
{
public readonly Type ComponentType;

public FindResourceOfTypeAttribute()
{ }

public FindResourceOfTypeAttribute(Type componentType)
{
ComponentType = componentType;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/FindWithTagAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/GetComponentAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/GetComponentInChildrenAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/InjectAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/InstanceAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/ProvidesAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/SingletonAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/UnityConvenienceAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/UnityDependencyAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/UnityInjectorAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Attributes/UnityProviderAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/DependencyContainer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Exceptions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Exceptions/InjectionException.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/GameObjectInjector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Graph.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Graph/DependencyMap.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Injection.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Injection/Injectable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Injection/InjectableFactory.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Injection/InjectableField.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Injection/InjectableProperty.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Scripts/InjectorComponent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Scripts/Provider.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading