@ -158,8 +158,10 @@ namespace Fungus
}
}
// Tell all components that implement IUpdateable to update to the new version
// Tell all components that implement IUpdateable to update to the new version
foreach ( Component component in GetComponents < Component > ( ) )
var components = GetComponents < Component > ( ) ;
for ( int i = 0 ; i < components . Length ; i + + )
{
{
var component = components [ i ] ;
IUpdateable u = component as IUpdateable ;
IUpdateable u = component as IUpdateable ;
if ( u ! = null )
if ( u ! = null )
{
{
@ -181,10 +183,10 @@ namespace Fungus
// This should always be the case, but some legacy Flowcharts may have issues.
// This should always be the case, but some legacy Flowcharts may have issues.
List < int > usedIds = new List < int > ( ) ;
List < int > usedIds = new List < int > ( ) ;
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
if ( block . ItemId = = - 1 | |
var block = blocks [ i ] ;
usedIds . Contains ( block . ItemId ) )
if ( block . ItemId = = - 1 | | usedIds . Contains ( block . ItemId ) )
{
{
block . ItemId = NextItemId ( ) ;
block . ItemId = NextItemId ( ) ;
}
}
@ -192,10 +194,10 @@ namespace Fungus
}
}
var commands = GetComponents < Command > ( ) ;
var commands = GetComponents < Command > ( ) ;
foreach ( var command in commands )
for ( int i = 0 ; i < commands . Length ; i + + )
{
{
if ( command . ItemId = = - 1 | |
var command = commands [ i ] ;
usedIds . Contains ( command . ItemId ) )
if ( command . ItemId = = - 1 | | usedIds . Contains ( command . ItemId ) )
{
{
command . ItemId = NextItemId ( ) ;
command . ItemId = NextItemId ( ) ;
}
}
@ -213,8 +215,10 @@ namespace Fungus
// It shouldn't happen but it seemed to occur for a user on the forum
// It shouldn't happen but it seemed to occur for a user on the forum
variables . RemoveAll ( item = > item = = null ) ;
variables . RemoveAll ( item = > item = = null ) ;
foreach ( Variable variable in GetComponents < Variable > ( ) )
var allVariables = GetComponents < Variable > ( ) ;
for ( int i = 0 ; i < allVariables . Length ; i + + )
{
{
var variable = allVariables [ i ] ;
if ( ! variables . Contains ( variable ) )
if ( ! variables . Contains ( variable ) )
{
{
DestroyImmediate ( variable ) ;
DestroyImmediate ( variable ) ;
@ -222,37 +226,40 @@ namespace Fungus
}
}
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
var commands = GetComponents < Command > ( ) ;
foreach ( var command in GetComponents < Command > ( ) )
for ( int i = 0 ; i < commands . Length ; i + + )
{
{
var command = commands [ i ] ;
bool found = false ;
bool found = false ;
foreach ( var block in blocks )
for ( int j = 0 ; j < blocks . Length ; j + + )
{
{
var block = blocks [ j ] ;
if ( block . CommandList . Contains ( command ) )
if ( block . CommandList . Contains ( command ) )
{
{
found = true ;
found = true ;
break ;
break ;
}
}
}
}
if ( ! found )
if ( ! found )
{
{
DestroyImmediate ( command ) ;
DestroyImmediate ( command ) ;
}
}
}
}
foreach ( EventHandler eventHandler in GetComponents < EventHandler > ( ) )
var eventHandlers = GetComponents < EventHandler > ( ) ;
for ( int i = 0 ; i < eventHandlers . Length ; i + + )
{
{
var eventHandler = eventHandlers [ i ] ;
bool found = false ;
bool found = false ;
foreach ( var block in blocks )
for ( int j = 0 ; j < blocks . Length ; j + + )
{
{
var block = blocks [ j ] ;
if ( block . _ EventHandler = = eventHandler )
if ( block . _ EventHandler = = eventHandler )
{
{
found = true ;
found = true ;
break ;
break ;
}
}
}
}
if ( ! found )
if ( ! found )
{
{
DestroyImmediate ( eventHandler ) ;
DestroyImmediate ( eventHandler ) ;
@ -279,9 +286,10 @@ namespace Fungus
/// </summary>
/// </summary>
public static void BroadcastFungusMessage ( string messageName )
public static void BroadcastFungusMessage ( string messageName )
{
{
MessageReceived [ ] eventHandlers = UnityEngine . Object . FindObjectsOfType < MessageReceived > ( ) ;
var eventHandlers = UnityEngine . Object . FindObjectsOfType < MessageReceived > ( ) ;
foreach ( MessageReceived eventHandler in eventHandlers )
for ( int i = 0 ; i < eventHandlers . Length ; i + + )
{
{
var eventHandler = eventHandlers [ i ] ;
eventHandler . OnSendFungusMessage ( messageName ) ;
eventHandler . OnSendFungusMessage ( messageName ) ;
}
}
}
}
@ -406,14 +414,16 @@ namespace Fungus
{
{
int maxId = - 1 ;
int maxId = - 1 ;
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
maxId = Math . Max ( maxId , block . ItemId ) ;
maxId = Math . Max ( maxId , block . ItemId ) ;
}
}
var commands = GetComponents < Command > ( ) ;
var commands = GetComponents < Command > ( ) ;
foreach ( var command in commands )
for ( int i = 0 ; i < commands . Length ; i + + )
{
{
var command = commands [ i ] ;
maxId = Math . Max ( maxId , command . ItemId ) ;
maxId = Math . Max ( maxId , command . ItemId ) ;
}
}
return maxId + 1 ;
return maxId + 1 ;
@ -438,8 +448,9 @@ namespace Fungus
public virtual Block FindBlock ( string blockName )
public virtual Block FindBlock ( string blockName )
{
{
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
if ( block . BlockName = = blockName )
if ( block . BlockName = = blockName )
{
{
return block ;
return block ;
@ -506,8 +517,9 @@ namespace Fungus
public virtual void StopAllBlocks ( )
public virtual void StopAllBlocks ( )
{
{
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( Block block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
if ( block . IsExecuting ( ) )
if ( block . IsExecuting ( ) )
{
{
block . Stop ( ) ;
block . Stop ( ) ;
@ -521,9 +533,10 @@ namespace Fungus
/// </summary>
/// </summary>
public virtual void SendFungusMessage ( string messageName )
public virtual void SendFungusMessage ( string messageName )
{
{
MessageReceived [ ] eventHandlers = GetComponents < MessageReceived > ( ) ;
var eventHandlers = GetComponents < MessageReceived > ( ) ;
foreach ( MessageReceived eventHandler in eventHandlers )
for ( int i = 0 ; i < eventHandlers . Length ; i + + )
{
{
var eventHandler = eventHandlers [ i ] ;
eventHandler . OnSendFungusMessage ( messageName ) ;
eventHandler . OnSendFungusMessage ( messageName ) ;
}
}
}
}
@ -553,15 +566,13 @@ namespace Fungus
while ( true )
while ( true )
{
{
bool collision = false ;
bool collision = false ;
foreach ( Variable variable in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
if ( variable = = null | |
var variable = variables [ i ] ;
variable = = ignoreVariable | |
if ( variable = = null | | variable = = ignoreVariable | | variable . Key = = null )
variable . Key = = null )
{
{
continue ;
continue ;
}
}
if ( variable . Key . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
if ( variable . Key . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
{
{
collision = true ;
collision = true ;
@ -597,14 +608,13 @@ namespace Fungus
while ( true )
while ( true )
{
{
bool collision = false ;
bool collision = false ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
if ( block = = ignoreBlock | |
var block = blocks [ i ] ;
block . BlockName = = null )
if ( block = = ignoreBlock | | block . BlockName = = null )
{
{
continue ;
continue ;
}
}
if ( block . BlockName . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
if ( block . BlockName . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
{
{
collision = true ;
collision = true ;
@ -640,15 +650,15 @@ namespace Fungus
while ( true )
while ( true )
{
{
bool collision = false ;
bool collision = false ;
foreach ( var command in block . CommandList )
var commandList = block . CommandList ;
for ( int i = 0 ; i < commandList . Count ; i + + )
{
{
var command = commandList [ i ] ;
Label label = command as Label ;
Label label = command as Label ;
if ( label = = null | |
if ( label = = null | | label = = ignoreLabel )
label = = ignoreLabel )
{
{
continue ;
continue ;
}
}
if ( label . Key . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
if ( label . Key . Equals ( key , StringComparison . CurrentCultureIgnoreCase ) )
{
{
collision = true ;
collision = true ;
@ -673,8 +683,9 @@ namespace Fungus
/// </summary>
/// </summary>
public Variable GetVariable ( string key )
public Variable GetVariable ( string key )
{
{
foreach ( Variable variable in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
var variable = variables [ i ] ;
if ( variable ! = null & & variable . Key = = key )
if ( variable ! = null & & variable . Key = = key )
{
{
return variable ;
return variable ;
@ -692,8 +703,9 @@ namespace Fungus
/// </summary>
/// </summary>
public T GetVariable < T > ( string key ) where T : Variable
public T GetVariable < T > ( string key ) where T : Variable
{
{
foreach ( Variable variable in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
var variable = variables [ i ] ;
if ( variable ! = null & & variable . Key = = key )
if ( variable ! = null & & variable . Key = = key )
{
{
return variable as T ;
return variable as T ;
@ -710,8 +722,9 @@ namespace Fungus
/// </summary>
/// </summary>
public void SetVariable < T > ( string key , T newvariable ) where T : Variable
public void SetVariable < T > ( string key , T newvariable ) where T : Variable
{
{
foreach ( Variable v in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
var v = variables [ i ] ;
if ( v ! = null & & v . Key = = key )
if ( v ! = null & & v . Key = = key )
{
{
T variable = v as T ;
T variable = v as T ;
@ -731,9 +744,10 @@ namespace Fungus
/// </summary>
/// </summary>
public virtual List < Variable > GetPublicVariables ( )
public virtual List < Variable > GetPublicVariables ( )
{
{
List < Variable > publicVariables = new List < Variable > ( ) ;
var publicVariables = new List < Variable > ( ) ;
foreach ( Variable v in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
var v = variables [ i ] ;
if ( v ! = null & & v . Scope = = VariableScope . Public )
if ( v ! = null & & v . Scope = = VariableScope . Public )
{
{
publicVariables . Add ( v ) ;
publicVariables . Add ( v ) ;
@ -874,9 +888,10 @@ namespace Fungus
{
{
if ( hideComponents )
if ( hideComponents )
{
{
Block [ ] blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( Block block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
block . hideFlags = HideFlags . HideInInspector ;
block . hideFlags = HideFlags . HideInInspector ;
if ( block . gameObject ! = gameObject )
if ( block . gameObject ! = gameObject )
{
{
@ -884,28 +899,30 @@ namespace Fungus
}
}
}
}
Command [ ] commands = GetComponents < Command > ( ) ;
var commands = GetComponents < Command > ( ) ;
foreach ( var command in commands )
for ( int i = 0 ; i < commands . Length ; i + + )
{
{
var command = commands [ i ] ;
command . hideFlags = HideFlags . HideInInspector ;
command . hideFlags = HideFlags . HideInInspector ;
}
}
EventHandler [ ] eventHandlers = GetComponents < EventHandler > ( ) ;
var eventHandlers = GetComponents < EventHandler > ( ) ;
foreach ( var eventHandler in eventHandlers )
for ( int i = 0 ; i < eventHandlers . Length ; i + + )
{
{
var eventHandler = eventHandlers [ i ] ;
eventHandler . hideFlags = HideFlags . HideInInspector ;
eventHandler . hideFlags = HideFlags . HideInInspector ;
}
}
}
}
else
else
{
{
MonoBehaviour [ ] monoBehaviours = GetComponents < MonoBehaviour > ( ) ;
var monoBehaviours = GetComponents < MonoBehaviour > ( ) ;
foreach ( MonoBehaviour monoBehaviour in monoBehaviours )
for ( int i = 0 ; i < monoBehaviours . Length ; i + + )
{
{
var monoBehaviour = monoBehaviours [ i ] ;
if ( monoBehaviour = = null )
if ( monoBehaviour = = null )
{
{
continue ;
continue ;
}
}
monoBehaviour . hideFlags = HideFlags . None ;
monoBehaviour . hideFlags = HideFlags . None ;
monoBehaviour . gameObject . hideFlags = HideFlags . None ;
monoBehaviour . gameObject . hideFlags = HideFlags . None ;
}
}
@ -939,16 +956,18 @@ namespace Fungus
if ( resetCommands )
if ( resetCommands )
{
{
var commands = GetComponents < Command > ( ) ;
var commands = GetComponents < Command > ( ) ;
foreach ( var command in commands )
for ( int i = 0 ; i < commands . Length ; i + + )
{
{
var command = commands [ i ] ;
command . OnReset ( ) ;
command . OnReset ( ) ;
}
}
}
}
if ( resetVariables )
if ( resetVariables )
{
{
foreach ( Variable variable in variables )
for ( int i = 0 ; i < variables . Count ; i + + )
{
{
var variable = variables [ i ] ;
variable . OnReset ( ) ;
variable . OnReset ( ) ;
}
}
}
}
@ -959,11 +978,11 @@ namespace Fungus
/// </summary>
/// </summary>
public virtual bool IsCommandSupported ( CommandInfoAttribute commandInfo )
public virtual bool IsCommandSupported ( CommandInfoAttribute commandInfo )
{
{
foreach ( string key in hideCommands )
for ( int i = 0 ; i < hideCommands . Count ; i + + )
{
{
// Match on category or command name (case insensitive)
// Match on category or command name (case insensitive)
if ( String . Compare ( commandInfo . Category , key , StringComparison . OrdinalIgnoreCase ) = = 0 | |
var key = hideCommands [ i ] ;
String . Compare ( commandInfo . CommandName , key , StringComparison . OrdinalIgnoreCase ) = = 0 )
if ( String . Compare ( commandInfo . Category , key , StringComparison . OrdinalIgnoreCase ) = = 0 | | String . Compare ( commandInfo . CommandName , key , StringComparison . OrdinalIgnoreCase ) = = 0 )
{
{
return false ;
return false ;
}
}
@ -978,8 +997,9 @@ namespace Fungus
public virtual bool HasExecutingBlocks ( )
public virtual bool HasExecutingBlocks ( )
{
{
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
if ( block . IsExecuting ( ) )
if ( block . IsExecuting ( ) )
{
{
return true ;
return true ;
@ -995,8 +1015,9 @@ namespace Fungus
{
{
var executingBlocks = new List < Block > ( ) ;
var executingBlocks = new List < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
var blocks = GetComponents < Block > ( ) ;
foreach ( var block in blocks )
for ( int i = 0 ; i < blocks . Length ; i + + )
{
{
var block = blocks [ i ] ;
if ( block . IsExecuting ( ) )
if ( block . IsExecuting ( ) )
{
{
executingBlocks . Add ( block ) ;
executingBlocks . Add ( block ) ;
@ -1032,19 +1053,18 @@ namespace Fungus
// Match the regular expression pattern against a text string.
// Match the regular expression pattern against a text string.
var results = r . Matches ( input ) ;
var results = r . Matches ( input ) ;
foreach ( Match match in results )
for ( int i = 0 ; i < results . Count ; i + + )
{
{
Match match = results [ i ] ;
string key = match . Value . Substring ( 2 , match . Value . Length - 3 ) ;
string key = match . Value . Substring ( 2 , match . Value . Length - 3 ) ;
// Look for any matching private variables in this Flowchart first
// Look for any matching private variables in this Flowchart first
foreach ( Variable variable in variables )
for ( int j = 0 ; j < variables . Count ; j + + )
{
{
var variable = variables [ j ] ;
if ( variable = = null )
if ( variable = = null )
continue ;
continue ;
if ( variable . Scope = = VariableScope . Private & & variable . Key = = key )
if ( variable . Scope = = VariableScope . Private & &
{
variable . Key = = key )
{
string value = variable . ToString ( ) ;
string value = variable . ToString ( ) ;
sb . Replace ( match . Value , value ) ;
sb . Replace ( match . Value , value ) ;
changed = true ;
changed = true ;
@ -1084,22 +1104,22 @@ namespace Fungus
// Match the regular expression pattern against a text string.
// Match the regular expression pattern against a text string.
var results = r . Matches ( input . ToString ( ) ) ;
var results = r . Matches ( input . ToString ( ) ) ;
foreach ( Match match in results )
for ( int i = 0 ; i < results . Count ; i + + )
{
{
Match match = results [ i ] ;
string key = match . Value . Substring ( 2 , match . Value . Length - 3 ) ;
string key = match . Value . Substring ( 2 , match . Value . Length - 3 ) ;
// Look for any matching public variables in this Flowchart
// Look for any matching public variables in this Flowchart
foreach ( Variable variable in variables )
for ( int j = 0 ; j < variables . Count ; j + + )
{
{
var variable = variables [ j ] ;
if ( variable = = null )
if ( variable = = null )
{
continue ;
continue ;
}
if ( variable . Scope = = VariableScope . Public & &
if ( variable . Scope = = VariableScope . Public & & variable . Key = = key )
variable . Key = = key )
{
{
string value = variable . ToString ( ) ;
string value = variable . ToString ( ) ;
input . Replace ( match . Value , value ) ;
input . Replace ( match . Value , value ) ;
modified = true ;
modified = true ;
}
}
}
}