Code Monkey home page Code Monkey logo

dekuple's Introduction

Dekuple Icon

Build status CodeFactor License Release

A dependancy-injection and entity system designed from the ground up to support both rapid prototyping and long-term development and support of Unity3d based applications.

The system also adds a MVC or Model-View-Controller pattern.

Except in this case, the Controller is called an Agent and uses the Flow library, and Views are based on MonoBehaviors.

The basic architecture is a morphism of a number ideas combined together into an integrated whole:

  • Dependancy Injection
  • Object Registry/Factory for persistence and networking
  • Model/View/Controller, or Model/ViewController/View
  • Unity3d Prefabs and Behaviours
  • Reactive programming techniques

The code is not 'tricky', other than the hoops required for templates in C#. The key hurdle a user will face is simply understanding the architecture and semantics of the seemingly simple systems.

One key understanding required is that one Registry<T> class is used for each model/agent/view domains, but of course with a different template parameter T.

There are Readme's in each substantial sub-folder that describes each component in more detail.

Unity Package

This repo is designed to be used as a Untiy3d Package. However, there are also Dekuple.{sln,proj} available so it can be opened in VisualStudio independantly. This results in these files being in the Unity3d package, even though they are unused. They hence also have .meta files.

Do not delete these or their .meta files.

Dependancies

This library uses the external CoLib and Flow libraries. These are added as git sub-modules.

Main Components

Request/Response

Used for internal message-passing/queing and in future for networking when combined with the Pyro system.

Future Work

This system is intended to be used with the new Unity3d ECS system.

Currently, only the View system has any reference to Unity3d.

It would be nice to separate that into a separate Assembly, so the system could be used outside the context of Unity3d.

Docs


Obsolete Unity Methods

Unity's Awake function, do not use within Dekuple entities - see Create.

Unity's Start function, do not use within Dekuple entities - see Begin.

Unity's OnDestroy function, do not use within Dekuple entities - instead subscribe to the OnDestroyed event.


Dekuple Documentation

Create

Alternative to Awake within Dekuple entities, called before Begin. Ensure that base.Create() is called.

Begin

Alternative to Start within Dekuple entities. Ensure that base.Begin() is called.

AddSubscriptions

Called after the object has been prepared, all dependencies have been resolved and all injections completed. Use this for initialising things that depend on injections.

Main.NewEntity

public TIView Main.NewEntity<TIView, TIAgent, TIModel>(Object prefab)

Create a new, complete entity from the given prefab. The simplest way to create a new entity.

Main.SetupEntities

private TIView[] Main.SetupEntities<TIView, TIAgent, TIModel>(params object[] args)

Create and prepare models and agents for objects of type TIView that exist in the scene.

ViewRegistry.FromPrefab

public TIView FromPrefab<TIView>(Object prefab);
public TIView FromPrefab<TIView>(Object prefab, Transform parent);
public TIView FromPrefab<TIView>(Object prefab,  IRegistry<TIAgent> agents);
public TIView FromPrefab<TIView>(Object prefab,  IAgent agent);
public TIView FromPrefab<TIView>(Object prefab, IRegistry<TIModel> models, IRegistry<TIAgent> agents = null);
Parameters
prefab The prefab to make an instance of.
parent Parent that will be assigned to the new object.
agent The agent to type to give to the newly created object.
agents The agent registry to find an appropriate agent from

Create a new View from the given prefab. Its model and agent will need to be added seperately if required. Equivalent to UnityEngine.Object.Instantiate.

Registry.Bind<TInterface, TImpl>()

Connect the given interface and concrete type together in the registry.

ViewRegistry.Bind<TInterface, TImpl>(T single)

Connect the given interface and concrete together as a singleton instance. Will create a GameObject given a prefab or connect to an existing GameObject within the scene.

ViewRegistry.InjectAllGameObjects()

Resolve all injections for GameObjects of type ViewBase that exist within the scene.

Registry.AddAllSubscriptions()

Invoke AddSubscriptions() for all instances in the given registry.

TODO

Make Error(..) etc log methods return object so they can return null and simplify usage.

dekuple's People

Contributors

cschladetsch avatar jarisrener avatar liminal-cto avatar andrea avatar bravesirandrew avatar davidliminal avatar

Watchers

James Cloos avatar  avatar

dekuple's Issues

View registry FromPrefab should have the same overloads as Object.Instantiate

public static Object Instantiate(Object original);
public static Object Instantiate(Object original, Transform parent);
public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace);
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);

Add validation systems

  • Add warnings for views that implement Unity methods - e.g. Start, Awake, Update.
  • During Editor time
  • During Run time
  • Impose any other pre-conditions and invariants
  • Warn on injections that have null values

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.