This repository is based on Ryan Hipple Talk about Game Architecture with Scriptable Objects and containe collection of wrappers that can help you manage dependancies between systems/components. Make sure to be familiar with concept of scriptable objects, because they are the core of this package. Clone this Repo to see the use case of this package.
Variables
are wrappers for any type of data (preferable value type), the purpose of Variables
is to decouple data from system, so other systems can access this data without need to know the source of the data. All Variables
derived from scriptable object.
Event Variables
are like normal variable with addition option for raising game event whenever variable is changed through SetValue
method.
use Reference Varaible
as a field whenever you don't know whether the class should use variable
or constant.
use ReadOnly Variable
as a field whenever you need access the value of Variable
, but you don't want to change it.
By default there are 4 different variables for int
, float
, bool
and string
. That include Variable
, Event Variable
, Reference Variable
, and Readonly Variable
for those types.
You can create more variable types with Class Creator or from code.
All Variables
and Event Variables
can be create from project context menu
Variables path : Create > ScriptableVars > Vars
Event variables path : Create > ScriptableVars > EventVars
Game events are scriptable objects that can be raise from code or by UnityEvent in editor. Every game event contain list of listeners which will be call whenever event is raise. The purpose of game event is to decouple event caller from event receiver.
By default there are 5 different Game Events
for each Game Event
there is corresponding Listener
. The zero argument Listener
can subscribe to any type of Game Event
.
- GameEvent
- IntGameEvent
- FloatGameEvent
- BoolGameEvent
- StringGameEvent
You can create more game event types with Class Creator or from code.
All Game Events
can be create from project context menu
Variables path : Create > ScriptableVars > Events
Game Event Triggers
are components that can help you trigger your Game Events
on one of the unity event(Awake, OnEnable etc.) without need to write additional code. All default game events
are supported.
Use Event Trigger
to trigger Game Event
on one of this unity event:
- Awake
- OnEnable
- Start
- OnDisable
- OnDestroy
Use Collision Event Trigger
to trigger Game Event
on one of this unity event:
- OnTriggerEnter
- OnTriggerEnter2D
- OnTriggerExit
- OnTriggerExit2D
- OnCollisionEnter2D
- OnCollisionEnter
- OnCollisionExit2D
- OnCollisionExit
Collision Event Triggers
support dynamic parameter for parameters which type derived from Component
, like ParticleSystem
or Rigidbody
. If dynamic parameter is tick then Game Event
will be call with component attached to the gameobject
which trigger on of the unity physic events. If the component is not present then one of the following think happen, depends on chosen behavior:
- StopOnNull - won't trigger event if component is null
- TriggerWithDefualt - will trigger event with component set in editor
- TriggerWithNull - will trigger event passing null as the argument
Dynamic Collections
are wrappers for List of Components
or Game Objects
the purpose of Dynamic Collections
is to decouple the way of collecting Components
or Game Objects
from the systems that require those Components
/Game Objects
.
By defualt there is only GameObjectCollection
, which can contain Game Objects
Currently you can add custom dynamic collection only from code(Class Creator will support creation of dynamic collection in the near future).
Use this code snippets as the guidelines for creating custom dynamic collection.
[NameOfType]
- type name of the component for example Rigidbody
namespace GTVariable
{
public class [NameOfType]Collection : DynamicCollection<[NameOfType]>
{
}
}
//this file should be in "Editor" folder
namespace GTVariable.Editor
{
public class [NameOfType]CollectionEditor : DynamicCollectionEditor<[NameOfType]Collection, [NameOfType]>
{
}
}
Text Widgets
are components that can help you display value of Variable
on the screen. There is TextWidget
for each default Variable
. You need TextMeshPro
to use this components.
To update widget you need to call UpdateValue method. You can do that by adding a Listener
component on same Game Object
and calling UpdateValue method in response.
Use class creator whenever you need to create custom type of Variable
, Game Event
or Event Trigger
To open class creator window navigated to Tools > Class Creator
After opening the class creator window:
- Specify the path in which files should be create, by clicking on
Select Button
in top right.
The path should lead to the Assets folder and shouldn't lead to the this package folder
- Specify the class name and type name for example Class Name:
Float
| Type Name:float
- You can add namespace in namespace field, if needed. For example
using MyNameSpace;
- Select either
Game Event Creator
to create customGame Event
orVariable Creator
to create customVariable
- Select classes you want to create.
- You can preview file by clicking
Preview Button
. You need to update preview everytime you make chanages. - Click
Create Button
to create clasess file orDelete Button
to delete classes file.
.
├── Editor # Folder for editor class
| ├── Collections
| ├── Events
| | ├── EventTriggers
| | | ├── CollisionTriggers
| | | └── Triggers
| | ├── GameEvents
| | ├── Listeners
| | └── UnityEvents
| └── Variables
| | ├── References
| | └── Vars
| | | └── ReadOnly
└── Runtime # Folder for runtime class
| ├── Collections
| ├── Events
| | ├── EventTriggers
| | | ├── CollisionTriggers
| | | └── Triggers
| | ├── GameEvents
| | ├── Listeners
| | └── UnityEvents
| └── Variables
| | ├── EventVars
| | ├── References
| | └── Vars
| | | └── ReadOnly