GithubHelp home page GithubHelp logo

scriptablereferencegenerator's Introduction

Scriptable Reference Generator

A little but easy and handy solution to inject dependencies in the Unity-Way (Code & Editor via ScriptableObjects)

How to use

  • Mark any of your MonoBehaviour with [ReferenceAutoGeneration] attribute
  • After project compilation, add a fresh generated script called YourClassNameRefSetter to GameObject which contains your MonoBehaviour
  • Put to the Scriptable field your fresh generated asset from Assets/Data/References/ folder.
  • The Generated scriptable asset holds an instance of an object.
  • To use that instance you need to reference the asset in the way as you always reference assets via [SerializedField] or just mark it as public in your MonoBehaviour

An example of usage here

When to use

When you don't need all the power that Zenject provides, when you have not too many reference-depepending scripts, but you want a simple way to handle dependency injection with some benefits.

What the benefits

  • You can create multiple assets by duplicate one of them, doing this you can hold a multiple instances of needed type of a class.
    For example you have few characters which needs to be referenced somewhere else, then you can mark Character class with the [ReferenceAutoGeneration] attribute, duplicate your generated asset, rename it and use this assets independently to link to your characters.
  • It also works for tests in the same way.
  • Using this you don't need to hardcode references, using Singletone/ServiceLocator, or doing any other tricky ways to achieve some sort of dependency injection.

scriptablereferencegenerator's People

Contributors

serezhadelaet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.