I thought this could be useful for some PlayMaker users. A convenient way to add a line break to the Append Raw action. I use it to make Debug Logs, so it's nice to have each message in its own line.
Code: Select all
[ActionCategory("Easy Save 2")]
public class AppendRaw : FsmStateAction
{
[RequiredField]
[Tooltip("The raw string we want to append to a file.")]
public FsmString saveValue;
[Tooltip("Add a line break at the end of the string.")]
public FsmBool addLineBreak = true;
[Tooltip("The name or absolute path of the file we want to append our raw string to. If the file doesn't exist, it will be created.")]
public FsmString filename = "defaultFile.txt";
[Tooltip("This event is called if an error occurs.")]
public FsmEvent ifError = null;
public override void Reset()
{
saveValue = null;
base.Reset (); // Ensure that base.Reset() is called when done.
}
public override void OnEnter()
{
try
{
if (addLineBreak.Value)
{
ES2.AppendRaw(saveValue.Value + "\r\n", filename.Value);
base.OnEnter(); // Ensure that base.OnEnter() is called when done.
Finish();
}
else
{
ES2.AppendRaw(saveValue.Value, filename.Value);
base.OnEnter(); // Ensure that base.OnEnter() is called when done.
Finish();
}
}
catch(System.Exception e)
{
if(ifError != null)
{
LogError(e.Message);
Fsm.Event(ifError);
}
}
}
}