diff --git a/Assets/Fungus/Flowchart/Scripts/EventHandler.cs b/Assets/Fungus/Flowchart/Scripts/EventHandler.cs
index 332fc4be..4602439c 100644
--- a/Assets/Fungus/Flowchart/Scripts/EventHandler.cs
+++ b/Assets/Fungus/Flowchart/Scripts/EventHandler.cs
@@ -32,23 +32,19 @@ namespace Fungus
/// Add an EventHandlerInfo attibute and your new EventHandler class will automatically appear in the
/// 'Execute On Event' dropdown menu when a block is selected.
///
- [RequireComponent(typeof(IBlock))]
+ [RequireComponent(typeof(Block))]
[RequireComponent(typeof(Flowchart))]
[AddComponentMenu("")]
- public class EventHandler : MonoBehaviour
+ public class EventHandler : MonoBehaviour, IEventHandler
{
- ///
- /// Returns the parent Block which owns this Event Handler.
- ///
- /// The parent block.
[HideInInspector]
[FormerlySerializedAs("parentSequence")]
[SerializeField] protected Block parentBlock;
+
+ #region IEventHandler
+
public virtual IBlock ParentBlock { get { return parentBlock; } set { parentBlock = (Block)value; } }
- ///
- /// The Event Handler should call this method when the event is detected.
- ///
public virtual bool ExecuteBlock()
{
if (parentBlock == null)
@@ -72,12 +68,11 @@ namespace Fungus
return flowchart.ExecuteBlock(parentBlock);
}
- ///
- /// Returns custom summary text for the event handler.
- ///
public virtual string GetSummary()
{
return "";
}
+
+ #endregion
}
}
diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs
index 22f4052d..4dc6d5a9 100644
--- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs
+++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs
@@ -890,7 +890,7 @@ namespace Fungus
}
EventHandler[] eventHandlers = GetComponents();
- foreach (EventHandler eventHandler in eventHandlers)
+ foreach (var eventHandler in eventHandlers)
{
eventHandler.hideFlags = HideFlags.HideInInspector;
}
diff --git a/Assets/Fungus/Flowchart/Scripts/IBlock.cs b/Assets/Fungus/Flowchart/Scripts/IBlock.cs
index 73a9c535..ffa44332 100644
--- a/Assets/Fungus/Flowchart/Scripts/IBlock.cs
+++ b/Assets/Fungus/Flowchart/Scripts/IBlock.cs
@@ -40,6 +40,7 @@ namespace Fungus
///
/// An optional Event Handler which can execute the block when an event occurs.
+ /// Note: Using the concrete class instead of the interface here because of weird editor behaviour.
///
EventHandler _EventHandler { get; set; }
diff --git a/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs b/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs
new file mode 100644
index 00000000..33998b3f
--- /dev/null
+++ b/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs
@@ -0,0 +1,30 @@
+using UnityEngine;
+
+namespace Fungus
+{
+ ///
+ /// A Block may have an associated Event Handler which starts executing commands when
+ /// a specific event occurs.
+ /// To create a custom Event Handler, simply subclass EventHandler and call the ExecuteBlock() method
+ /// when the event occurs.
+ /// Add an EventHandlerInfo attibute and your new EventHandler class will automatically appear in the
+ /// 'Execute On Event' dropdown menu when a block is selected.
+ ///
+ public interface IEventHandler
+ {
+ ///
+ /// The parent Block which owns this Event Handler.
+ ///
+ IBlock ParentBlock { get; set; }
+
+ ///
+ /// The Event Handler should call this method when the event is detected to start executing the Block.
+ ///
+ bool ExecuteBlock();
+
+ ///
+ /// Returns custom summary text for the event handler.
+ ///
+ string GetSummary();
+ }
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs.meta b/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs.meta
new file mode 100644
index 00000000..9c74a406
--- /dev/null
+++ b/Assets/Fungus/Flowchart/Scripts/IEventHandler.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 5ae3dddb3147c4a07a851843721affe8
+timeCreated: 1473856414
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs b/Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs
index 5ee63a14..168c5c71 100644
--- a/Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs
+++ b/Assets/Fungus/Scripts/Editor/FlowchartMenuItems.cs
@@ -25,8 +25,8 @@ namespace Fungus
if (GameObject.FindObjectsOfType().Length > 1)
{
IBlock block = go.GetComponent();
- block._EventHandler = null;
GameObject.DestroyImmediate(block._EventHandler);
+ block._EventHandler = null;
}
}