playMaker

Author Topic: StringGetLineCount  (Read 1379 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14500
  • Official Playmaker Support
    • View Profile
StringGetLineCount
« on: February 22, 2012, 12:33:32 AM »
Hi,
 
 to complement StringDeleteLine, you can get the number of lines in a string.

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.String)]
[Tooltip("Get the number of lines of a string.")]
public class StringGetLineCount : FsmStateAction
{

[Tooltip("The string.")]
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString theString;

[Tooltip("The number of lines")]
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt lineCount;


public override void Reset()
{
theString = null;
lineCount = 0;

}

public override void OnEnter()
{
DoGetLineCountFromString();

Finish();
}


void DoGetLineCountFromString()
{
if (theString == null)
{
Debug.LogWarning("String not defined");
return;
}

string[] split = theString.Value.Split('\n');

lineCount.Value = split.Length;
}

}
}

 Bye,

 Jean