unity-atoms/Packages/Core/Runtime/Actions/SetVariableValue/SetVariableValue.cs
Adam Ramberg 9b027e2308
Added pre change transformers to Variables + Clamp Int / Float (#93)
* Added pre change transformers to Variable + Clamp Value Function (first pre change transformer implementation)
- Added a list of pre change transformers to AtomVariable
- Added docs
- Added two AtomFunctions - ClampInt and ClampFloat
- Added custom editors for ClampInt and ClampFloat
- AtomFunction<T, T> is not part of the generator
- Regenerated all the Atoms

* - Created a base class for the editor for ClampFloat and ClampInt. Apparently it is not allowed to have multiple CustomEditor attributes defined for the same class. To implement this I also created an interface called `IIsValid` (for casting purposes in the editor).
- Initialize `PreChangeTransformers ` at declaration and removed initialization `OnEnable`
- Moved call to `RunPreChangeTransformers ` from `OnEnable` to `OnValidate`. Running it 2 times, once for initialValue and once for value since value can be changed at runtime via editor.
- Made the variable PreChangeTransformers private and created a property instead in order to make it impossible to overwrite the list with `null` from the outside.
- Moved `ClampInt` and `ClampFloat` in the `CreateAssetMenu` for `Unity Atoms/Functions/Transformers`
2020-02-16 12:44:46 +01:00

45 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
/// <summary>
/// Base class for all SetVariableValue Actions. Inherits from `VoidAction`.
/// </summary>
/// <typeparam name="T">The type of the Variable to set.</typeparam>
/// <typeparam name="V">A Variable class of type `type` to set.</typeparam>
/// <typeparam name="C">A Constant class of type `type` to set.</typeparam>
/// <typeparam name="R">A Reference of type `type`.</typeparam>
/// <typeparam name="E1">An Event of type `type`.</typeparam>
/// <typeparam name="E2">An Event x 2 of type `type`.</typeparam>
/// <typeparam name="F">A Function x 2 of type `type`.</typeparam>
public abstract class SetVariableValue<T, V, C, R, E1, E2, F> : VoidAction
where E1 : AtomEvent<T>
where E2 : AtomEvent<T, T>
where F : AtomFunction<T, T>
where V : AtomVariable<T, E1, E2, F>
where C : AtomBaseVariable<T>
where R : AtomReference<T, V, C>
{
/// <summary>
/// The Variable to set.
/// </summary>
[SerializeField]
private V _variable = null;
/// <summary>
/// The value to set.
/// </summary>
[SerializeField]
private R _value = null;
/// <summary>
/// Perform the action.
/// </summary>
public override void Do()
{
_variable.Value = _value.Value;
}
}
}