forked from snozbot/fungus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more versatile version of Message Received
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This code is part of the Fungus library (https://github.com/snozbot/fungus) | ||
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) | ||
|
||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace Fungus | ||
{ | ||
/// <summary> | ||
/// The block will execute when the specified message is received from a Send Message command. | ||
/// </summary> | ||
[EventHandlerInfo("Scene", | ||
"Messages Received", | ||
"Like Message Received, but works so this block is executed when it receives any in a group of messages from Send Message.")] | ||
[AddComponentMenu("")] | ||
public class MessagesReceived : EventHandler | ||
{ | ||
[Tooltip("Fungus messages to listen for")] | ||
[SerializeField] protected string[] messages = null; | ||
|
||
#region Public members | ||
|
||
/// <summary> | ||
/// Called from Flowchart when a message is sent. | ||
/// </summary> | ||
/// <param name="messageToConsider">Message.</param> | ||
public void OnSendFungusMessage(string messageToConsider) | ||
{ | ||
if (ShouldRespondToMessage(messageToConsider)) | ||
{ | ||
ExecuteBlock(); | ||
} | ||
} | ||
|
||
protected virtual bool ShouldRespondToMessage(string messageToConsider) | ||
{ | ||
for (int i = 0; i < this.messages.Length; i++) | ||
if (messages[i] == messageToConsider) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a newline-separated combined string of the messages this is set to respond to. | ||
/// </summary> | ||
public override string GetSummary() | ||
{ | ||
string summary = ""; | ||
|
||
for (int i = 0; i < this.messages.Length; i++) | ||
{ | ||
summary.Concat(this.messages[i]); | ||
summary.Concat("\n"); | ||
} | ||
|
||
return summary; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Fungus/Scripts/EventHandlers/MessagesReceived.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.