Browse Source

Added SendFungusMessage() and BroadcastFungusMessage() commands

Fixed event handlers not executing correctly on first frame update
master
chrisgregan 10 years ago
parent
commit
581adb2749
  1. 2
      Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs
  2. 26
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  3. 2
      Assets/Fungus/FungusScript/Scripts/Sequence.cs

2
Assets/Fungus/FungusScript/Scripts/CommandCopyBuffer.cs

@ -35,7 +35,7 @@ namespace Fungus
return instance; return instance;
} }
protected override void Start() protected virtual void Start()
{ {
if (Application.isPlaying) if (Application.isPlaying)
{ {

26
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -115,6 +115,32 @@ namespace Fungus
return false; return false;
} }
/**
* Sends a message to this Fungus Script only.
* Any sequence with a matching MessageReceived event handler will start executing.
*/
public virtual void SendFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = GetComponentsInChildren<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
{
eventHandler.OnSendFungusMessage(messageName);
}
}
/**
* Sends a message to all Fungus Script objects in the current scene.
* Any sequence with a matching MessageReceived event handler will start executing.
*/
public static void BroadcastFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = GameObject.FindObjectsOfType<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
{
eventHandler.OnSendFungusMessage(messageName);
}
}
/** /**
* Start running another Fungus Script by executing a specific child sequence. * Start running another Fungus Script by executing a specific child sequence.
* The sequence must be in an idle state to be executed. * The sequence must be in an idle state to be executed.

2
Assets/Fungus/FungusScript/Scripts/Sequence.cs

@ -26,7 +26,7 @@ namespace Fungus
protected int executionCount; protected int executionCount;
protected virtual void Start() protected virtual void Awake()
{ {
// Give each child command a reference back to its parent sequence // Give each child command a reference back to its parent sequence
foreach (Command command in commandList) foreach (Command command in commandList)

Loading…
Cancel
Save