Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on October 11, 2012, 06:14:05 AM
-
Hi,
Following some threads, I think it's time for a convenient action to change the size of a guiTexture. I did a while ago an action to change the inset position, but not its size, so now it's complete.
if you don't want to alter a size, simply set it to 'none' as if you wanted to select a fsm value only don't select any and leave it to none.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUIElement)]
[Tooltip("Sets the Pixel Inset Soze of the GUITexture attached to a Game Object. Useful for sizing GUI elements around.")]
public class SetGUITexturePixelInsetSize : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(GUITexture))]
public FsmOwnerDefault gameObject;
[RequiredField]
public FsmFloat width;
public FsmFloat height;
public bool everyFrame;
public override void Reset()
{
gameObject = null;
width = null;
height = null;
everyFrame = false;
}
public override void OnEnter()
{
DoGUITexturePixelInsetSize();
if(!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoGUITexturePixelInsetSize();
}
void DoGUITexturePixelInsetSize()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null && go.guiTexture != null)
{
Rect pixelInset = go.guiTexture.pixelInset;
if (!width.IsNone)
{
pixelInset.width = width.Value;
}
if (!height.IsNone)
{
pixelInset.height = height.Value;
}
go.guiTexture.pixelInset = pixelInset;
}
}
}
}
bye,
Jean
-
Hey Jean can you make this work for an Int as well?
and is there a way to get the bar when it hit a max float of 100, I have it set to max for 100 and min 0 but it just grows right past it.
if this could be set up for ints it would be awesome, but I need it to no flow past it as well, so maybe add a max limit to it like once it hits the max int value it will stop growing, could just be my scripts though.
-
You could use Float Clamp to clamp the float to a 0-100 range.
https://hutonggames.fogbugz.com/default.asp?W77
-
I tried it just makes the bar stop moving.
if I put it after GUI Texture Set Size it just grows past if in the positive or if it goes to 0 it keeps going more and more negative and grows in the negative way.
-
Hi,
For ints, I would simply convert your int into a float first and then do the math then
as for the overshoot, I can't really see what's wrong in your state stack of actions, but as Alex suggested it, clamping is the way to go.
maybe 100 is not the right value. Double check manually what is the max inset values you should set it for, it's usually helping, you may have some scaling, or indeed your max pixel size is not 100.
also you might confused the "health" value, with the actual "width" of your texture.
Bye,
Jean
-
the width of my texture is set to 180, I wanted the Max Stamina to be 100,...
Ok after a few hours have gone by, I went and re looked at my Stamina Regen system, yea the clamp in there wasn't set to every frame so it would just keep going, sob LOL it all works fine now. I feel so dumb lol
-
Just for curiosity.
Does this action have an (performance) advantage over a "set property" action where i change the inset size?
-
Hi,
I am not sure at all about performance differences. I would think it doesn't make any difference, but "Set Property" is using a specificy system in c# and it can create problems on mobile, so I tend to prefer using actions when I know I am targeting mobile.
bye,
Jean
-
Hi Jean,
thanks for the information.
Im using some "set property" actions and im aiming for mobile. Yet i didnt had any problems but i tested only on two android phones yet.
Can you give me a bit more information about the problems that could arise so i could watch out for them?
Thanks,
Matthias
-
Hi,
I am not sure myself, I only tested on IOS, don't know about android, it might work perfectly fine on android.
bye,
Jean