Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Andrew.Lukasik on October 20, 2011, 05:27:42 AM

Title: Level Name To String
Post by: Andrew.Lukasik on October 20, 2011, 05:27:42 AM
LevelNameToString.cs

Description: Returns current level's name as a String


Example: Using it with <Load Level> (from string) - can be very helpful when it comes to working with multiple scenes.
With this action you can store name of a previously played level to go back to it later when needed (sub-locations / interiors etc) or to simply restart scene.


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// micro script by Andrew Raphael Lukasik

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Level)]
[Tooltip("Returns current level's name as a string.")]
public class LevelNameToString : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString stringVariable;
[RequiredField]
private FsmString stringValue;

public override void Reset()
{
stringVariable = null;
stringValue = null;
}

public override void OnEnter()
{
DoSetStringValue();

Finish();
}


void DoSetStringValue()
{
if (stringVariable == null) return;
stringValue = Application.loadedLevelName;
stringVariable.Value = stringValue.Value;
}

}
}