Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: MABManZ on October 03, 2011, 05:13:00 PM

Title: How to modify GUITexture Pixel Inset? [SOLVED]
Post by: MABManZ on October 03, 2011, 05:13:00 PM
I'm trying to set up an analog joystick with PM and can't figure out how to transform the X and Y of the Pixel Inset property on a GUITexture object.

Anyone have a clue?
Title: Re: How to modify GUITexture Pixel Inset?
Post by: jeanfabre on October 04, 2011, 01:24:34 AM
Hi,

 I think it's simply because there is no action yet for this. Until now :)

 I made a custom action where you can set the x and y position of the pixel inset of a gui texture. You can optionnaly decide if you want to increment or use absolute positioning.

 If you need to control the actual rect ( because pixelInset is actually a rect), I can make a custom action where you use a rect, this would give you total control of the pixel inset this way.

If you are having trouble using this custom action, just shout and I'll give you more details.

 Code below ( but just download the file attached and drop it in the PLayMaker/Actions/ folder of your project.

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 Position of the GUITexture attached to a Game Object. Useful for moving GUI elements around.")]
public class SetGUITexturePixelInsetPosition : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(GUITexture))]
public FsmOwnerDefault gameObject;
[RequiredField]
public FsmFloat PixelInsetX;
public FsmFloat PixelInsetY;

public FsmBool AsIncrement;

public bool everyFrame;

public override void Reset()
{
gameObject = null;
PixelInsetX = null;
PixelInsetY = null;
AsIncrement = null;
everyFrame = false;
}

public override void OnEnter()
{
DoGUITexturePixelInsetPosition();

if(!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoGUITexturePixelInsetPosition();
}


void DoGUITexturePixelInsetPosition()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null && go.guiTexture != null)
{
Rect pixelInset = go.guiTexture.pixelInset;

if (AsIncrement.Value == true){
pixelInset.x += PixelInsetX.Value;
pixelInset.y += PixelInsetY.Value;
}else{
pixelInset.x = PixelInsetX.Value;
pixelInset.y = PixelInsetY.Value;
}
go.guiTexture.pixelInset = pixelInset;
}
}
}
}


Bye,

 Jean
Title: Re: How to modify GUITexture Pixel Inset?
Post by: MABManZ on October 08, 2011, 03:36:51 PM
Thanks a lot I'll ask if I have any problems :)