@ -16,7 +16,7 @@ namespace Fungus
/// </summary>
/// </summary>
public class StringSubstituter : IStringSubstituter
public class StringSubstituter : IStringSubstituter
{
{
protected List < ISubstitutionHandler > substitutionHandlers = new List < ISubstitutionHandler > ( ) ;
protected static List < ISubstitutionHandler > substitutionHandlers = new List < ISubstitutionHandler > ( ) ;
/// <summary>
/// <summary>
/// The StringBuilder instance used to substitute strings optimally.
/// The StringBuilder instance used to substitute strings optimally.
@ -27,6 +27,19 @@ namespace Fungus
#region Public members
#region Public members
public static void RegisterHandler ( ISubstitutionHandler handler )
{
if ( ! substitutionHandlers . Contains ( handler ) )
{
substitutionHandlers . Add ( handler ) ;
}
}
public static void UnregisterHandler ( ISubstitutionHandler handler )
{
substitutionHandlers . Remove ( handler ) ;
}
/// <summary>
/// <summary>
/// Constructor which caches all components in the scene that implement ISubstitutionHandler.
/// Constructor which caches all components in the scene that implement ISubstitutionHandler.
/// <param name="recursionDepth">Number of levels of recursively embedded keys to resolve.</param>
/// <param name="recursionDepth">Number of levels of recursively embedded keys to resolve.</param>
@ -43,34 +56,6 @@ namespace Fungus
public virtual StringBuilder _ StringBuilder { get { return stringBuilder ; } }
public virtual StringBuilder _ StringBuilder { get { return stringBuilder ; } }
public virtual void CacheSubstitutionHandlers ( )
{
// Use reflection to find all components in the scene that implement ISubstitutionHandler
#if NETFX_CORE
var types = this . GetType ( ) . GetAssembly ( ) . GetTypes ( ) . Where ( type = > type . IsClass ( ) & &
! type . IsAbstract ( ) & &
typeof ( ISubstitutionHandler ) . IsAssignableFrom ( type ) ) ;
# else
var types = this . GetType ( ) . Assembly . GetTypes ( ) . Where ( type = > type . IsClass & &
! type . IsAbstract & &
typeof ( ISubstitutionHandler ) . IsAssignableFrom ( type ) ) ;
# endif
substitutionHandlers . Clear ( ) ;
foreach ( System . Type t in types )
{
Object [ ] objects = GameObject . FindObjectsOfType ( t ) ;
foreach ( Object o in objects )
{
ISubstitutionHandler handler = o as ISubstitutionHandler ;
if ( handler ! = null )
{
substitutionHandlers . Add ( handler ) ;
}
}
}
}
public virtual string SubstituteStrings ( string input )
public virtual string SubstituteStrings ( string input )
{
{
stringBuilder . Length = 0 ;
stringBuilder . Length = 0 ;