-
Notifications
You must be signed in to change notification settings - Fork 119
Quick Start
The first thing you should do, is ensure your Unity editor version is compatible with SO-A. You currently need Unity version 2017.3 or higher
There are three ways you can install SO-A. Here's a short guide that explains the pros and cons of each method
+ Get updates as soon as they're ready.
+ Has an in-editor manager for updates.
+ Assets are kept in a separate section, which reduces clutter in project-view
+/- Assets will be locked, so you can't modify the source code in any way. Whether this is a good or bad thing is up to you
- Not properly supported until 2018.1
+ Has an in-editor manager for updates.
- Updates can take several days to be published, due to manual verification step by Unity.
- Installation and updating can be tedious
- No in-editor way to check for updates.
- Ensure you're using Unity 2018.1 or higher
- Open your asset folder
- Open the "Packages" folder
- Open the "manifest.json" file in a text editor
- Add the following to your dependencies
"com.danieleverland.scriptableobjectarchitecture": "https://github.com/DanielEverland/ScriptableObject-Architecture.git#release/stable",
- Save changes. Unity will automatically import the package.
- Open the Unity Asset Store window
- Search for "ScriptableObject-Architecture"
- Select the ScriptableObject-Architecture package and click on "IMPORT"
- Import all assets
-
Navigate to the GitHub Release Page
-
Open the newest release and click on the .unitypackage file
- In Unity, click on Assets > Import Package > Custom Package...
- Select the downloaded .unitypackage file
- Import all assets
Under Construction
Throughout this tutorial I'll take you through the step-by-step instructions for using the following features of ScriptableObject-Architecture
- Variables
- References
- Events
- Typed events
- Runtime sets
This will also give you a fundamental understanding of how using scriptable objects can improve your architecture in terms of decoupling systems and debugging them.
In order to keep the length of this tutorial manageable, I will only describe code and concepts relating to SO-A specifically. Everything else, like how to register collisions in Unity, code snippets for code that makes the player move etc. will not be covered. The entire repository is available in the branch called "tutorial", though, in case you want to check it out.
The first thing we're going to do is create two assets. These assets will define the maximum- and current amount of health the player has. These are both what SO-A calls 'variables', as they store data, and both will be of the type float
.
First, we'll create the max health variable. To do so, simply right-click somewhere in your project and select Create > Variables > float.
We're going to name this asset "PlayerMaxHealth" and set its value to 100
We're going to do the exact same thing for our players current health, but leave it blank, since it'll be managed by code.
Great! Now we need to tie this together with some code. For now the only responsibility of this piece of code is to set the current health to maximum when the game starts, but we'll expand it later on to add more complex behaviour.
This leads us to SO-A's next concept: references. References are what allows us to reference some value from our code without knowing where it comes from - all we care about is reading and writing to it, the rest is handled entirely from Unity's inspector. We're dealing with data of the type float
, so we want to use the reference type called FloatReference
.
We simply create a component that includes the following snippet
[SerializeField]
private FloatReference currentHealth = null;
[SerializeField]
private FloatReference maxHealth = null;
private void Awake()
{
currentHealth.Value = maxHealth.Value;
}
In order to couple our assets to these values, we simply drag them into the inspector
- Player (Variables - Max Health, Clamped Variables - Current Health, References)
- Health UI (Events - OnDamagedEvent, decoupling)
- Damage Indicator (Typed event)
- Placing Cubes (Runtime sets)