This commit is contained in:
Adam Ramberg 2020-03-11 21:11:27 +01:00
parent 42d97b840f
commit e4c489c88e
73 changed files with 2148 additions and 1812 deletions

View File

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

View File

@ -0,0 +1,17 @@
using UnityEngine;
public static class Rigidbody2DExtensions
{
public static void Move(this Rigidbody2D body, Vector2 input, float speed, float deltaTime)
{
var direction = input.normalized;
var targetVelocity = direction * speed;
body.velocity = Vector2.Lerp(body.velocity, targetVelocity, 10f * deltaTime);
if (direction.magnitude > 0f)
{
float lookAtTargetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
body.transform.rotation = Quaternion.AngleAxis(lookAtTargetAngle, Vector3.forward);
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 569d7bf500f764f559232bde0a9f5cac
guid: 65ccada6f42ae49518ebdb6b31b679eb
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,45 +0,0 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
using UnityAtoms.Tags;
using UnityAtoms.FSM;
public class EnemyMovement : MonoBehaviour
{
[SerializeField]
private StringReference _tagToTarget;
[SerializeField]
private FloatReference _shotRange = new FloatReference(5f);
[SerializeField]
private FloatReference _moveSpeedMultiplier = new FloatReference(2f);
[SerializeField]
private FiniteStateMachineReference _enemyMovement;
void Awake()
{
var target = AtomTags.FindByTag(_tagToTarget.Value).transform;
var body = GetComponent<Rigidbody2D>();
_enemyMovement.Machine.OnUpdate((deltaTime, value) =>
{
// Calculate velocity
var direction = (target.position - transform.position).normalized;
var targetVelocity = value == "CHASING" ? new Vector2(direction.x, direction.y) * _moveSpeedMultiplier.Value : Vector2.zero;
body.velocity = Vector2.Lerp(body.velocity, targetVelocity, 0.05f);
// Calculate rotation
float lookAtTargetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(lookAtTargetAngle, Vector3.forward);
});
_enemyMovement.Machine.DispatchWhen(command: "ATTACK", (value) => value == "CHASING" && (_shotRange.Value >= Vector3.Distance(target.position, transform.position)));
_enemyMovement.Machine.DispatchWhen(command: "CHASE", (value) => value == "ATTACKING" && (_shotRange.Value < Vector3.Distance(target.position, transform.position)));
}
void Start()
{
_enemyMovement.Machine.Begin();
}
}

View File

@ -1,26 +0,0 @@
using UnityAtoms.BaseAtoms;
using UnityAtoms.FSM;
using UnityEngine;
public class EnemyShooting : MonoBehaviour
{
[SerializeField]
private StringReference _tagToTarget;
[SerializeField]
private FloatReference _shotRange = new FloatReference(5f);
[SerializeField]
private FiniteStateMachineReference _enemyMovement;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -1,245 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1102 &-3281836843204836208
AnimatorState:
serializedVersion: 5
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ATTACKING
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 957046207414541133}
- {fileID: 7720928478735985469}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 0}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1107 &-1645917759095553555
AnimatorStateMachine:
serializedVersion: 5
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 1111875292591114466}
m_Position: {x: 420, y: 60, z: 0}
- serializedVersion: 1
m_State: {fileID: -3281836843204836208}
m_Position: {x: 420, y: 200, z: 0}
m_ChildStateMachines:
- serializedVersion: 1
m_StateMachine: {fileID: 936194623181512215}
m_Position: {x: 708.486, y: 213.59134, z: 0}
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 300, y: -80, z: 0}
m_EntryPosition: {x: 130, y: 110, z: 0}
m_ExitPosition: {x: 760, y: 70, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 1111875292591114466}
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: EnemyTesting
serializedVersion: 5
m_AnimatorParameters:
- m_Name: ASDF
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 1
m_Controller: {fileID: 0}
- m_Name: Speed
m_Type: 3
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
- m_Name: New Trigger
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: -1645917759095553555}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &732751341839492188
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: Speed
m_EventTreshold: 0
- m_ConditionMode: 1
m_ConditionEvent: New Trigger
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1107 &936194623181512215
AnimatorStateMachine:
serializedVersion: 5
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Sub machine
m_ChildStates: []
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 0}
--- !u!1101 &957046207414541133
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 1
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: ASDF
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1111875292591114466}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &1111875292591114466
AnimatorState:
serializedVersion: 5
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: CHASING
m_Speed: 0.1
m_CycleOffset: 0
m_Transitions:
- {fileID: 3657637417717354949}
- {fileID: 732751341839492188}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 0}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1101 &3657637417717354949
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: A
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: ASDF
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -3281836843204836208}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &7720928478735985469
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 936194623181512215}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1

View File

@ -0,0 +1,267 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2421445419809145576
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2421445419809145580}
- component: {fileID: 2421445419809145583}
- component: {fileID: 2421445419809145582}
- component: {fileID: 2421445419809145571}
- component: {fileID: 2421445419809145577}
- component: {fileID: 2421445419809145581}
- component: {fileID: 2421445419809145570}
- component: {fileID: 2421445419809145569}
- component: {fileID: 4909826835678234752}
- component: {fileID: -2978108162882953924}
m_Layer: 0
m_Name: Enemy
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2421445419809145580
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -3.249, y: 1.461, z: 0}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &2421445419809145583
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: bcb9bdff5d4664c74a932c679135aff5, type: 3}
m_Color: {r: 0.28435388, g: 0.37606388, b: 0.8490566, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!61 &2421445419809145582
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!50 &2421445419809145571
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &2421445419809145577
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3570dca9cf8f40ac9731ef4082c9a4ef, type: 3}
m_Name:
m_EditorClassIdentifier:
_tags:
- {fileID: 11400000, guid: 548d717e096e245aa93d91687b22e1f7, type: 2}
--- !u!114 &2421445419809145581
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cf9e86ff89e64f7fb046969f9297b7f, type: 3}
m_Name:
m_EditorClassIdentifier:
_tagToTarget:
_usage: 1
_value:
_constant: {fileID: 11400000, guid: 23f42a77324bd4158a00555f04f7824e, type: 2}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_shootingRange:
_usage: 0
_value: 5
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_moveSpeedMultiplier:
_usage: 0
_value: 2
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_enemyState:
_usage: 1
_machine: {fileID: 0}
_machineInstancer: {fileID: 2421445419809145570}
--- !u!114 &2421445419809145570
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4c23750724dd48beb6147120ab31180, type: 3}
m_Name:
m_EditorClassIdentifier:
_inMemoryCopy: {fileID: 0}
_base: {fileID: 11400000, guid: 574b826f5842e400eb4cb44d63b60077, type: 2}
_syncToCollection: {fileID: 0}
_syncToList: {fileID: 0}
_fsmBase: {fileID: 11400000, guid: 574b826f5842e400eb4cb44d63b60077, type: 2}
--- !u!114 &2421445419809145569
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b6d7e87282ce6479184ce08bf6dbe121, type: 3}
m_Name:
m_EditorClassIdentifier:
_tagToTarget:
_usage: 1
_value:
_constant: {fileID: 11400000, guid: 23f42a77324bd4158a00555f04f7824e, type: 2}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_shootingRange:
_usage: 0
_value: 5
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_enemyState:
_usage: 1
_machine: {fileID: 0}
_machineInstancer: {fileID: 2421445419809145570}
_projectile: {fileID: 2729875676815699808, guid: e06c7b1d6f150401bbea0ac60adf80b1,
type: 3}
--- !u!114 &4909826835678234752
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 521fccafae8ab41e8b91a6aebdf2a1f1, type: 3}
m_Name:
m_EditorClassIdentifier:
_health:
_usage: 3
_value: 0
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: -2978108162882953924}
--- !u!114 &-2978108162882953924
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2421445419809145576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: adacd19b642ba4bd9866612e37971b00, type: 3}
m_Name:
m_EditorClassIdentifier:
_inMemoryCopy: {fileID: 0}
_base: {fileID: 11400000, guid: 16bf069429937474390ce1ed7d17a8bf, type: 2}
_syncToCollection: {fileID: 0}
_syncToList: {fileID: 11400000, guid: a92988507b22a4bad8e15483d6e1695f, type: 2}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1326bc3a5a491414d936c2cbaaf52c53
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cf8a67b68db3d4650908f8cf6adeda60, type: 3}
m_Name: EnemyHealthBase
m_EditorClassIdentifier:
_developerDescription:
_value: 0
_initialValue: 0
_oldValue: 0
Changed: {fileID: 11400000, guid: d481ae3b5fe854cd187b0e79017e8d1e, type: 2}
ChangedWithHistory: {fileID: 0}
_preChangeTransformers: []

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d8870090dbd674420ba589d684f371af
guid: 16bf069429937474390ce1ed7d17a8bf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9fce12a4beec24778830e555cb6e5ca3, type: 3}
m_Name: EnemyHealthChangedBase
m_EditorClassIdentifier:
_developerDescription:
_replayBufferSize: 1
_inspectorRaiseValue: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d481ae3b5fe854cd187b0e79017e8d1e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using UnityEngine;
using UnityAtoms.BaseAtoms;
using UnityAtoms.Tags;
using UnityAtoms.FSM;
public class EnemyMovement : MonoBehaviour
{
[SerializeField]
private StringReference _tagToTarget;
[SerializeField]
private FloatReference _shootingRange = new FloatReference(5f);
[SerializeField]
private FloatReference _moveSpeedMultiplier = new FloatReference(2f);
[SerializeField]
private FiniteStateMachineReference _enemyState;
void Awake()
{
var target = AtomTags.FindByTag(_tagToTarget.Value).transform;
var body = GetComponent<Rigidbody2D>();
_enemyState.Machine.OnUpdate((deltaTime, value) => body.Move((target.position - transform.position), value == "CHASING" ? 2f : 0f, deltaTime), gameObject);
_enemyState.Machine.DispatchWhen(command: "ATTACK", (value) => value == "CHASING" && (_shootingRange.Value >= Vector3.Distance(target.position, transform.position)), gameObject);
_enemyState.Machine.DispatchWhen(command: "CHASE", (value) => value == "ATTACKING" && (_shootingRange.Value < Vector3.Distance(target.position, transform.position)), gameObject);
}
// void Start()
// {
// _enemyState.Machine.Begin();
// }
}

View File

@ -0,0 +1,20 @@
using UnityAtoms.BaseAtoms;
using UnityAtoms.FSM;
using UnityEngine;
public class EnemyShooting : MonoBehaviour
{
[SerializeField]
private FiniteStateMachineReference _enemyState;
[SerializeField]
private GameObject _projectile;
void Awake()
{
_enemyState.Machine.OnStateCooldown("ATTACKING", (value) =>
{
var spawnPos = transform.position + transform.right;
Instantiate(_projectile, spawnPos, transform.rotation);
}, gameObject);
}
}

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 708376110c05a4e20b0ce756930c3bb0, type: 3}
m_Name: EnemyShootingRange
m_EditorClassIdentifier:
_developerDescription:
_value: 5

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8eeed365578d048ff9b2098ce261db1c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,10 +13,10 @@ MonoBehaviour:
m_Name: EnemyStateMachine
m_EditorClassIdentifier:
_developerDescription:
_value: IDLE
_value: CHASING
_initialValue: CHASING
_oldValue: IDLE
Changed: {fileID: 0}
_oldValue: CHASING
Changed: {fileID: 11400000, guid: da1401f0da9c44ed98d933c0f6b86d10, type: 2}
ChangedWithHistory: {fileID: 0}
_preChangeTransformers: []
_transitionStarted: {fileID: 0}
@ -28,7 +28,7 @@ MonoBehaviour:
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_duration:
_cooldown:
_usage: 0
_value: 0
_constant: {fileID: 0}
@ -41,7 +41,7 @@ MonoBehaviour:
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_duration:
_cooldown:
_usage: 0
_value: 2
_constant: {fileID: 0}

View File

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

View File

@ -0,0 +1,71 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a56d454e768904df09296076c1aaea26, type: 3}
m_Name: GameStateMachine
m_EditorClassIdentifier:
_developerDescription:
_value: InGame
_initialValue: InGame
_oldValue: InGame
Changed: {fileID: 11400000, guid: 3979f8535cda044809f98bde2acbadcd, type: 2}
ChangedWithHistory: {fileID: 0}
_preChangeTransformers: []
_transitionStarted: {fileID: 0}
_completeCurrentTransition: {fileID: 0}
_states:
- _id:
_usage: 0
_value: InGame
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_cooldown:
_usage: 0
_value: 0
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_subMachine: {fileID: 0}
- _id:
_usage: 0
_value: GameOver
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_cooldown:
_usage: 0
_value: 0
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_subMachine: {fileID: 0}
_transitions:
- _fromState:
_usage: 0
_value: InGame
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_toState:
_usage: 0
_value: GameOver
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_command:
_usage: 0
_value: SetGameOver
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_testCondition: {fileID: 0}
_raiseEventToCompleteTransition: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 42e941e460d424571aa897b211cee70e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

View File

@ -0,0 +1,347 @@
fileFormatVersion: 2
guid: 7fd1cff2aff054d3f90a2fe5a61c5809
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 3
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 4
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline:
- - {x: 0, y: 2}
- {x: -0.09813535, y: 1.9975909}
- {x: -0.19603428, y: 1.9903694}
- {x: -0.29346094, y: 1.978353}
- {x: -0.39018065, y: 1.9615705}
- {x: -0.4859604, y: 1.9400625}
- {x: -0.5805693, y: 1.9138807}
- {x: -0.67377967, y: 1.8830881}
- {x: -0.76536685, y: 1.8477591}
- {x: -0.8551101, y: 1.8079786}
- {x: -0.9427934, y: 1.7638426}
- {x: -1.0282055, y: 1.7154572}
- {x: -1.1111405, y: 1.6629392}
- {x: -1.1913986, y: 1.606415}
- {x: -1.2687867, y: 1.5460209}
- {x: -1.343118, y: 1.4819021}
- {x: -1.4142137, y: 1.4142134}
- {x: -1.4819024, y: 1.3431177}
- {x: -1.5460211, y: 1.2687864}
- {x: -1.6064153, y: 1.1913984}
- {x: -1.6629394, y: 1.1111403}
- {x: -1.7154574, y: 1.0282052}
- {x: -1.7638427, y: 0.94279313}
- {x: -1.8079787, y: 0.8551098}
- {x: -1.8477592, y: 0.76536644}
- {x: -1.8830884, y: 0.6737792}
- {x: -1.9138808, y: 0.5805688}
- {x: -1.9400626, y: 0.48595977}
- {x: -1.9615707, y: 0.39018002}
- {x: -1.9783531, y: 0.29346028}
- {x: -1.9903696, y: 0.19603357}
- {x: -1.9975909, y: 0.098134585}
- {x: -2, y: -0.0000008026785}
- {x: -1.9975909, y: -0.09813619}
- {x: -1.9903693, y: -0.19603516}
- {x: -1.9783529, y: -0.29346186}
- {x: -1.9615704, y: -0.3901816}
- {x: -1.9400623, y: -0.48596132}
- {x: -1.9138803, y: -0.58057034}
- {x: -1.8830878, y: -0.67378074}
- {x: -1.8477587, y: -0.7653679}
- {x: -1.8079782, y: -0.855111}
- {x: -1.7638422, y: -0.9427941}
- {x: -1.715457, y: -1.028206}
- {x: -1.6629391, y: -1.1111407}
- {x: -1.606415, y: -1.1913987}
- {x: -1.546021, y: -1.2687865}
- {x: -1.4819025, y: -1.3431177}
- {x: -1.4142139, y: -1.4142132}
- {x: -1.3431184, y: -1.4819018}
- {x: -1.2687873, y: -1.5460204}
- {x: -1.1913995, y: -1.6064144}
- {x: -1.1111416, y: -1.6629385}
- {x: -1.0282067, y: -1.7154565}
- {x: -0.9427949, y: -1.7638417}
- {x: -0.85511184, y: -1.8079778}
- {x: -0.76536876, y: -1.8477583}
- {x: -0.6737818, y: -1.8830874}
- {x: -0.5805717, y: -1.91388}
- {x: -0.48596293, y: -1.9400618}
- {x: -0.39018345, y: -1.96157}
- {x: -0.29346398, y: -1.9783525}
- {x: -0.1960375, y: -1.9903691}
- {x: -0.09813879, y: -1.9975908}
- {x: -0.0000036398517, y: -2}
- {x: 0.098131515, y: -1.9975911}
- {x: 0.19603026, y: -1.9903698}
- {x: 0.29345676, y: -1.9783536}
- {x: 0.3901763, y: -1.9615715}
- {x: 0.48595586, y: -1.9400636}
- {x: 0.58056474, y: -1.913882}
- {x: 0.67377496, y: -1.8830898}
- {x: 0.765362, y: -1.847761}
- {x: 0.8551053, y: -1.8079809}
- {x: 0.94278854, y: -1.7638452}
- {x: 1.0282005, y: -1.7154602}
- {x: 1.1111355, y: -1.6629425}
- {x: 1.1913936, y: -1.6064187}
- {x: 1.2687817, y: -1.546025}
- {x: 1.3431131, y: -1.4819067}
- {x: 1.4142088, y: -1.4142184}
- {x: 1.4818976, y: -1.3431231}
- {x: 1.5460167, y: -1.2687918}
- {x: 1.6064112, y: -1.1914037}
- {x: 1.6629357, y: -1.1111456}
- {x: 1.7154542, y: -1.0282105}
- {x: 1.7638398, y: -0.94279844}
- {x: 1.8079762, y: -0.855115}
- {x: 1.8477571, y: -0.76537156}
- {x: 1.8830866, y: -0.6737842}
- {x: 1.9138794, y: -0.5805737}
- {x: 1.9400615, y: -0.48596448}
- {x: 1.9615698, y: -0.39018452}
- {x: 1.9783524, y: -0.29346457}
- {x: 1.9903691, y: -0.19603767}
- {x: 1.9975908, y: -0.09813846}
- {x: 2, y: -0.0000028371733}
- {x: 1.997591, y: 0.0981328}
- {x: 1.9903697, y: 0.19603202}
- {x: 1.9783533, y: 0.29345897}
- {x: 1.9615709, y: 0.39017895}
- {x: 1.9400629, y: 0.48595896}
- {x: 1.9138811, y: 0.58056825}
- {x: 1.8830885, y: 0.6737789}
- {x: 1.8477592, y: 0.7653663}
- {x: 1.8079787, y: 0.8551099}
- {x: 1.7638426, y: 0.9427934}
- {x: 1.7154571, y: 1.0282056}
- {x: 1.662939, y: 1.1111408}
- {x: 1.6064146, y: 1.1913992}
- {x: 1.5460203, y: 1.2687874}
- {x: 1.4819014, y: 1.3431189}
- {x: 1.4142125, y: 1.4142147}
- {x: 1.3431165, y: 1.4819036}
- {x: 1.2687849, y: 1.5460223}
- {x: 1.1913966, y: 1.6064166}
- {x: 1.1111382, y: 1.6629407}
- {x: 1.0282029, y: 1.7154588}
- {x: 0.94279057, y: 1.7638441}
- {x: 0.85510695, y: 1.8079801}
- {x: 0.76536334, y: 1.8477606}
- {x: 0.67377585, y: 1.8830895}
- {x: 0.58056515, y: 1.9138819}
- {x: 0.48595583, y: 1.9400636}
- {x: 0.3901758, y: 1.9615716}
- {x: 0.29345578, y: 1.9783537}
- {x: 0.1960288, y: 1.99037}
- {x: 0.09812956, y: 1.9975911}
physicsShape:
- - {x: 0, y: 2}
- {x: -0.09813535, y: 1.9975909}
- {x: -0.19603428, y: 1.9903694}
- {x: -0.29346094, y: 1.978353}
- {x: -0.39018065, y: 1.9615705}
- {x: -0.4859604, y: 1.9400625}
- {x: -0.5805693, y: 1.9138807}
- {x: -0.67377967, y: 1.8830881}
- {x: -0.76536685, y: 1.8477591}
- {x: -0.8551101, y: 1.8079786}
- {x: -0.9427934, y: 1.7638426}
- {x: -1.0282055, y: 1.7154572}
- {x: -1.1111405, y: 1.6629392}
- {x: -1.1913986, y: 1.606415}
- {x: -1.2687867, y: 1.5460209}
- {x: -1.343118, y: 1.4819021}
- {x: -1.4142137, y: 1.4142134}
- {x: -1.4819024, y: 1.3431177}
- {x: -1.5460211, y: 1.2687864}
- {x: -1.6064153, y: 1.1913984}
- {x: -1.6629394, y: 1.1111403}
- {x: -1.7154574, y: 1.0282052}
- {x: -1.7638427, y: 0.94279313}
- {x: -1.8079787, y: 0.8551098}
- {x: -1.8477592, y: 0.76536644}
- {x: -1.8830884, y: 0.6737792}
- {x: -1.9138808, y: 0.5805688}
- {x: -1.9400626, y: 0.48595977}
- {x: -1.9615707, y: 0.39018002}
- {x: -1.9783531, y: 0.29346028}
- {x: -1.9903696, y: 0.19603357}
- {x: -1.9975909, y: 0.098134585}
- {x: -2, y: -0.0000008026785}
- {x: -1.9975909, y: -0.09813619}
- {x: -1.9903693, y: -0.19603516}
- {x: -1.9783529, y: -0.29346186}
- {x: -1.9615704, y: -0.3901816}
- {x: -1.9400623, y: -0.48596132}
- {x: -1.9138803, y: -0.58057034}
- {x: -1.8830878, y: -0.67378074}
- {x: -1.8477587, y: -0.7653679}
- {x: -1.8079782, y: -0.855111}
- {x: -1.7638422, y: -0.9427941}
- {x: -1.715457, y: -1.028206}
- {x: -1.6629391, y: -1.1111407}
- {x: -1.606415, y: -1.1913987}
- {x: -1.546021, y: -1.2687865}
- {x: -1.4819025, y: -1.3431177}
- {x: -1.4142139, y: -1.4142132}
- {x: -1.3431184, y: -1.4819018}
- {x: -1.2687873, y: -1.5460204}
- {x: -1.1913995, y: -1.6064144}
- {x: -1.1111416, y: -1.6629385}
- {x: -1.0282067, y: -1.7154565}
- {x: -0.9427949, y: -1.7638417}
- {x: -0.85511184, y: -1.8079778}
- {x: -0.76536876, y: -1.8477583}
- {x: -0.6737818, y: -1.8830874}
- {x: -0.5805717, y: -1.91388}
- {x: -0.48596293, y: -1.9400618}
- {x: -0.39018345, y: -1.96157}
- {x: -0.29346398, y: -1.9783525}
- {x: -0.1960375, y: -1.9903691}
- {x: -0.09813879, y: -1.9975908}
- {x: -0.0000036398517, y: -2}
- {x: 0.098131515, y: -1.9975911}
- {x: 0.19603026, y: -1.9903698}
- {x: 0.29345676, y: -1.9783536}
- {x: 0.3901763, y: -1.9615715}
- {x: 0.48595586, y: -1.9400636}
- {x: 0.58056474, y: -1.913882}
- {x: 0.67377496, y: -1.8830898}
- {x: 0.765362, y: -1.847761}
- {x: 0.8551053, y: -1.8079809}
- {x: 0.94278854, y: -1.7638452}
- {x: 1.0282005, y: -1.7154602}
- {x: 1.1111355, y: -1.6629425}
- {x: 1.1913936, y: -1.6064187}
- {x: 1.2687817, y: -1.546025}
- {x: 1.3431131, y: -1.4819067}
- {x: 1.4142088, y: -1.4142184}
- {x: 1.4818976, y: -1.3431231}
- {x: 1.5460167, y: -1.2687918}
- {x: 1.6064112, y: -1.1914037}
- {x: 1.6629357, y: -1.1111456}
- {x: 1.7154542, y: -1.0282105}
- {x: 1.7638398, y: -0.94279844}
- {x: 1.8079762, y: -0.855115}
- {x: 1.8477571, y: -0.76537156}
- {x: 1.8830866, y: -0.6737842}
- {x: 1.9138794, y: -0.5805737}
- {x: 1.9400615, y: -0.48596448}
- {x: 1.9615698, y: -0.39018452}
- {x: 1.9783524, y: -0.29346457}
- {x: 1.9903691, y: -0.19603767}
- {x: 1.9975908, y: -0.09813846}
- {x: 2, y: -0.0000028371733}
- {x: 1.997591, y: 0.0981328}
- {x: 1.9903697, y: 0.19603202}
- {x: 1.9783533, y: 0.29345897}
- {x: 1.9615709, y: 0.39017895}
- {x: 1.9400629, y: 0.48595896}
- {x: 1.9138811, y: 0.58056825}
- {x: 1.8830885, y: 0.6737789}
- {x: 1.8477592, y: 0.7653663}
- {x: 1.8079787, y: 0.8551099}
- {x: 1.7638426, y: 0.9427934}
- {x: 1.7154571, y: 1.0282056}
- {x: 1.662939, y: 1.1111408}
- {x: 1.6064146, y: 1.1913992}
- {x: 1.5460203, y: 1.2687874}
- {x: 1.4819014, y: 1.3431189}
- {x: 1.4142125, y: 1.4142147}
- {x: 1.3431165, y: 1.4819036}
- {x: 1.2687849, y: 1.5460223}
- {x: 1.1913966, y: 1.6064166}
- {x: 1.1111382, y: 1.6629407}
- {x: 1.0282029, y: 1.7154588}
- {x: 0.94279057, y: 1.7638441}
- {x: 0.85510695, y: 1.8079801}
- {x: 0.76536334, y: 1.8477606}
- {x: 0.67377585, y: 1.8830895}
- {x: 0.58056515, y: 1.9138819}
- {x: 0.48595583, y: 1.9400636}
- {x: 0.3901758, y: 1.9615716}
- {x: 0.29345578, y: 1.9783537}
- {x: 0.1960288, y: 1.99037}
- {x: 0.09812956, y: 1.9975911}
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
using UnityAtoms.FSM;
using UnityEngine;
public class KillPlayer : MonoBehaviour
{
[SerializeField]
private FiniteStateMachineReference _gameStateRef;
void Awake()
{
// _gameStateRef.Machine.
}
}

View File

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

View File

@ -0,0 +1,48 @@
using UnityAtoms.BaseAtoms;
using UnityEngine;
public class PlayerShooting : MonoBehaviour
{
[SerializeField]
private GameObject _projectile;
[SerializeField]
private StringConstant _playerTag;
void Update()
{
var shootDirection = Vector3.zero;
var rot = Quaternion.identity;
if (Input.GetKeyDown(KeyCode.UpArrow))
{
shootDirection = Vector3.up;
rot = Quaternion.Euler(0f, 0f, 90f);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
shootDirection = Vector3.down;
rot = Quaternion.Euler(0f, 0f, -90f);
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
shootDirection = Vector3.right;
rot = Quaternion.Euler(0f, 0f, 0f);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
shootDirection = Vector3.left;
rot = Quaternion.Euler(0f, 0f, 180f);
}
if (shootDirection != Vector3.zero)
{
var spawnPos = transform.position + shootDirection * 0.6f;
var projectile = Instantiate(_projectile, spawnPos, rot);
projectile.GetComponent<DecreaseHealth>().TagsAffected.Remove(_playerTag); // Turn off friendly fire
}
}
}

View File

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

View File

@ -8,6 +8,8 @@ using UnityAtoms.Tags;
public class DecreaseHealth : MonoBehaviour
{
public List<StringConstant> TagsAffected { get => _tags; }
[SerializeField]
private IntReference _decreaseBy;

View File

@ -5,12 +5,15 @@ using UnityAtoms.BaseAtoms;
public class DestroyMe : MonoBehaviour
{
[SerializeField]
FloatReference _delay;
FloatReference _delay = new FloatReference(-1f);
void Start()
{
Assert.IsNotNull(_delay);
Destroy(gameObject, _delay.Value);
if (_delay.Value >= 0f)
{
Destroy(gameObject, _delay.Value);
}
}
public void DestroyImmediate()

View File

@ -11,9 +11,6 @@ public class MoveInDirection : MonoBehaviour
[SerializeField]
private FloatReference _speed;
[SerializeField]
private Vector2Reference _direction;
private Rigidbody2D rb;
void Start()
@ -24,6 +21,6 @@ public class MoveInDirection : MonoBehaviour
void Update()
{
rb.velocity = _direction.Value.normalized * _speed.Value;
rb.velocity = transform.right * _speed.Value;
}
}

View File

@ -118,7 +118,7 @@ SpriteRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: e73905c499d7b4660a64b7a956ebd018, type: 3}
m_Color: {r: 0.9339623, g: 0.53306335, b: 0.8997125, a: 1}
m_Color: {r: 0.9824066, g: 1, b: 0.8915094, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
@ -156,7 +156,6 @@ MonoBehaviour:
m_BoolArgument: 0
m_CallState: 2
_actionResponses: []
_actionResponsesNoValue: []
_eventReference:
_usage: 1
_event: {fileID: 0}
@ -189,7 +188,6 @@ MonoBehaviour:
m_BoolArgument: 0
m_CallState: 2
_actionResponses: []
_actionResponsesNoValue: []
_eventReference:
_usage: 1
_event: {fileID: 0}
@ -309,13 +307,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
_speed:
_usage: 0
_value: 4
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}
_direction:
_usage: 0
_value: {x: 1, y: 0}
_value: 5
_constant: {fileID: 0}
_variable: {fileID: 0}
_variableInstancer: {fileID: 0}

View File

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

View File

@ -0,0 +1,10 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class RestartCurrentScene : MonoBehaviour
{
public void Do()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}

View File

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

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 04d35e2eb934747da9d77a3af62bb8ca, type: 3}
m_Name: TryAgainButtonClicked
m_EditorClassIdentifier:
_developerDescription: Raised when the player clicks the try again button in the
game over screen.
_replayBufferSize: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b512e6d2a87f440c5883fe3546438a16
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 75feba4dec8d44f0fb83f34e749e4dc3, type: 3}
m_Name: UIStateChanged
m_EditorClassIdentifier:
_developerDescription: Raised when UI state is changed.
_replayBufferSize: 1
_inspectorRaiseValue:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3979f8535cda044809f98bde2acbadcd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,11 +12,8 @@ namespace UnityAtoms.Examples
{
_horizontal = Input.GetAxis("Horizontal");
_vertical = Input.GetAxis("Vertical");
}
private void FixedUpdate()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(_horizontal, _vertical) * 5f;
GetComponent<Rigidbody2D>().Move(new Vector2(_horizontal, _vertical), 5f, Time.deltaTime);
}
}
}
}

View File

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

View File

@ -1,295 +1,295 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!13 &1
InputManager:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton: a
altPositiveButton: d
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
altNegativeButton: s
altPositiveButton: w
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton: mouse 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton: mouse 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left shift
altNegativeButton:
altPositiveButton: mouse 2
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: space
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse X
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse Y
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Mouse ScrollWheel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 2
joyNum: 0
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 0
type: 2
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 1
type: 2
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 0
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 1
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 2
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 3
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: return
altNegativeButton:
altPositiveButton: joystick button 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: enter
altNegativeButton:
altPositiveButton: space
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Cancel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: escape
altNegativeButton:
altPositiveButton: joystick button 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!13 &1
InputManager:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: a
positiveButton: d
altNegativeButton:
altPositiveButton:
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: s
positiveButton: w
altNegativeButton:
altPositiveButton:
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton: mouse 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton: mouse 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left shift
altNegativeButton:
altPositiveButton: mouse 2
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: space
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse X
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse Y
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Mouse ScrollWheel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 2
joyNum: 0
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 0
type: 2
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 1
type: 2
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 0
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 1
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 2
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 3
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: return
altNegativeButton:
altPositiveButton: joystick button 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: enter
altNegativeButton:
altPositiveButton: space
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Cancel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: escape
altNegativeButton:
altPositiveButton: joystick button 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0

View File

@ -71,6 +71,7 @@ namespace UnityAtoms
{
var action = _actionResponses[i];
var actionWithParam = action as AtomAction<T>;
if (actionWithParam != null)
{
actionWithParam.Do(item);

View File

@ -36,9 +36,11 @@ namespace UnityAtoms
/// </summary>
public T Value { get => _inMemoryCopy.Value; set => _inMemoryCopy.Value = value; }
public virtual V Base { get => _base; }
[SerializeField]
[ReadOnly]
protected V _inMemoryCopy;
protected V _inMemoryCopy = default(V);
/// <summary>
/// The variable that the in memory copy will be based on when created at runtime.
@ -65,17 +67,17 @@ namespace UnityAtoms
private void OnEnable()
{
Assert.IsNotNull(_base);
_inMemoryCopy = Instantiate(_base);
Assert.IsNotNull(Base);
_inMemoryCopy = Instantiate(Base);
if (_base.Changed != null)
if (Base.Changed != null)
{
_inMemoryCopy.Changed = Instantiate(_base.Changed);
_inMemoryCopy.Changed = Instantiate(Base.Changed);
}
if (_base.ChangedWithHistory != null)
if (Base.ChangedWithHistory != null)
{
_inMemoryCopy.ChangedWithHistory = Instantiate(_base.ChangedWithHistory);
_inMemoryCopy.ChangedWithHistory = Instantiate(Base.ChangedWithHistory);
}
ImplSpecificSetup();

View File

@ -100,7 +100,7 @@ namespace UnityAtoms
/// Reset the Variable to its `_initalValue`.
/// </summary>
/// <param name="shouldTriggerEvents">Set to `true` if Events should be triggered on reset, otherwise `false`.</param>
public override sealed void Reset(bool shouldTriggerEvents = false)
public override void Reset(bool shouldTriggerEvents = false)
{
if (!shouldTriggerEvents)
{

View File

@ -0,0 +1,30 @@
using UnityEditor;
using UnityAtoms.Editor;
namespace UnityAtoms.FSM.Editor
{
/// <summary>
/// A custom property drawer for References. Makes it possible to choose between a value, Variable, Constant or a Variable Instancer.
/// </summary>
[CustomPropertyDrawer(typeof(FSMTransitionDataBaseEventReference), true)]
public class FSMTransitionDataBaseEventReferenceDrawer : AtomEventReferenceDrawer
{
protected class UsageFSM : UsageData
{
public override int Value { get => FSMTransitionDataBaseEventReferenceUsage.FSM; }
public override string PropertyName { get => "_fsm"; }
public override string DisplayName { get => "Use FSM"; }
}
protected class UsageFSMInstancer : UsageData
{
public override int Value { get => FSMTransitionDataBaseEventReferenceUsage.FSM_INSTANCER; }
public override string PropertyName { get => "_fsmInstancer"; }
public override string DisplayName { get => "Use FSM Instancer"; }
}
private readonly UsageData[] _usages = new UsageData[4] { new UsageEvent(), new UsageEventInstancer(), new UsageFSM(), new UsageFSMInstancer() };
protected override UsageData[] GetUsages(SerializedProperty prop = null) => _usages;
}
}

View File

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

View File

@ -4,26 +4,26 @@ using UnityAtoms.Editor;
namespace UnityAtoms.FSM.Editor
{
/// <summary>
/// A custom property drawer for References. Makes it possible to choose between a value, Variable, Constant or a Variable Instancer.
/// A custom property drawer for FiniteStateMachineReference. Makes it possible to choose between a FSM or a FSM Instancer.
/// </summary>
[CustomPropertyDrawer(typeof(FiniteStateMachineReference), true)]
public class FiniteStateMachineReferenceDrawer : AtomBaseReferenceDrawer
{
protected class UsageMachine : UsageData
protected class UsageFSM : UsageData
{
public override int Value { get => FiniteStateMachineReferenceUsage.MACHINE; }
public override string PropertyName { get => "_machine"; }
public override string DisplayName { get => "Use Machine"; }
public override int Value { get => FiniteStateMachineReferenceUsage.FSM; }
public override string PropertyName { get => "_fsm"; }
public override string DisplayName { get => "Use FSM"; }
}
protected class UsageMachineInstancer : UsageData
protected class UsageFSMInstancer : UsageData
{
public override int Value { get => FiniteStateMachineReferenceUsage.MACHINE_INSTANCER; }
public override string PropertyName { get => "_machineInstancer"; }
public override string DisplayName { get => "Use Machine Instancer"; }
public override int Value { get => FiniteStateMachineReferenceUsage.FSM_INSTANCER; }
public override string PropertyName { get => "_fsmInstancer"; }
public override string DisplayName { get => "Use FSM Instancer"; }
}
private readonly UsageData[] _usages = new UsageData[2] { new UsageMachine(), new UsageMachineInstancer() };
private readonly UsageData[] _usages = new UsageData[2] { new UsageFSM(), new UsageFSMInstancer() };
protected override UsageData[] GetUsages(SerializedProperty prop = null) => _usages;
}

View File

@ -1,7 +1,14 @@
using UnityEngine;
using System;
namespace UnityAtoms.FSM
{
public class FSMTransitionDataBaseEventReferenceUsage
{
public const int FSM = 2;
public const int FSM_INSTANCER = 3;
}
/// <summary>
/// Event Reference of type `FSMTransitionData`. Inherits from `AtomBaseEventReference&lt;FSMTransitionData, FSMTransitionDataEvent, FSMTransitionDataEventInstancer&gt;`.
/// </summary>
@ -10,5 +17,50 @@ namespace UnityAtoms.FSM
FSMTransitionData,
FSMTransitionDataEvent,
FSMTransitionDataEventInstancer>, IGetEvent
{ }
{
/// <summary>
/// Get the value for the Reference.
/// </summary>
/// <value>The value of type `FiniteStateMachine`.</value>
public override FSMTransitionDataEvent Event
{
get
{
switch (_usage)
{
case (FSMTransitionDataBaseEventReferenceUsage.FSM_INSTANCER): return ((FiniteStateMachine)_fsmInstancer.Variable).TransitionStarted;
case (FSMTransitionDataBaseEventReferenceUsage.FSM): return _fsm.TransitionStarted;
default:
return base.Event;
}
}
set
{
switch (_usage)
{
case (FSMTransitionDataBaseEventReferenceUsage.FSM_INSTANCER):
((FiniteStateMachine)_fsmInstancer.Variable).TransitionStarted = value;
break;
case (FSMTransitionDataBaseEventReferenceUsage.FSM):
_fsm.TransitionStarted = value;
break;
default:
base.Event = value;
break;
}
}
}
/// <summary>
/// Takes event from this FiniteStateMachine if `Usage` is set to `FSM`.
/// </summary>
[SerializeField]
private FiniteStateMachine _fsm = default(FiniteStateMachine);
/// <summary>
/// Takes event from this FiniteStateMachineInstancer if `Usage` is set to `FSM Instancer`.
/// </summary>
[SerializeField]
private FiniteStateMachineInstancer _fsmInstancer = default(FiniteStateMachineInstancer);
}
}

View File

@ -5,20 +5,20 @@ using UnityAtoms.BaseAtoms;
namespace UnityAtoms.FSM
{
[Serializable]
public struct FSMState
public class FSMState
{
public string Id { get => _id.Value; }
public FiniteStateMachine SubMachine { get => _subMachine; }
public float Timer { get; set; }
public float Duration { get => _duration.Value; }
public float Cooldown { get => _cooldown.Value; }
[SerializeField]
private StringReference _id;
private StringReference _id = default(StringReference);
[SerializeField]
private FloatReference _duration;
private FloatReference _cooldown = new FloatReference(0f);
[SerializeField]
private FiniteStateMachine _subMachine;
private FiniteStateMachine _subMachine = default(FiniteStateMachine);
}
}

View File

@ -9,6 +9,10 @@ namespace UnityAtoms.FSM
[CreateAssetMenu(menuName = "Unity Atoms/FSM/Finite State Machine", fileName = "FiniteStateMachine")]
public class FiniteStateMachine : StringVariable
{
/// <summary>
/// Get or set current value of this FSM. If a sub FSM is having the current state, then its state will be returned. Using the setter is the same thing as calling `Dispatch`.
/// </summary>
/// <value>The command to issue.</value>
public override string Value
{
get
@ -20,7 +24,7 @@ namespace UnityAtoms.FSM
}
public FSMTransitionDataEvent TransitionStarted { get => _transitionStarted; set => _transitionStarted = value; }
public BoolEvent CompleteCurrentTransition { get => _completeCurrentTransition; set => _completeCurrentTransition = value; }
public override string InitialValue { get => _states.Count > 0 ? _states[0].Id : ""; }
public override string InitialValue { get => _states != null && _states.Count > 0 ? _states[0].Id : ""; }
/// <summary>
/// Gets a boolean value indicating if the state machine is currently transitioning.
@ -43,54 +47,136 @@ namespace UnityAtoms.FSM
private bool _isUpdatingState = false;
private Transition _currentTransition = null;
private bool _resetOnNextTransitionCompleted = false;
private bool _triggerEventsOnNextReset = false;
private event Action<float, string> _onUpdate;
private event Action<float, string> _onFixedUpdate;
private event Action<string> _dispatchWhen;
private event Action<string> _onStateCooldown;
/// <summary>
/// The value in this state machine, disregarding a "deeper" values in a sub machine.
/// </summary>
private string _currentFlatValue;
private void Awake()
{
FiniteStateMachineMonoHook.GetInstance(createIfNotExist: true).OnUpdate -= OnUpdate;
FiniteStateMachineMonoHook.GetInstance().OnUpdate += OnUpdate;
FiniteStateMachineMonoHook.GetInstance().OnStart -= OnStart;
FiniteStateMachineMonoHook.GetInstance().OnStart += OnStart;
}
private void OnDisable()
{
if (FiniteStateMachineUpdateHook.GetInstance() != null)
if (FiniteStateMachineMonoHook.GetInstance() != null)
{
FiniteStateMachineUpdateHook.GetInstance().OnUpdate -= UpdateTick;
FiniteStateMachineMonoHook.GetInstance().OnUpdate -= OnUpdate;
FiniteStateMachineMonoHook.GetInstance().OnStart -= OnStart;
}
_onUpdate = null;
_onFixedUpdate = null;
_dispatchWhen = null;
_onStateCooldown = null;
}
public void OnUpdate(Action<float, string> handler)
public void OnUpdate(Action<float, string> handler, GameObject gameObject)
{
_onUpdate += handler;
}
public void DispatchWhen(string command, Func<string, bool> func)
{
_dispatchWhen += (value) =>
Action<float, string> extendedHandler = null;
extendedHandler = (deltaTime, state) =>
{
// Unregister created handler if original handler doesn't or if the GameObject has been destroyed
if (handler == null || gameObject == null || !gameObject.scene.IsValid())
{
_onUpdate -= extendedHandler;
return;
}
handler(deltaTime, state);
};
_onUpdate += extendedHandler;
}
public void OnFixedUpdate(Action<float, string> handler, GameObject gameObject)
{
Action<float, string> extendedHandler = null;
extendedHandler = (deltaTime, state) =>
{
// Unregister created handler if original handler doesn't or if the GameObject has been destroyed
if (handler == null || gameObject == null || !gameObject.scene.IsValid())
{
_onFixedUpdate -= extendedHandler;
return;
}
handler(deltaTime, state);
};
_onFixedUpdate += extendedHandler;
}
public void DispatchWhen(string command, Func<string, bool> func, GameObject gameObject)
{
Action<string> extendedHandler = null;
extendedHandler = (value) =>
{
// Unregister created handler if original handler doesn't or if the GameObject has been destroyed
if (func == null || gameObject == null || !gameObject.scene.IsValid())
{
_dispatchWhen -= extendedHandler;
return;
}
if (func(value))
{
Dispatch(command);
}
};
_dispatchWhen += extendedHandler;
}
public void Begin()
public void OnStateCooldown(string state, Action<string> handler, GameObject gameObject)
{
FiniteStateMachineUpdateHook.GetInstance(createIfNotExist: true).OnUpdate -= UpdateTick;
FiniteStateMachineUpdateHook.GetInstance().OnUpdate += UpdateTick;
Action<string> extendedHandler = null;
extendedHandler = (value) =>
{
// Unregister created handler if original handler doesn't or if the GameObject has been destroyed
if (handler == null || gameObject == null || !gameObject.scene.IsValid())
{
_onStateCooldown -= extendedHandler;
return;
}
if (value == state)
{
handler(value);
}
};
_onStateCooldown += extendedHandler;
}
public override void Reset(bool shouldTriggerEvents = false)
{
// TODO: Validate transitions and states
// Set all timers to the same as the cooldown
for (var i = 0; i < _states.Count; ++i)
{
_states[i].Timer = _states[i].Cooldown;
}
if (!_resetOnNextTransitionCompleted && !IsTransitioning)
{
_resetOnNextTransitionCompleted = false;
ResetAllSubMachines();
base.Reset(false);
base.Reset(shouldTriggerEvents);
_currentFlatValue = _value;
}
else
{
_triggerEventsOnNextReset = shouldTriggerEvents;
_resetOnNextTransitionCompleted = true;
}
}
@ -130,11 +216,12 @@ namespace UnityAtoms.FSM
}
);
}
transition.Begin(this);
transition.Begin(this, EndCurrentTransition);
}
}
else
{
// State doesn't exist in this FSM, propagate down to all sub FSMs.
var state = GetState(_currentFlatValue);
if (state.SubMachine != null)
{
@ -143,14 +230,14 @@ namespace UnityAtoms.FSM
}
}
protected override bool ValueEquals(string other) => false;
protected override bool ValueEquals(string other) => false; // Always trigger events even if changing to the same state as previous
public void EndCurrentTransition()
private void EndCurrentTransition()
{
if (_resetOnNextTransitionCompleted)
{
_resetOnNextTransitionCompleted = false;
Begin();
Reset(_triggerEventsOnNextReset);
return;
}
@ -160,7 +247,7 @@ namespace UnityAtoms.FSM
if (toState.SubMachine != null)
{
// Reset sub machines in to state
toState.SubMachine.Begin();
toState.SubMachine.Reset();
base.Value = toState.SubMachine.Value;
}
else
@ -173,57 +260,72 @@ namespace UnityAtoms.FSM
_isUpdatingState = false;
}
public void ResetAllSubMachines()
private void ResetAllSubMachines()
{
for (var i = 0; i < _states.Count; ++i)
{
if (_states[i].SubMachine != null)
{
_states[i].SubMachine.Begin();
_states[i].SubMachine.Reset();
}
}
}
private void UpdateTick(float deltaTime)
private void OnStart()
{
// Update timers
Reset();
}
private void OnUpdate(float deltaTime)
{
// Update timers and call OnStateCooldown handlers if applicable
var currentValue = Value;
for (var i = 0; i < _states.Count; ++i)
{
var state = _states[i];
if (state.Duration > 0f)
if (state.Cooldown > 0f)
{
var isCurrent = state.Id == currentValue;
var isOngoing = !isCurrent && state.Timer > 0f;
if (isCurrent || isOngoing)
{
if (isCurrent && state.Timer <= 0f && _onStateCooldown != null)
{
_onStateCooldown.Invoke(currentValue);
}
state.Timer += deltaTime;
if (state.Timer > state.Duration)
if (state.Timer >= state.Cooldown)
{
if (isCurrent)
{
base.Value = currentValue; // Will trigger Changed event
}
state.Timer = 0f;
}
}
}
}
// Call OnUpdate hooks
// Call OnUpdate handlers
if (_onUpdate != null)
{
_onUpdate.Invoke(deltaTime, currentValue);
}
// Call DispatchWhen handlers
if (_dispatchWhen != null)
{
_dispatchWhen.Invoke(currentValue);
}
}
private void OnFixedUpdate(float deltaTime)
{
// Call OnFixedUpdate handlers
if (_onFixedUpdate != null)
{
_onFixedUpdate.Invoke(deltaTime, Value);
}
}
private Transition FindTransitionForCurrentState(string command)
{
Transition ret = null;

View File

@ -5,25 +5,25 @@ namespace UnityAtoms.FSM
{
[EditorIcon("atom-icon-hotpink")]
[AddComponentMenu("Unity Atoms/FSM/Finite State Machine Instancer")]
public class FiniteStateMachineInstancer : AtomVariableInstancer<
FiniteStateMachine,
StringPair,
string,
StringEvent,
StringPairEvent,
StringStringFunction,
AtomCollection,
AtomList>
public class FiniteStateMachineInstancer : StringVariableInstancer
{
public override StringVariable Base { get => (StringVariable)_fsmBase; }
/// <summary>
/// The variable that the in memory copy will be based on when created at runtime.
/// </summary>
[SerializeField]
private FiniteStateMachine _fsmBase = null;
protected override void ImplSpecificSetup()
{
if (_base.TransitionStarted != null)
if (((FiniteStateMachine)Base).TransitionStarted != null)
{
_inMemoryCopy.TransitionStarted = Instantiate(_base.TransitionStarted);
((FiniteStateMachine)_inMemoryCopy).TransitionStarted = Instantiate(((FiniteStateMachine)Base).TransitionStarted);
}
if (_base.CompleteCurrentTransition != null)
if (((FiniteStateMachine)Base).CompleteCurrentTransition != null)
{
_inMemoryCopy.CompleteCurrentTransition = Instantiate(_base.CompleteCurrentTransition);
((FiniteStateMachine)_inMemoryCopy).CompleteCurrentTransition = Instantiate(((FiniteStateMachine)Base).CompleteCurrentTransition);
}
}
}

View File

@ -3,22 +3,24 @@ using UnityEngine;
namespace UnityAtoms.FSM
{
public class FiniteStateMachineUpdateHook : MonoBehaviour
public class FiniteStateMachineMonoHook : MonoBehaviour
{
public static FiniteStateMachineUpdateHook GetInstance(bool createIfNotExist = false)
public static FiniteStateMachineMonoHook GetInstance(bool createIfNotExist = false)
{
if (_instance == null && createIfNotExist)
{
GameObject go = new GameObject("FiniteStateMachineUpdateHook");
_instance = go.AddComponent<FiniteStateMachineUpdateHook>();
_instance = go.AddComponent<FiniteStateMachineMonoHook>();
}
return _instance;
}
public event Action OnStart;
public event Action<float> OnUpdate;
public event Action<float> OnFixedUpdate;
private static FiniteStateMachineUpdateHook _instance;
private static FiniteStateMachineMonoHook _instance;
private void Awake()
{
@ -32,6 +34,14 @@ namespace UnityAtoms.FSM
DontDestroyOnLoad(gameObject);
}
private void Start()
{
if (OnStart != null)
{
OnStart.Invoke();
}
}
private void Update()
{
if (OnUpdate != null)
@ -39,5 +49,13 @@ namespace UnityAtoms.FSM
OnUpdate.Invoke(Time.deltaTime);
}
}
private void FixedUpdate()
{
if (OnFixedUpdate != null)
{
OnFixedUpdate.Invoke(Time.deltaTime);
}
}
}
}

View File

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

View File

@ -7,8 +7,8 @@ namespace UnityAtoms.FSM
public class FiniteStateMachineReferenceUsage
{
public const int MACHINE = 0;
public const int MACHINE_INSTANCER = 1;
public const int FSM = 0;
public const int FSM_INSTANCER = 1;
}
/// <summary>
@ -27,24 +27,25 @@ namespace UnityAtoms.FSM
{
switch (_usage)
{
case (FiniteStateMachineReferenceUsage.MACHINE_INSTANCER): return _machineInstancer == null ? default(FiniteStateMachine) : _machineInstancer.Variable;
case (FiniteStateMachineReferenceUsage.MACHINE):
case (FiniteStateMachineReferenceUsage.FSM_INSTANCER):
return _fsmInstancer == null ? default(FiniteStateMachine) : (FiniteStateMachine)_fsmInstancer.Variable;
case (FiniteStateMachineReferenceUsage.FSM):
default:
return _machine;
return _fsm;
}
}
}
/// <summary>
/// Variable used if `Usage` is set to `Variable`.
/// Variable used if `Usage` is set to `FSM`.
/// </summary>
[SerializeField]
private FiniteStateMachine _machine = default(FiniteStateMachine);
private FiniteStateMachine _fsm = default(FiniteStateMachine);
/// <summary>
/// Variable Instancer used if `Usage` is set to `VariableInstancer`.
/// Variable Instancer used if `Usage` is set to `FSM_INSTANCER`.
/// </summary>
[SerializeField]
private FiniteStateMachineInstancer _machineInstancer = default(FiniteStateMachineInstancer);
private FiniteStateMachineInstancer _fsmInstancer = default(FiniteStateMachineInstancer);
}
}

View File

@ -30,16 +30,21 @@ namespace UnityAtoms.FSM
private bool _raiseEventToCompleteTransition;
private FiniteStateMachine _fsmReference;
private Action _onComplete;
private void Complete()
{
_fsmReference.EndCurrentTransition();
_onComplete();
_fsmReference = null;
_onComplete = null;
}
public void Begin(FiniteStateMachine fsm)
public void Begin(FiniteStateMachine fsm, Action onComplete)
{
_fsmReference = fsm;
_onComplete = onComplete;
if (_raiseEventToCompleteTransition)
{

View File

@ -16,17 +16,17 @@ namespace UnityAtoms.UI
/// Variable that we listens to.
/// </summary>
[SerializeField]
private StringVariable _UIStateVariable = null;
private StringVariable _currentUIState = null;
/// <summary>
/// A list of states that this `UIContainer` will be visible for.
/// </summary>
[SerializeField]
private List<StringConstant> _visibleForStates = null;
private List<StringReference> _visibleForStates = null;
private void Start()
{
StateNameChanged(_UIStateVariable.Value);
StateNameChanged(_currentUIState.Value);
}
/// <summary>
@ -56,17 +56,17 @@ namespace UnityAtoms.UI
private void Awake()
{
if (_UIStateVariable.Changed != null)
if (_currentUIState.Changed != null)
{
_UIStateVariable.Changed.RegisterListener(this);
_currentUIState.Changed.RegisterListener(this);
}
}
private void OnDestroy()
{
if (_UIStateVariable.Changed != null)
if (_currentUIState.Changed != null)
{
_UIStateVariable.Changed.UnregisterListener(this);
_currentUIState.Changed.UnregisterListener(this);
}
}
}