playMaker

Author Topic: How to modify GUITexture Pixel Inset? [SOLVED]  (Read 4251 times)

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 126
    • View Profile
    • MABManZ.com
How to modify GUITexture Pixel Inset? [SOLVED]
« on: October 03, 2011, 02: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?
« Last Edit: October 11, 2011, 10:27:56 PM by alexchouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14342
  • Official Playmaker Support
    • View Profile
Re: How to modify GUITexture Pixel Inset?
« Reply #1 on: October 03, 2011, 10:24:34 PM »
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

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 126
    • View Profile
    • MABManZ.com
Re: How to modify GUITexture Pixel Inset?
« Reply #2 on: October 08, 2011, 12:36:51 PM »
Thanks a lot I'll ask if I have any problems :)