Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on July 02, 2012, 03:24:06 AM

Title: GUI CalcSize
Post by: jeanfabre on July 02, 2012, 03:24:06 AM
hi,

 Following a request, http://hutonggames.com/playmakerforum/index.php?topic=1798.0 (http://hutonggames.com/playmakerforum/index.php?topic=1798.0)


 Please find a action that will compute the size of a guiContent.

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUILayout)]
[Tooltip("GUIStyle Calc. Calculate the size of a some content if it is rendered with this style.")]
public class GuiStyleCalcSize : FsmStateAction
{
[RequiredField]
[Tooltip("Event sent if Float 1 equals Float 2 (within Tolerance)")]
public FsmString guiStyleName;

[Tooltip("The image of the gui content")]
public FsmTexture image;

[Tooltip("The text of the gui content")]
public FsmString text;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The size of the gui content")]
public FsmVector2 size;

public bool everyFrame;

private GUIStyle _style;

GUIContent content;

public override void Reset()
{
image = null;
text = null;
guiStyleName = null;

}

public override void OnGUI()
{
if (_style==null || _style.name !=guiStyleName.Value){
_style = new GUIStyle(guiStyleName.Value);
}
size.Value = _style.CalcSize( new GUIContent(text.Value, image.Value) );

if (!everyFrame)
{
Finish ();
}
}
}
}



bye,

 Jean
Title: Re: GUI CalcSize
Post by: kiriri on July 03, 2012, 01:06:55 PM
woah you managed it afterall? awesome! now I can finally throw away my crappy script which caused nothing but errors :D
Thanks a lot, I didn't think you'd still produce a solution ;)
Title: Re: GUI CalcSize
Post by: jeanfabre on July 04, 2012, 02:51:11 AM
Hi,

 If I didn't it would have meant I simply forgot about it ( brain memory overload... ), in which case please remind me. That's true for other readers that might think: hang on he told me he would do something, and I am still waiting :), so in that case, simply remind me.

bye,

 Jean