Go to file
Adam Ramberg bdf81a5e9c Squashed commit of the following:
commit 847eff037204d841546c0da772d2f341f9cf1e25
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Sun Mar 17 22:09:38 2019 +0100

    #17 - Serializable not needed for ScriptableObject

commit 593b275e6394b9d589de8a7a20375145dfc4aa84
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Sun Mar 17 21:59:33 2019 +0100

    18 - IGameEvent<T1, T2> RegisterListener

commit 40443ce9bd4b1c339aaf19cfcb119f2336608dae
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:35:04 2019 +0100

    Remove some more warnings

commit bd453110ac51a6ebe3d54368fcb039bdbe52e278
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:33:30 2019 +0100

    Update README

commit 90977b853a047c84efb5311768a09f4e8a1165b2
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:31:45 2019 +0100

    Initialize to null to get rid off warnings

commit 38b7f5c4ede195aa7198f567801c9cbeedc9b6f6
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:15:53 2019 +0100

    More fixes to enable local unity project

commit 404e1cbf88ed4431c61d3ece074e838e74ac5141
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:12:37 2019 +0100

    Remove duplicated asmdef

commit 5734300684e8a16553f213157cad1b4722b7cb7f
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:09:46 2019 +0100

    Change files to include

commit d1e42b119a6bc1577b1792459fa298e063652337
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 16:05:56 2019 +0100

    Added root package json

commit 1709a0347147d74460f653182bbaf8d15eb6154e
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 15:30:44 2019 +0100

    #16 - Add test and examples Unity project

commit a3ea1a133bf6727e011ba85c64569db45302e487
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 13:12:02 2019 +0100

    #13 - Make usage of UPM (package manager)

commit 492a30e905f6cf3f5899cb7080ef2bda73110f00
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 11:28:56 2019 +0100

    Added extensions + code formatting fixes

commit 709949a1016c236cfd363cf25392fedfd8d083ca
Author: Oliver Biwer <soraphis@users.noreply.github.com>
Date:   Fri Mar 8 10:16:45 2019 +0100

    More AtomicTags changes (#15)

    * - added assembly defintions, and unit tests
    - improved AtomicTags in regards of #8, #9 and #10

    * Fixes #11
    - Added Equality Members (inclusive HashCode) for ScriptableObjectVariableBase

    * removed Rider Plugins from git

    * Further AtomicTag optimization

commit ae6584c879f182e727fe0a8d0aff4b0715829914
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 10:08:36 2019 +0100

    Editor config

commit 197d7067608600e4e2d13dc42db909ee8f8c75df
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Mar 8 09:23:12 2019 +0100

    Added editor config file

commit 53d6adc07b
Author: Oliver Biwer <soraphis@users.noreply.github.com>
Date:   Tue Mar 5 22:57:47 2019 +0100

    More efficient AtomicTags (#12)

    * - added assembly defintions, and unit tests
    - improved AtomicTags in regards of #8, #9 and #10

    * Fixes #11
    - Added Equality Members (inclusive HashCode) for ScriptableObjectVariableBase

    * removed Rider Plugins from git

commit 81209d83b5
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Wed Dec 12 20:54:17 2018 +0100

    Added MonoHooks + ColliderType + bug fixes

commit c6b240cebb
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Sat Dec 1 00:23:10 2018 +0100

    Experimenting with adding UI state management

commit dfd70a8944
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Nov 30 23:10:21 2018 +0100

    Issue #6 - AtomicTags

commit 8907763227
Author: Adam Ramberg <andersson.adam.89@gmail.com>
Date:   Fri Nov 30 22:42:29 2018 +0100

    First commit of v1.0.0
2019-03-17 23:43:20 +01:00
Source Squashed commit of the following: 2019-03-17 23:43:20 +01:00
UnityAtomsTestsAndExamples Squashed commit of the following: 2019-03-17 23:43:20 +01:00
.editorconfig Squashed commit of the following: 2019-03-17 23:43:20 +01:00
.gitignore Squashed commit of the following: 2019-03-17 23:43:20 +01:00
LICENSE Added license 2018-11-18 15:56:29 +01:00
LICENSE.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00
omnisharp.json Squashed commit of the following: 2019-03-17 23:43:20 +01:00
omnisharp.json.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00
package.json Squashed commit of the following: 2019-03-17 23:43:20 +01:00
package.json.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00
README.md Squashed commit of the following: 2019-03-17 23:43:20 +01:00
README.md.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00
Source.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00
UnityAtomsTestsAndExamples.meta Squashed commit of the following: 2019-03-17 23:43:20 +01:00

⚛️ Unity Atoms

Tiny modular pieces utilizing the power of Scriptable Objects

Read this article on Medium for a great introduction to Unity Atoms.

Influences

Unity Atoms is derrived from and a continuation of Ryan Hipple's talk from Unite 2017. The original source code can be found here.

This talk by Richard Fine is a forerunner to Ryan Hipple's talk during Unite 2016.

Motivation

The general approach to building scripts in Unity often generates a code base that is monolithic. This results in that your code is cumbersome to test, non-modular and hard to debug and understand.

Unity Atoms is an open source library that aims to make your game code:

  • 📦 Modular - avoid scripts and systems directly dependent on each other
  • ✏️ Editable - Scriptable Objects makes it possible to make changes to your game at runtime
  • 🐞 Debuggable - modular code is easier to debug than tightly coupled code

Introduction

Before you start looking into this library you should watch the video above ☝️ and read this article on how to architect your game with Scriptable Objects.

Installation 2018.3+

Go to your projects Packages/manifest.json and add this:

 "dependencies": {
    ...
    "com.mambojambostudios.unity-atoms": "https://github.com/AdamRamberg/unity-atoms.git#v1.0.0",
    ...
 }

This will make the Unity packagemager install it.

Usage

Unity Atoms is an event based system that encourages the game to be as data-driven as possible. The 4 most fundamental pieces (atoms) of Unity Atoms are:

  • Variables
  • (Game) Events
  • (Game Event) Listeners
  • Responses

Variables

Variables are data / variables stored as Scriptable Objects. Because Variables are stored as Scriptable Objects they are not part of any scene, but could be instead be seen as part of a global shared game state. Variables are also designed to make it easy to inject (via the Unity Inspector) to your MonoBehaviours.

It is possible to attach an event to a Variable that gets raised when its updated. This makes it possible to write more data-driven code.

It is also possible to attach another event to a Variable that also gets raised when a Variable is changed, but that contains both the old and the new value of the Variable.

Unity Atoms also offer some variations / additions to Variables such as Contants, References and Lists.

Constants

Exactly the same as Variables, but can not be changed via script and therefore does not contain the change events that Variables does. The idea is to use Constants for for example tags instead of hard coding tags in your scripts.

References

References can be toggled between "use as constant" or "use variable" via the Unity Inspector. When a reference is "used as constant" then it functions exactly like a regular serialized variable in a MonoBehaviour script. However, when it is set to "use variable" it functions exactly like a Variable.

Lists

A list is an array of values that is stored as a Scriptable Object. There is the possibility to add Game Events for when the following happens to the list:

  • An item is added to the list.
  • An item is removed from the list.
  • The list is cleared.

Game Events

A game event is a thing that happens in the game that others could listen / subscribe to. Game events are also Scriptable Objects that lives outside of a specific scene. It is possible to raise a Game Event from the Unity Inspector for debug purposes.

Game Event Listeners

A listener listens / observes / subscribes to an event and raises / invokes zero to many responses to that event. Game Event Listeners are Monobehaviours and lives in a scene. See below for more information on the type of responses there are.

Responses

A responses is raised by a listener in response to an event. Responses can live both in the scene as UnityEvents or outside the scene as a Scriptable Object in the shape of a Game Action or a Game Function.

Game Actions

A Game Action is a C# function as a Scriptable Object. A Game Function can be used as a response in a Game Event Listener.

Game Functions

A Game Function is basically the same as a Game Action, but while a Game Actions does not return something a Game Function does.

Mono Hooks

Mono Hooks is a way to make it possible to have Unity lifecycle methods as events. The main reason for this is to make this pattern consistent and possible to use in ALL of your code.

Further Notes

When you start thinking about this pattern you will realize that everything can be explained using the atoms above. The native Unity lifecycle methods can be thought of as variation of the pattern above, where events gets raised and passes a long data (eg. OnTriggerEnter2D) and you write a response to that event.

Examples

Examples will soon be added to this project.

Contribution

Would ❤️ if you would like to contribute to the project. Post me a message if you want to become a contributer.