mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-22 08:08:51 -05:00
Update docs + remove ds store
This commit is contained in:
parent
c3bc59259f
commit
6f78cab386
2
.gitignore
vendored
2
.gitignore
vendored
@ -44,3 +44,5 @@ node_modules
|
|||||||
|
|
||||||
# Website build folder
|
# Website build folder
|
||||||
/website/build
|
/website/build
|
||||||
|
|
||||||
|
.DS_Store
|
@ -7,8 +7,6 @@ namespace UnityAtoms.Examples
|
|||||||
{
|
{
|
||||||
public class HealthBarUniRx : MonoBehaviour
|
public class HealthBarUniRx : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
|
||||||
private IntConstant _maxHealth = null;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private IntVariable _health = null;
|
private IntVariable _health = null;
|
||||||
|
|
||||||
@ -16,7 +14,7 @@ namespace UnityAtoms.Examples
|
|||||||
{
|
{
|
||||||
_health.ObserveChange().Subscribe(health =>
|
_health.ObserveChange().Subscribe(health =>
|
||||||
{
|
{
|
||||||
GetComponent<Image>().fillAmount = 1.0f * health / _maxHealth.Value;
|
GetComponent<Image>().fillAmount = 1.0f * health / _health.InitialValue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
Packages/.DS_Store
vendored
BIN
Packages/.DS_Store
vendored
Binary file not shown.
BIN
Packages/Core/.DS_Store
vendored
BIN
Packages/Core/.DS_Store
vendored
Binary file not shown.
BIN
Packages/Core/Editor/.DS_Store
vendored
BIN
Packages/Core/Editor/.DS_Store
vendored
Binary file not shown.
@ -228,7 +228,7 @@ namespace UnityAtoms.Editor
|
|||||||
private VisualElement CreateAtomTypeToGenerateToggleRow(AtomType atomType)
|
private VisualElement CreateAtomTypeToGenerateToggleRow(AtomType atomType)
|
||||||
{
|
{
|
||||||
var row = new VisualElement() { style = { flexDirection = FlexDirection.Row } };
|
var row = new VisualElement() { style = { flexDirection = FlexDirection.Row } };
|
||||||
row.Add(new Label() { text = atomType.Name, style = { width = 180, marginRight = 8 } });
|
row.Add(new Label() { text = atomType.DisplayName, style = { width = 180, marginRight = 8 } });
|
||||||
var toggle = new Toggle() { value = _atomTypesToGenerate.Contains(atomType) };
|
var toggle = new Toggle() { value = _atomTypesToGenerate.Contains(atomType) };
|
||||||
toggle.RegisterCallback<ChangeEvent<bool>>(evt =>
|
toggle.RegisterCallback<ChangeEvent<bool>>(evt =>
|
||||||
{
|
{
|
||||||
|
BIN
Packages/Core/Editor/Resources/.DS_Store
vendored
BIN
Packages/Core/Editor/Resources/.DS_Store
vendored
Binary file not shown.
@ -15,7 +15,9 @@
|
|||||||
"/Runtime",
|
"/Runtime",
|
||||||
"/Runtime.meta",
|
"/Runtime.meta",
|
||||||
"/Editor",
|
"/Editor",
|
||||||
"/Editor.meta"
|
"/Editor.meta",
|
||||||
|
"/Documentation",
|
||||||
|
"/Documentation.meta"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.mambojambostudios.unity-atoms-core": "4.0.0"
|
"com.mambojambostudios.unity-atoms-core": "4.0.0"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
"/package.json.meta",
|
"/package.json.meta",
|
||||||
"/Runtime",
|
"/Runtime",
|
||||||
"/Runtime.meta",
|
"/Runtime.meta",
|
||||||
|
"/Editor",
|
||||||
|
"/Editor.meta",
|
||||||
"/Documentation",
|
"/Documentation",
|
||||||
"/Documentation.meta"
|
"/Documentation.meta"
|
||||||
],
|
],
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 48 KiB |
@ -161,7 +161,7 @@ The `HealthBar.cs` script is now only responsible for what happens when our play
|
|||||||
The `HealthChanged` function created above is actually a Response of type `UnityEvent`. However, in Unity Atoms there is also the possibility to create Responses as Scriptable Objects called Actions. An Action is a function as a Scriptable Object that does not return a value. As a side note there are also Functions in Unity Atoms, which are exactly like Actions, but does return a value. To demonstrate the concept of an Action as a Response lets create an Action called `HealthLogger.cs` that gives some love to the console and logs the player’s health whenever it changes:
|
The `HealthChanged` function created above is actually a Response of type `UnityEvent`. However, in Unity Atoms there is also the possibility to create Responses as Scriptable Objects called Actions. An Action is a function as a Scriptable Object that does not return a value. As a side note there are also Functions in Unity Atoms, which are exactly like Actions, but does return a value. To demonstrate the concept of an Action as a Response lets create an Action called `HealthLogger.cs` that gives some love to the console and logs the player’s health whenever it changes:
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
[CreateAssetMenu(menuName = "Unity Atoms/Examples//Health Logger")]
|
[CreateAssetMenu(menuName = "Unity Atoms/Examples/Health Logger")]
|
||||||
public class HealthLogger : IntAction
|
public class HealthLogger : IntAction
|
||||||
{
|
{
|
||||||
public override void Do(int health)
|
public override void Do(int health)
|
||||||
|
@ -91,15 +91,20 @@ By default the Atoms that gets generated will be under the namespace `UnityAtoms
|
|||||||
|
|
||||||
This is a list of Atom types that you want to generate. Simply select the Atoms that you want to generate. Some Atoms depends on other Atoms. If you unselect an Atom that other Atoms depends on, then the Generator will unselect those depending Atoms. Below you find the dependency graph:
|
This is a list of Atom types that you want to generate. Simply select the Atoms that you want to generate. Some Atoms depends on other Atoms. If you unselect an Atom that other Atoms depends on, then the Generator will unselect those depending Atoms. Below you find the dependency graph:
|
||||||
|
|
||||||
|
- Pair Action - depends on Pair
|
||||||
|
- Pair Event - depends on Pair
|
||||||
- Value List - depends on Event
|
- Value List - depends on Event
|
||||||
- Listener - depends on Action, Variable, Event, Event x 2, Function x 2, Variable Instancer, Event Reference and Unity Event
|
- Event Reference Listener - depends on Action, Variable, Event, Pair Event, Function x 2, Variable Instancer, Pair Event Reference and Unity Event and Pair.
|
||||||
- Listener x 2 - depends on Action x 2, Variable, Event, Event x 2, Function x 2, Variable Instancer, Event x 2 Reference and Unity Event x 2
|
- Pair Event Reference Listener - depends on Pair Action, Variable, Event, Pair Event, Function x 2, Variable Instancer, Event Reference and Pair Unity Event and Pair.
|
||||||
- Reference - depends on Constant, Variable, Event, Event x 2, Function x 2 and Variable Instancer
|
- Reference - depends on Constant, Variable, Event, Pair Event, Function x 2 and Variable Instancer and Pair.
|
||||||
- Set Variable Value - depends on Event, Event x 2, Function x 2, Variable, Constant, Reference, Variable Instancer
|
- Event Reference - depends on Variable, Event, Pair Event, Function x 2, Variable Instancer and Pair.
|
||||||
- Variable - depends on Event, Event x 2 and Function x 2
|
- Pair Event Reference - depends on Variable, Event, Pair Event, Function x 2, Variable Instancer and Pair.
|
||||||
- Variable Instancer - depsends on Variable, Event, Event x 2, Function x 2
|
- Set Variable Value - depends on Event, Pair Event, Function x 2, Variable, Constant, Reference, Variable Instancer and Pair.
|
||||||
- Event Reference - depends on Variable, Event, Event x 2, Function x 2, Variable Instancer
|
- Pair Unity Event - depends on Pair.
|
||||||
- Event x 2 Reference - depends on Variable, Event, Event x 2, Function x 2, Variable Instancer
|
- Variable - depends on Event, Pair Event, Pair and Function x 2
|
||||||
|
- Variable Instancer - depsends on Variable, Event, Pair Event, Function x 2 and Pair.
|
||||||
|
- Event Instancer - depsends on Event.
|
||||||
|
- Pair Event Instancer - depsends on Event and Pair.
|
||||||
|
|
||||||
### Close & Generate
|
### Close & Generate
|
||||||
|
|
||||||
|
@ -9,59 +9,86 @@ sidebar_label: Overview and philosopy
|
|||||||
|
|
||||||
Unity Atoms is an event based system that encourages the game to be as data-driven as possible. The four most fundamental parts of Unity Atoms are:
|
Unity Atoms is an event based system that encourages the game to be as data-driven as possible. The four most fundamental parts of Unity Atoms are:
|
||||||
|
|
||||||
- Variables
|
- Data
|
||||||
- Events
|
- Events
|
||||||
- Listeners
|
- Listeners
|
||||||
- Responses
|
- Functions
|
||||||
|
- Collections
|
||||||
|
|
||||||
## Variables
|
## Data
|
||||||
|
|
||||||
|
### 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.
|
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 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.
|
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 generates Pairs (a simple struct) for Atoms containing 2 variables of the same type for this purpose.
|
||||||
|
|
||||||
You can also add pre change transformers to a Variable. A pre change transformer is an AtomFunction that takes the value type of the Variable, performs some logic, and returns a new value of the same type. It's called on `OnEnable` as well as before setting a new Value of a Variable. An example of a pre change transformer is `ClampInt`, an `IntIntFunction` that clamps the Variable's value between two values.
|
You can also add pre change transformers to a Variable. A pre change transformer is an AtomFunction that takes the value type of the Variable, performs some logic, and returns a new value of the same type. It's called on `OnEnable` as well as before setting a new Value of a Variable. An example of a pre change transformer is `ClampInt`, an `IntIntFunction` that clamps the Variable's value between two values.
|
||||||
|
|
||||||
Unity Atoms also offer some variations / additions to Variables such as Contants, References and Lists.
|
Unity Atoms also offer some variations / additions to Variables such as Contants, References and Lists.
|
||||||
|
|
||||||
## Constants
|
### 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.
|
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
|
||||||
|
|
||||||
References are values that can be toggled between `Use Value`, `Use Constant`, `Use Variable` or `Use Variable Instancer` via the Unity Inspector. When a Reference is set to `Use Value` it functions exactly like a regular serialized variable in a MonoBehaviour script. However, when it is set to `Use Variable` or `Use Constant` it uses a Variable or a Constant. When it's set to `Use Variable Instancer` you can drag and drop a Variable Instancer of the correct type.
|
References are values that can be toggled between `Use Value`, `Use Constant`, `Use Variable` or `Use Variable Instancer` via the Unity Inspector. When a Reference is set to `Use Value` it functions exactly like a regular serialized variable in a MonoBehaviour script. However, when it is set to `Use Variable` or `Use Constant` it uses a Variable or a Constant. When it's set to `Use Variable Instancer` you can drag and drop a Variable Instancer of the correct type.
|
||||||
|
|
||||||
## Variable Instancers
|
### Variable Instancers
|
||||||
|
|
||||||
This is a MonoBehaviour that takes a base Variable and makes an in memory copy of it `OnEnable`. This is particular useful when working with prefabs that is going to be instantiated at runtime. For example, when creating an enemy prefab you can use an `IntVariableInstancer` that creates an in memory copy of the enemy's health that you then can use in your scripts on the enemy prefab (using References). You can also give it a reference to a List or a Collection. If that is done the instancer will add the in memory Variable on Start to the List / Collection and then remove it OnDestroy.
|
This is a MonoBehaviour that takes a base Variable and makes an in memory copy of it `OnEnable`. This is particular useful when working with prefabs that is going to be instantiated at runtime. For example, when creating an enemy prefab you can use an `IntVariableInstancer` that creates an in memory copy of the enemy's health that you then can use in your scripts on the enemy prefab (using References). You can also give it a reference to a List or a Collection. If that is done the instancer will add the in memory Variable on Start to the List / Collection and then remove it OnDestroy.
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
|
||||||
An event is a thing that happens in the game that others can listen / subscribe to. Events in Unity Atoms are also Scriptable Objects that lives outside of a specific scene. It is possible to raise an Event from the Unity Inspector for debug purposes.
|
### Events
|
||||||
|
|
||||||
## Event References
|
An event is a thing that happens in the game that others can listen / subscribe to. Events in Unity Atoms are also Scriptable Objects that lives outside of a specific scene. It is possible to raise an Event from the Unity Inspector for debugging purposes.
|
||||||
|
|
||||||
Event References are events that can be toggled between `Use Event`, `Use Variable` or `Use Variable Instancer` via the Unity Inspector. When an Event Reference is set to `Use Event` it functions exactly like a regular serialized Event in a MonoBehaviour script. When it is set to `Use Variable` it is going to use the Event associated with the Variable's Changed event. When it's set to `Use Variable Instancer` you can drag and drop a Variable Instancer of the correct type and it will use its associated Changed event.
|
### Pair Events
|
||||||
|
|
||||||
## Event Instancers
|
Like Event, but for pairs. Pairs are simple structs containing 2 variables of the same type, used for example in Variables' Changed With History Event.
|
||||||
|
|
||||||
|
### Event References
|
||||||
|
|
||||||
|
Event References are events that can be toggled between `Use Event`, `Use Event Instancer`, `Use Variable` or `Use Variable Instancer` via the Unity Inspector. When an Event Reference is set to `Use Event` it functions exactly like a regular serialized Event in a MonoBehaviour script. When it is set to `Use Event Instancer` you can drag and drop an Event Instancer whos Event the Event Reference will use. When it is set to `Use Variable` it is going to use the Event associated with the Variable's Changed event. When it's set to `Use Variable Instancer` you can drag and drop a Variable Instancer of the correct type and it will use its associated Changed event.
|
||||||
|
|
||||||
|
### Event Instancers
|
||||||
|
|
||||||
This is a MonoBehaviour that takes a base Event and makes an in memory copy of it `OnEnable`. This is particular useful when working with prefabs that is going to be instantiated at runtime, for example when working with Mono Hooks on your prefabs.
|
This is a MonoBehaviour that takes a base Event and makes an in memory copy of it `OnEnable`. This is particular useful when working with prefabs that is going to be instantiated at runtime, for example when working with Mono Hooks on your prefabs.
|
||||||
|
|
||||||
|
### Pair Event Instancers
|
||||||
|
|
||||||
|
Like Event Instancer, but for pairs. Pairs are simple structs containing 2 variables of the same type, used for example in Variables' Changed With History Event.
|
||||||
|
|
||||||
## Listeners
|
## Listeners
|
||||||
|
|
||||||
A Listener listens / observes / subscribes to an event and raises / invokes zero to many responses to that event. Listeners are MonoBehaviours and lives in a scene. See below for more information on the type of responses there are.
|
### Event Reference Listeners
|
||||||
|
|
||||||
|
A Listener listens / observes / subscribes to an event reference and raises / invokes zero to many responses to that Event Reference. Listeners are MonoBehaviours and lives in a scene. See below for more information on the type of responses there are.
|
||||||
|
|
||||||
|
### Pair Event Reference Listeners
|
||||||
|
|
||||||
|
Like Event Reference Listeners, but for pairs. Pairs are simple structs containing 2 variables of the same type, used for example in Variables' Changed With History Event.
|
||||||
|
|
||||||
|
### Event Reference Listeners
|
||||||
|
|
||||||
|
Like Event Reference Listeners, but are using a regular Event instead of an Event Reference. This makes more sense in listeners observing for example Collections (see more info below).
|
||||||
|
|
||||||
## Responses
|
## Responses
|
||||||
|
|
||||||
A Responses is raised by a Listener in Response to an event. Responses can live both in the scene as [UnityEvents](https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html) or outside the scene as a Scriptable Object in the shape of an Action.
|
A Responses are raised by a Listener in Response to an event. Responses can live both in the scene as [UnityEvents](https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html) or outside the scene as a Scriptable Object in the shape of an Action.
|
||||||
|
|
||||||
### Actions
|
### Actions
|
||||||
|
|
||||||
An Action in Unity Atoms is a C# function as a Scriptable Object. An Action can be used as a response in a Listener.
|
An Action in Unity Atoms is a C# function as a Scriptable Object. An Action can be used as a response in a Listener.
|
||||||
|
|
||||||
|
#### Pair Actions
|
||||||
|
|
||||||
|
Like Actions, but for pairs. Pairs are simple structs containing 2 variables of the same type, used for example in Variables' Changed With History Event.
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
|
|
||||||
A Function in Unity Atoms is basically the same as an Action, but while an Actions does not return something a Function does.
|
A Function in Unity Atoms is basically the same as an Action, but while an Actions does not return something a Function does.
|
||||||
|
@ -20,8 +20,6 @@ using UniRx;
|
|||||||
|
|
||||||
public class HealthBarUniRx : MonoBehaviour
|
public class HealthBarUniRx : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
|
||||||
private IntConstant _maxHealth = null;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private IntVariable _health = null;
|
private IntVariable _health = null;
|
||||||
|
|
||||||
@ -29,7 +27,7 @@ public class HealthBarUniRx : MonoBehaviour
|
|||||||
{
|
{
|
||||||
_health.ObserveChange().Subscribe(health =>
|
_health.ObserveChange().Subscribe(health =>
|
||||||
{
|
{
|
||||||
GetComponent<Image>().fillAmount = 1.0f * health / _maxHealth.Value;
|
GetComponent<Image>().fillAmount = 1.0f * health / _health.InitialValue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
],
|
],
|
||||||
"category": "Unity",
|
"category": "Unity",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"publish:all": "npm run publish:core && npm run publish:mobile && npm run publish:scene && npm run publish:tags && npm run publish:ui && npm run publish:mono",
|
"publish:all": "npm run publish:core && npm run publish:mobile && npm run publish:scene && npm run publish:tags && npm run publish:ui && npm run publish:mono && npm run publish:base",
|
||||||
"publish:core": "npm publish ./Packages/Core",
|
"publish:core": "npm publish ./Packages/Core",
|
||||||
|
"publish:base": "npm publish ./Packages/BaseAtoms",
|
||||||
"publish:mobile": "npm publish ./Packages/Mobile",
|
"publish:mobile": "npm publish ./Packages/Mobile",
|
||||||
"publish:scene": "npm publish ./Packages/SceneMgmt",
|
"publish:scene": "npm publish ./Packages/SceneMgmt",
|
||||||
"publish:tags": "npm publish ./Packages/Tags",
|
"publish:tags": "npm publish ./Packages/Tags",
|
||||||
|
Loading…
Reference in New Issue
Block a user