This commit is contained in:
Adam Ramberg 2020-03-08 13:24:46 +01:00
parent cb3486ae7f
commit ba583f8995
38 changed files with 368 additions and 26 deletions

View File

@ -94,6 +94,14 @@ namespace UnityAtoms.Editor
new RegenerateItem(valueType: "Collider2DGameObject", baseWritePath: Path.Combine(path, "MonoHooks"), isValueEquatable: true, atomTypesToGenerate: AtomTypes.ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.MonoHooks", subUnityAtomsNamespace: "MonoHooks"),
new RegenerateItem(valueType: "TouchUserInput", baseWritePath: Path.Combine(path, "Mobile"), isValueEquatable: true, atomTypesToGenerate: AtomTypes.ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.Mobile", subUnityAtomsNamespace: "Mobile"),
new RegenerateItem(valueType: "SceneField", baseWritePath: Path.Combine(path, "SceneMgmt"), isValueEquatable: true, atomTypesToGenerate: AtomTypes.ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.SceneMgmt", subUnityAtomsNamespace: "SceneMgmt"),
new RegenerateItem(
valueType: "FSMTransitionData",
baseWritePath: Path.Combine(path, "FSM"),
isValueEquatable: false,
atomTypesToGenerate: new List<AtomType>() { AtomTypes.EVENT, AtomTypes.ACTION, AtomTypes.UNITY_EVENT, AtomTypes.BASE_EVENT_REFERENCE, AtomTypes.EVENT_INSTANCER, AtomTypes.BASE_EVENT_REFERENCE_LISTENER },
typeNamespace: "",
subUnityAtomsNamespace: "FSM"
),
};

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
@ -13,6 +14,12 @@ namespace UnityAtoms
{
public T InspectorRaiseValue { get => _inspectorRaiseValue; }
/// <summary>
/// Retrieve Replay Buffer as a List. This call will allocate memory so use sparsely.
/// </summary>
/// <returns></returns>
public List<T> ReplayBuffer { get => _replayBuffer.ToList(); }
[SerializeField]
private event Action<T> _onEvent;
@ -64,7 +71,7 @@ namespace UnityAtoms
public void Register(Action<T> action)
{
_onEvent += action;
ReplayBuffer(action);
ReplayBufferToSubscriber(action);
}
/// <summary>
@ -83,7 +90,7 @@ namespace UnityAtoms
public void RegisterListener(IAtomListener<T> listener)
{
_onEvent += listener.OnEventRaised;
ReplayBuffer(listener.OnEventRaised);
ReplayBufferToSubscriber(listener.OnEventRaised);
}
/// <summary>
@ -115,7 +122,7 @@ namespace UnityAtoms
}
}
private void ReplayBuffer(Action<T> action)
private void ReplayBufferToSubscriber(Action<T> action)
{
if (_replayBufferSize > 0 && _replayBuffer.Count > 0)
{

View File

@ -38,13 +38,13 @@ namespace UnityAtoms
[SerializeField]
[ReadOnly]
private V _inMemoryCopy;
protected V _inMemoryCopy;
/// <summary>
/// The variable that the in memory copy will be based on when created at runtime.
/// </summary>
[SerializeField]
private V _base = null;
protected V _base = null;
/// <summary>
/// If assigned the in memory copy variable will be added to the collection on Start using the gameObject's instance id as key. The value will also be removed from the collection OnDestroy.
@ -58,6 +58,11 @@ namespace UnityAtoms
[SerializeField]
private L _syncToList = default(L);
/// <summary>
/// Override to add implementation specific setup on `OnEnable`.
/// </summary>
protected virtual void ImplSpecificSetup() { }
private void OnEnable()
{
Assert.IsNotNull(_base);
@ -72,6 +77,8 @@ namespace UnityAtoms
{
_inMemoryCopy.ChangedWithHistory = Instantiate(_base.ChangedWithHistory);
}
ImplSpecificSetup();
}
void Start()

8
Packages/FSM/Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0e6ffe42694484f8289b34d6a6881f20
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b1082284fa256450facf1ca2995aaf83
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4963fa9efc94c45b9b20e7d916000ea6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityAtoms.Editor;
namespace UnityAtoms.FSM.Editor
{
/// <summary>
/// Event property drawer of type `FSMTransitionData`. Inherits from `AtomDrawer&lt;FSMTransitionDataEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomPropertyDrawer(typeof(FSMTransitionDataEvent))]
public class FSMTransitionDataEventDrawer : AtomDrawer<FSMTransitionDataEvent> { }
}
#endif

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 26feab68589f54c8e9e0c78b2344d940
guid: 1f9c3131cf77c4aef8db3c5e5876cd63
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9089395bf394744bdaebe4f393e87501
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e3bde4f74fc4e45b5ad3a1d65fe970f4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.FSM.Editor
{
/// <summary>
/// Event property drawer of type `FSMTransitionData`. Inherits from `AtomEventEditor&lt;FSMTransitionData, FSMTransitionDataEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(FSMTransitionDataEvent))]
public sealed class FSMTransitionDataEventEditor : AtomEventEditor<FSMTransitionData, FSMTransitionDataEvent> { }
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 42a5a06c8c66842f4912d22ee7448038
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
{
"name": "MamboJamboStudios.UnityAtomsFSM.Editor",
"references": [
"MamboJamboStudios.UnityAtomsCore.Editor",
"MamboJamboStudios.UnityAtomsFSM.Runtime",
"MamboJamboStudios.UnityAtomsCore.Runtime",
"MamboJamboStudios.UnityAtomsBaseAtoms.Editor",
"MamboJamboStudios.UnityAtomsBaseAtoms.Runtime"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3c1deed969bef45f090d1de9c5ae3f54
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9c924c734424d41d88bcdff2dc6c9c14
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
namespace UnityAtoms.FSM
{
/// <summary>
/// Action of type `FSMTransitionData`. Inherits from `AtomAction&lt;FSMTransitionData&gt;`.
/// </summary>
[EditorIcon("atom-icon-purple")]
public abstract class FSMTransitionDataAction : AtomAction<FSMTransitionData> { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 138992ec523f04fc19179f1d12e161df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 691a47ae9831344ce823cde932633810, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 38f420ce96c754c18b20bcb0f8041585
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using UnityEngine;
namespace UnityAtoms.FSM
{
/// <summary>
/// Event Reference Listener of type `FSMTransitionData`. Inherits from `AtomEventReferenceListener&lt;FSMTransitionData, FSMTransitionDataAction, FSMTransitionDataEvent, FSMTransitionDataBaseEventReference, FSMTransitionDataUnityEvent&gt;`.
/// </summary>
[EditorIcon("atom-icon-orange")]
[AddComponentMenu("Unity Atoms/Listeners/FSMTransitionData Base Event Reference Listener")]
public sealed class FSMTransitionDataBaseEventReferenceListener : AtomEventReferenceListener<
FSMTransitionData,
FSMTransitionDataAction,
FSMTransitionDataEvent,
FSMTransitionDataBaseEventReference,
FSMTransitionDataUnityEvent>
{ }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c40324269e5944f2e9c6369039c03210
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4aa7b99ae77d84884a0c0c0ce307792f, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7821c9661f5974d4a8619946169a34af
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
namespace UnityAtoms.FSM
{
/// <summary>
/// Event Reference of type `FSMTransitionData`. Inherits from `AtomBaseEventReference&lt;FSMTransitionData, FSMTransitionDataEvent, FSMTransitionDataEventInstancer&gt;`.
/// </summary>
[Serializable]
public sealed class FSMTransitionDataBaseEventReference : AtomBaseEventReference<
FSMTransitionData,
FSMTransitionDataEvent,
FSMTransitionDataEventInstancer>, IGetEvent
{ }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60abd20b777714e5aa587896563c9565
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6468e92d3237a43e4aab2d821a719752
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using UnityEngine;
namespace UnityAtoms.FSM
{
/// <summary>
/// Event Instancer of type `FSMTransitionData`. Inherits from `AtomEventInstancer&lt;FSMTransitionData, FSMTransitionDataEvent&gt;`.
/// </summary>
[EditorIcon("atom-icon-sign-blue")]
[AddComponentMenu("Unity Atoms/Event Instancers/FSMTransitionData Event Instancer")]
public class FSMTransitionDataEventInstancer : AtomEventInstancer<FSMTransitionData, FSMTransitionDataEvent> { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04fb76dace4bf41e78900c62d46f12fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 8c25ac30c7b7d4e3b90bed61d900d244, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a98e9a447044489081db19cb107b8b0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using UnityEngine;
namespace UnityAtoms.FSM
{
/// <summary>
/// Event of type `FSMTransitionData`. Inherits from `AtomEvent&lt;FSMTransitionData&gt;`.
/// </summary>
[EditorIcon("atom-icon-cherry")]
[CreateAssetMenu(menuName = "Unity Atoms/Events/FSMTransitionData", fileName = "FSMTransitionDataEvent")]
public sealed class FSMTransitionDataEvent : AtomEvent<FSMTransitionData> { }
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e55cc627a85344113bc2c10eb8a64dc0
guid: 376a724a7f6d44dbe8bb457e0de8fed6
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,30 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
{
[EditorIcon("atom-icon-hotpink")]
[AddComponentMenu("Unity Atoms/FSM/FSM Instancer")]
public class FSMInstancer : AtomVariableInstancer<
FiniteStateMachine,
StringPair,
string,
StringEvent,
StringPairEvent,
StringStringFunction,
AtomCollection,
AtomList>
{
protected override void ImplSpecificSetup()
{
if (_base.TransitionStarted != null)
{
_inMemoryCopy.TransitionStarted = Instantiate(_base.TransitionStarted);
}
if (_base.CompleteCurrentTransition != null)
{
_inMemoryCopy.CompleteCurrentTransition = Instantiate(_base.CompleteCurrentTransition);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2a4e34526588e4d4c9d51113df626342
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: f4c59e5c7eed94aefa9f60ed1e800dfb, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,7 @@ using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
{
public struct TransitionData
public struct FSMTransitionData
{
public string FromState { get; set; }
public string ToState { get; set; }

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 07d3e6f1bef1b40cf84940723e51ff9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
@ -10,14 +8,15 @@ namespace UnityAtoms.FSM
public class FiniteStateMachine : StringVariable
{
public override string Value { get => _value; set => Dispatch(value); }
public StringReference InitialState { get => _initialState; }
public FSMTransitionDataEvent TransitionStarted { get => _transitionStarted; set => _transitionStarted = value; }
public BoolEvent CompleteCurrentTransition { get => _completeCurrentTransition; set => _completeCurrentTransition = value; }
/// <summary>
/// Gets a boolean value indicating if the state machine is currently transitioning.
/// </summary>
public bool IsTransitioning { get => _currentTransition != null; }
public BoolEvent CompleteCurrentTransition { get => _completeCurrentTransition; }
public bool IsAtEndState
{
get
@ -38,7 +37,7 @@ namespace UnityAtoms.FSM
private StringReference _initialState = default(StringReference);
[SerializeField]
private TransitionEvent _transitionStarted = default(TransitionEvent);
private FSMTransitionDataEvent _transitionStarted = default(FSMTransitionDataEvent);
[SerializeField]
private BoolEvent _completeCurrentTransition = default(BoolEvent);
@ -89,7 +88,7 @@ namespace UnityAtoms.FSM
if (_transitionStarted != null)
{
_transitionStarted.Raise(
new TransitionData()
new FSMTransitionData()
{
FromState = transition.FromState,
ToState = transition.ToState,

View File

@ -1,12 +0,0 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
{
/// <summary>
/// Event of type `TransitionData`. Inherits from `AtomEvent&lt;TransitionData&gt;`.
/// </summary>
[EditorIcon("atom-icon-cherry")]
[CreateAssetMenu(menuName = "Unity Atoms/FSM/Transition Event", fileName = "TransitionEvent")]
public sealed class TransitionEvent : AtomEvent<TransitionData> { }
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d296f8b2b900147ee873d9de00d29e5c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using System;
using UnityEngine.Events;
namespace UnityAtoms.FSM
{
/// <summary>
/// None generic Unity Event of type `FSMTransitionData`. Inherits from `UnityEvent&lt;FSMTransitionData&gt;`.
/// </summary>
[Serializable]
public sealed class FSMTransitionDataUnityEvent : UnityEvent<FSMTransitionData> { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89f60660883a647a2b78206e0188ed81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: