playMaker

Author Topic: GuiTexture set Size  (Read 7158 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
GuiTexture set Size
« 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.

Code: [Select]
// (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
« Last Edit: May 10, 2013, 12:36:39 PM by Alex Chouls »

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: GuiTexture set Size
« Reply #1 on: May 09, 2013, 10:22:02 PM »
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.
« Last Edit: May 09, 2013, 10:34:07 PM by Saputo »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: GuiTexture set Size
« Reply #2 on: May 09, 2013, 10:42:23 PM »
You could use Float Clamp to clamp the float to a 0-100 range.

https://hutonggames.fogbugz.com/default.asp?W77

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: GuiTexture set Size
« Reply #3 on: May 09, 2013, 11:14:17 PM »
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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GuiTexture set Size
« Reply #4 on: May 10, 2013, 05:51:42 AM »
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

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: GuiTexture set Size
« Reply #5 on: May 10, 2013, 09:23:17 AM »
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
« Last Edit: May 10, 2013, 11:29:49 AM by Saputo »

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: GuiTexture set Size
« Reply #6 on: May 11, 2013, 04:22:54 AM »
Just for curiosity.
Does this action have an (performance) advantage over a "set property" action where i change the inset size?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GuiTexture set Size
« Reply #7 on: May 12, 2013, 03:52:42 AM »
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

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: GuiTexture set Size
« Reply #8 on: May 12, 2013, 07:54:43 AM »
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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GuiTexture set Size
« Reply #9 on: May 13, 2013, 04:48:38 AM »
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