https://github.com/mackysoft/modiferty
Property Modification for Unity
https://github.com/mackysoft/modiferty
c-sharp modification modifier properties unirx unity
Last synced: 3 months ago
JSON representation
Property Modification for Unity
- Host: GitHub
- URL: https://github.com/mackysoft/modiferty
- Owner: mackysoft
- License: mit
- Created: 2020-05-19T07:38:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-03T20:57:24.000Z (about 1 year ago)
- Last Synced: 2025-03-23T20:22:32.180Z (7 months ago)
- Topics: c-sharp, modification, modifier, properties, unirx, unity
- Language: C#
- Homepage: https://mackysoft.github.io/Modiferty/
- Size: 555 KB
- Stars: 24
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Modiferty - Property Modification
**Created by Hiroya Aramaki ([Makihiro](https://twitter.com/makihiro_dev))**
[](https://github.com/mackysoft/Modiferty/actions/workflows/tests.yaml)
[](https://github.com/mackysoft/Modiferty/actions/workflows/build.yaml)
[](https://github.com/mackysoft/Modiferty/releases)
[](https://openupm.com/packages/com.mackysoft.modiferty/)## What is Modiferty ?
Modiferty is a great solution for making modifications to properties.
In games, there are often situations in which the status of characters, weapons, etc. temporarily change.
Modiferty can be used in the following situations.
- Want to modify the in-game character status temporally.
- [Installation](#installation)
- [Usage](#usage)
- [Using ModifierList](#using-modifierlist)
- [Modifier Types](#modifier-types)
- [Set Modifier](#set-modifier)
- [Create Modifier](#create-modifier)
- [External Assets](#external-assets)
- [UniRx](#unirx)
- [Author Info](#author-info)
- [License](#license)Download any version from releases.
Releases: https://github.com/mackysoft/Modiferty/releases
# Usage
Add "MackySoft.Modiferty" namespace into using area.
```cs
using MackySoft.Modiferty;
```The following code implements a temporary increase the character attack power.
```cs
public class Character : MonoBehaviour {public int health = 3;
public ModifiableInt attackPower = new ModifiableInt(baseValue: 1);public void Attack (Character target){
target.health -= attackPower.Evaluate();
}}
public class PowerUpItem : MonoBehaviour {
public AdditiveModifierInt additivePower = new AdditiveModifierInt(1);
public void Modify (Character target){
target.attackPower.Modifiers.Add(additivePower);// Same as below.
// target.attackPower.AddModifier(additivePower);
}}
```If you want to modify the value without using ModifiableProperty, use a ModifierList.
```cs
ModifierList m_DamageModifiers = new ModifierList;// Add something modifiers.
m_DamageModifiers.Add(modifier);// Evaluate the damage.
int evaluatedDamage = m_DamageModifiers.Evaluate(damage);
```ModifiableList is also used in the ModifiableProperty implementation.
Basic operator modifiers are provided.
- Additive Modifier
- Subtractive Modifier
- Multiply Modifier
- Division ModifierA variety of other unique modifiers are also available.
## Set Modifier
The given value ignored and the specified value returned.
```cs
var setModifier = new SetModifierInt(0);character.attackPower.AddModifier(setModifier);
// result is always 0.
int result = character.attackPower.Evaluate();
```The lambda formula allows you to improvise complex modifiers.
```cs
var createModifier = new CreateModifier(value => {
int result;// Do something process...
return result;
});
```Modiferty supports integration with some external assets.
## UniRx
Install UniRx and define `MODIFERTY_UNIRX` to enable integration with UniRx.
UniRx: [https://github.com/neuecc/UniRx](https://github.com/neuecc/UniRx)
The integration with UniRx mainly adds the following APIs to allow you to observe the values of Modiferty.
- `ReactiveModifierList`
- `ReactiveModifiableProperty````cs
using UnityEngine;
using UnityEngine.UI;
using MackySoft.Modiferty;
using UniRx;public class Character : MonoBehaviour {
// Define attackPower as ReactiveModifiableProperty.
public ReactiveModifiableInt attackPower = new ReactiveModifiableInt(baseValue: 1);. . . . .
}
public class CharacterAttackPowerUI : MonoBehaviour {
public Character character;
public Text attackPowerTsxt;void Awake () {
// You can observe changes BaseValue and Modifiers.
character.attackPower.ObserveChanged().Subscribe(property => {// Apply the attackPower change to the text.
attackPowerText.text = property.Evaluate();
});
}
}
```Hiroya Aramaki is a indie game developer in Japan.
- Blog: [https://mackysoft.net/blog](https://mackysoft.net/blog)
- Twitter: [https://twitter.com/makihiro_dev](https://twitter.com/makihiro_dev)# License
This library is under the MIT License.