Christopher
8 years ago
7 changed files with 337 additions and 6 deletions
@ -0,0 +1,36 @@
|
||||
using Fungus.Utils; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Block event signalling system. |
||||
/// You can use this to be notified about various events in the Block execution process. |
||||
/// </summary> |
||||
public static class BlockSignals |
||||
{ |
||||
#region Public members |
||||
|
||||
/// <summary> |
||||
/// BlockStart signal. Sent when the Block starts execution. |
||||
/// </summary> |
||||
public static event BlockStartHandler OnBlockStart; |
||||
public delegate void BlockStartHandler(Block block); |
||||
public static void DoBlockStart(Block block) { if (OnBlockStart != null) OnBlockStart(block); } |
||||
|
||||
/// <summary> |
||||
/// BlockEnd signal. Sent when the Block ends execution. |
||||
/// </summary> |
||||
public static event BlockEndHandler OnBlockEnd; |
||||
public delegate void BlockEndHandler(Block block); |
||||
public static void DoBlockEnd(Block block) { if (OnBlockEnd != null) OnBlockEnd(block); } |
||||
|
||||
/// <summary> |
||||
/// CommandExecute signal. Sent just before a Command in a Block executes. |
||||
/// </summary> |
||||
public static event CommandExecuteHandler OnCommandExecute; |
||||
public delegate void CommandExecuteHandler(Block block, Command command, int commandIndex, int maxCommandIndex); |
||||
public static void DoCommandExecute(Block block, Command command, int commandIndex, int maxCommandIndex) { if (OnCommandExecute != null) OnCommandExecute(block, command, commandIndex, maxCommandIndex); } |
||||
|
||||
#endregion |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 12109e10b0f034bbab8a7a5d700bc070 |
||||
timeCreated: 1474988491 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,53 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using Fungus.Commands; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Checks if Block signals are being sent correctly. |
||||
/// </summary> |
||||
[AddComponentMenu("")] |
||||
public class BlockSignalsTester : MonoBehaviour |
||||
{ |
||||
bool started = false; |
||||
bool commandExecuted = false; |
||||
|
||||
void OnEnable() |
||||
{ |
||||
BlockSignals.OnBlockStart += OnBlockStart; |
||||
BlockSignals.OnBlockEnd += OnBlockEnd; |
||||
BlockSignals.OnCommandExecute += OnCommandExecute; |
||||
} |
||||
|
||||
void OnDisable() |
||||
{ |
||||
BlockSignals.OnBlockStart -= OnBlockStart; |
||||
BlockSignals.OnBlockEnd -= OnBlockEnd; |
||||
BlockSignals.OnCommandExecute -= OnCommandExecute; |
||||
} |
||||
|
||||
void OnBlockStart(Block block) |
||||
{ |
||||
IntegrationTest.Assert(block.BlockName == "Start"); |
||||
|
||||
started = true; |
||||
} |
||||
|
||||
void OnBlockEnd(Block block) |
||||
{ |
||||
IntegrationTest.Assert(started); |
||||
IntegrationTest.Assert(commandExecuted); |
||||
|
||||
IntegrationTest.Pass(); |
||||
} |
||||
|
||||
void OnCommandExecute(Block block, Command command, int commandIndex, int maxCommandIndex) |
||||
{ |
||||
IntegrationTest.Assert(commandIndex == 0); |
||||
IntegrationTest.Assert(maxCommandIndex == 1); |
||||
IntegrationTest.Assert(command.GetType() == typeof(Wait)); |
||||
commandExecuted = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 5d396ca39a0454e2ca06d4aad7c5706c |
||||
timeCreated: 1474988463 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue