com.fluid.unity-gauges
v1.0.1
Published
A simple utility script for creating gauges to maintain stats such as health, energy, stamina, ect.
Downloads
1,050
Maintainers
Readme
Unity Gauges
A simple utility script for creating gauges to maintain stats such as health, energy, stamina, ect.
- Allows you to set a min, max, and value range
- Helper methods such as
IsEmptyandChargePercentto quickly analyze data - Emits events when the value changes to sync UIs, remove characters, update AI, ect.
- Written with tests and interfaces for TDD
Example Usage
Unity Gauge is a light implementation with no dependencies. The creation is class based and does not require a MonoBehavior.
The below example creates a health bar that could be attached to a character. With the _onChange event you can easily makes health changes modify a connected character.
using CleverCrow.Fluid.Gauges;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class ExampleHealthBar : MonoBehaviour {
private readonly Gauge _health = new Gauge(10);
[SerializeField]
private Slider _healthBar;
[SerializeField]
private UnityEvent _onChange;
private void Start () {
_healthBar.maxValue = _health.ChargeMax;
_healthBar.value = 5;
_healthBar.onValueChanged.AddListener((changeValue) => _onChange.Invoke());
}
public void AddHealth (int health) {
_healthBar.value += health;
}
public void RemoveHealth (int health) {
_healthBar.value -= health;
}
}For a full example please see the Assets/Examples folder.
Installation
Unity Gauges is used through Unity's Package Manager. In order to use it you'll need to add the following lines to your Packages/manifest.json file. After that you'll be able to visually control what specific version of Unity Gauges you're using from the package manager window in Unity. This has to be done so your Unity editor can connect to NPM's package registry.
{
"scopedRegistries": [
{
"name": "NPM",
"url": "https://registry.npmjs.org",
"scopes": [
"com.fluid"
]
}
],
"dependencies": {
"com.fluid.unity-gauges": "1.0.0"
}
}Releases
Archives of specific versions and release notes are available on the releases page.
Nightly Builds
To access nightly builds of the develop branch that are package manager friendly, you'll need to manually edit your Packages/manifest.json as so.
{
"dependencies": {
"com.fluid.unity-gauges": "https://github.com/ashblue/unity-gauges.git#nightly"
}
}Note that to get a newer nightly build you must delete this line and any related lock data in the manifest, let Unity rebuild, then add it back. As Unity locks the commit hash for Git urls as packages.
Development Environment
If you wish to run the development environment you'll need to install the Node.js version in the .nvmrc file. The easiest way to do this is install NVM and run nvm use.
Once you've installed Node.js, run the following from the root once.
npm install
If you wish to create a build run npm run build from the root and it will populate the dist folder.
Making Commits
All commits should be made using Commitizen (which is automatically installed when running npm install). Commits are automatically compiled to version numbers on release so this is very important. PRs that don't have Commitizen based commits will be rejected.
To make a commit type the following into a terminal from the root.
npm run commitHow To Contribute
Please see the CONTRIBUTIONS.md file for full details on how to contribute to this project.
This project was generated with Oyster Package Generator.
