public override string ToString()
{
m_Text = m_ScriptPrescription.m_Template;
m_Writer = new StringWriter ();
m_Writer.NewLine = "\n";
// Make sure all line endings are Unix (Mac OS X) format
m_Text = Regex.Replace (m_Text, @"\r\n?", delegate(Match m) { return "\n"; });
// Class Name
m_Text = m_Text.Replace ("$ClassName", ClassName);
m_Text = m_Text.Replace ("$NicifiedClassName", ObjectNames.NicifyVariableName (ClassName));
// Other replacements
foreach (KeyValuePair<string, string> kvp in m_ScriptPrescription.m_StringReplacements)
m_Text = m_Text.Replace (kvp.Key, kvp.Value);
// Functions
// Find $Functions keyword including leading tabs
Match match = Regex.Match (m_Text, @"(\t*)\$Functions");
if (match.Success)
{
// Set indent level to number of tabs before $Functions keyword
IndentLevel = match.Groups[1].Value.Length;
bool hasFunctions = false;
if (m_ScriptPrescription.m_Functions != null)
{
foreach (var function in m_ScriptPrescription.m_Functions.Where (f => f.include))
{
WriteFunction (function);
WriteBlankLine ();
hasFunctions = true;
}
// Replace $Functions keyword plus newline with generated functions text
if (hasFunctions)
m_Text = m_Text.Replace (match.Value + "\n", m_Writer.ToString ());
}
if (!hasFunctions)
{
if (m_ScriptPrescription.m_Lang == Language.Boo && !m_Text.Contains ("def"))
// Replace $Functions keyword with "pass" if no functions in Boo
m_Text = m_Text.Replace (match.Value, m_Indentation + "pass");
else
// Otherwise just remove $Functions keyword plus newline
m_Text = m_Text.Replace (match.Value + "\n", string.Empty);
}
}
// Put curly vraces on new line if specified in editor prefs
if (EditorPrefs.GetBool ("CurlyBracesOnNewLine"))
PutCurveBracesOnNewLine ();
// Return the text of the script
return m_Text;
}