playMaker

Author Topic: StringAddNewLine  (Read 3362 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
StringAddNewLine
« on: February 22, 2012, 01:39:54 AM »
Lackedof inspiration for the name.. so if someone finds a better name, I'll change it :)

 basically, I need to add new lines to a string, and while its possible with buildString ( by copying pasting a newline cahr from a text editor and put it in the separator, etc etc), it's not very nice, so I wrote a specific action for this.

 This is very good for chat applications for example or logging stuff easily on screen.


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.String)]
[Tooltip("Adds strings together seprated by a line.")]
public class StringAddNewLine : FsmStateAction
{
[Tooltip("List of the strings to compose.")]
[RequiredField]
public FsmString[] stringParts;

[Tooltip("Store the result.")]
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString storeResult;


public override void Reset()
{
stringParts = new FsmString[2];

storeResult = null;
}

public override void OnEnter()
{
DoBuildString();

Finish();
}


void DoBuildString()
{
if (storeResult == null) return;

string result = "";
int count = stringParts.Length;
for(int i=0;i<count;i++)
{
if (result != "")
{
result += "\n";
}

result += stringParts[i];
}

    storeResult.Value = result;
}

}
}

 Bye,

 Jean