mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 16:48:23 -05:00
8a6b8a97a6
AtomVariableInstancer - Added AtomVariableInstancer as an option to AtomReference. - Added AtomVariableInstancer to generator. - Added editor icon for AtomVariableInstancer. AtomEventReference - Added an AtomEventReference class (and AtomEventX2Reference). It’s similar to an AtomReference, but for Events. Let’s you pick between an Event, Variable (will select the Changed event) and a VariableInstancer (see above). - Added AtomEventReference and AtomEventX2Reference to generator. - Added a drawer for AtomEventReference. - Listeners are now using AtomEventReference instead of AtomEvent. - Refactoring of VoidHooks since Listeners are now using AtomEventReference. AtomCollection - Created an AtomCollection - a collection of Atoms associated with key strings (AtomReferences). - Added new editor icon for collections. - Created a SerializableDictionary class, which AtomCollection is using. - Custom property drawer for SerializableDictionary. - SerializableDictionary supports nested structures meaning that a AtomCollection can have a KVP that is pointing to another AtomCollection. - AtomCollections have 3 events: Added, Removed, Cleared. - Added an option to sync an InstanceVariable to collection - adding it to the collection when created (using gameObject’s instance id as key) and removing it from the collection when destroyed. AtomList - Renamed old AtomList to AtomValueList - Added AtomList, like Collection, but a list - Added new icon for AtomList - Created a AtomBaseVariableList class, which AtomList is using. - Custom property drawer for AtomBaseVariableList. - AtomLists have 3 events: Added, Removed, Cleared. - Added an option to sync an InstanceVariable to list - adding it to the list when created and removing it from the list when destroyed.
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UnityAtoms
|
|
{
|
|
/// <summary>
|
|
/// None generic base class for Events. Inherits from `BaseAtom` and `ISerializationCallbackReceiver`.
|
|
/// </summary>
|
|
[EditorIcon("atom-icon-cherry")]
|
|
public abstract class AtomEventBase : BaseAtom, ISerializationCallbackReceiver
|
|
{
|
|
/// <summary>
|
|
/// Event without value.
|
|
/// </summary>
|
|
public event Action OnEventNoValue;
|
|
|
|
protected void RaiseNoValue()
|
|
{
|
|
OnEventNoValue?.Invoke();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register handler to be called when the Event triggers.
|
|
/// </summary>
|
|
/// <param name="del">The handler.</param>
|
|
public void Register(Action del)
|
|
{
|
|
OnEventNoValue += del;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unregister handler that was registered using the `Register` method.
|
|
/// </summary>
|
|
/// <param name="del">The handler.</param>
|
|
public void Unregister(Action del)
|
|
{
|
|
OnEventNoValue -= del;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register a Listener that in turn trigger all its associated handlers when the Event triggers.
|
|
/// </summary>
|
|
/// <param name="listener">The Listener to register.</param>
|
|
public void RegisterListener(IAtomListener listener)
|
|
{
|
|
OnEventNoValue += listener.OnEventRaised;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unregister a listener that was registered using the `RegisterListener` method.
|
|
/// </summary>
|
|
/// <param name="listener">The Listener to unregister.</param>
|
|
public void UnregisterListener(IAtomListener listener)
|
|
{
|
|
OnEventNoValue -= listener.OnEventRaised;
|
|
}
|
|
|
|
public void OnBeforeSerialize() { }
|
|
|
|
public virtual void OnAfterDeserialize()
|
|
{
|
|
// Clear all delegates when exiting play mode
|
|
if (OnEventNoValue != null)
|
|
{
|
|
foreach (var d in OnEventNoValue.GetInvocationList())
|
|
{
|
|
OnEventNoValue -= (Action)d;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |