Skip to content

Dependency Injection totalement à la noix for Unity, honestly the shittiest alternative out there, but it does what I need. Used in https://anthony-rey.itch.io/morstairs

License

MIT, Unknown licenses found

Licenses found

MIT
LICENCE
Unknown
LICENCE.meta
Notifications You must be signed in to change notification settings

ReyAnthony/DItan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DItan

Quick and dirty Dependency Injection for Unity / DI totalement à la noix

DItan is used to Inject scriptable object at the start of a scene.

Usage

First, create an empty GameObject in the scene with the component "SceneInjector" attached. Then create a ScriptableInjector asset with Right click > Create/DItan/ScriptableInjector.

[CreateAssetMenu(menuName = "game/assets/Player stats")]
public class PlayerStats : ScriptableObject
{
    public int Score => 10;
}
public class ScoreBoard : MonoBehaviour
{
    [Inject] private PlayerStats _stats;
    [SerializeField] private Text _scoreText;

    private void Start()
    {
        _scoreText.text = _stats.Score.ToString();
    }
}
 private void InternalSpawnIntoScene(Vector3 position)
{
        _refInScene = _injector.InstantiateNew(_modelPrefab, position, Quaternion.identity);
        _selectable = _refInScene.GetComponent<Selectable>();
        _navMeshAgent = _refInScene.GetComponent<NavMeshAgent>();
        ....
}

About

Dependency Injection totalement à la noix for Unity, honestly the shittiest alternative out there, but it does what I need. Used in https://anthony-rey.itch.io/morstairs

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENCE
Unknown
LICENCE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages