EZ GUI - Place and Scale (Script)

Version 1.2.1 Jan-27-2013

This script will allow you to easily position, scale, and rotate a GUI Texture2D any where on your screen and have it scale according to your current screen resolution.

See it in action Here

Instructions

Setting Up

  1. Create an empty gameObject and name it *GUI ( or what ever your like ).
  2. Apply the FX_GUI_2D script to the new gameObject.
  3. Apply your Texture2D to the “Your Texture” slot in the inspector.
    3a. Apply the Pivot Helper texture to the “Pivot Texture” slot in the inspector.

Moving and Scaling

Any changes made can be done outside of play mode interactively

  1. To interactively move your Texture, make sure the “Interactive” check box is enabled.
  2. Position your texture using the Texture Offset in the inspector. This will move your texture left right up and down.
  3. To scale your texture use the Texture Scale in the inspector. This will increase and decrease the size of your texture.

Basic Rotating

TIP: If your are working with Textures that are not transparent then you can disable the texture, or reduce it’s Alpha in the inspector window to easily see where your pivot point is.

  1. Make sure that Turn On Pivot Helper is enabled in the inspector. This will give you visual feedback of where your texture’s pivot point is located on the screen.
  2. Adjust the pivot’s placement by using the Pivot Offset X , Y in the inspector.
  3. Rotate your texture by using the Rot Angle in the inspector.

Rotating With Transforms

You can use a transform to determine the rotation of your texture. You may want to do this to represent a directional indicator for the player such as a compass or just display in what direction they are facing with a fixed heading. You can do this by:

  1. Add a game asset that you want to drive your textures rotation to the “Your Transforms” slot in the inspector.
  2. Choose which rotation method your want to use. eulerAngles or localEulerAngles.
  3. Choose which Axis of your transform your want to be represented by your texture.

While inside the Unity editor make sure that Interactive is enabled to see the changes while switching from Maximize to window.

Your final code should have a call to update the RefreshGUI on any screen changes, or you can move all calls into an function Update().

Once you get your texture the way you want go ahead and hard code the values into your script.

Enjoy


498552–43669–$FX_GUI_Tools v1.2.1.unitypackage (12.9 KB)

EZ_GUI 1.2

1.(Beta). Supports rotating your texture around a custom pivot point.
This is a beta implement. It only correctly works on a fixed resolution.

  1. Supports editing your texture position, scale, and rotation outside of play mode.

EZ_GUI 1.3a

  1. Rotation now works with scaling and resolution changes.

  2. You can disable your texture to better see where your pivot point is.

You can now see EZ_GUI in action by checking out my Tank WebPlayer. You will see EZ_GUI doing it’s thing on the tank indicator in the bottom left of the screen… The position, scale, and rotation are all controlled by the EZ_GUI script.

See it Here

EZ_GUI 1.4

  1. Added Texture aspect correction ( Adjust this if you need to bring your texture back into shape )
  2. Rotations can be disabled if they are not going to be used.
  3. Code cleaning, and added some comments to the code to help.

EZ_GUI 1.5

  1. Native support in the inspector for a transforms rotational eulerAngle, or localEulerAngle along the X, Y, or Z.
  2. The textures Alpha can now be controlled through the inspector.

With this new release you should be able to do just about anything from within the inspector with little or no coding at all.

The next step is to get a custom Inspector GUI for the script for ease of use.

As all ways i’m interested in your feedback.

EZ_GUI 1.6

  1. Changed the way EulerRotations, LocalEulerRotations, and Axis selections were made. This should fix any issues of having multiple selections at once.

  2. First custom GUI for the inspector.

I apologize for everyone else who read this thread but didn’t give you a response. I think this is a wonderful and much-needed solution and I personally thank you for offering it to us. I hate transforming GUI by hand; you’ve made it easy!

Thanks again and keep up the good work!

Thank you for your response. I’m glad this script can be of use for you in your projects.

I’ve got some more ideas that i thought of last night after i went to bed. I was thinking of setting a limit for the min max rotations and then have those between values be driven by and outside source. An example would be a speedometer 0-80 or something like that. Also a check box to inverse the rotations. If there are any more features you or anyone can think of i would love to hear them.

Nice work, but why are you calling it EZ GUI when theres already a product called EZ GUI?

There is? That sux…

Anouncing a name that script contest… Winner gets a free copy of this free script.

How about “Painless GUI”?
Should I wait by my mailbox for my prize? :heart:

HAHA! Check your mail… Think i’ll name my tools after my screen name. This one will become ForceX GUI Tools or FX GUI Tools for short. The change will become effective in the next release. I’ve just started working on some more additions, once i get it all sorted out and integrated into the editor interface in an effective way i’ll get it posted.

I think your next implementation should have GUI that supports every single resolution (unless its already in and i missed it) Because ive always had a problem trying to make the right formula for a gui that fits in every single res and looks good on all of them. Good luck!

Artimese can you give me an example that would require a rotation input that an Euler or localEuler cant cover that would be used to drive a texture rotation, and i’ll check it out.

Thanks

FX_GUI_2D v1.0

NEW NAME FX_GUI_2D : As pointed out by another member; there is all ready a script named EZ_GUI. So to prevent confusion or problems with the creators of that script the name has been changed but the features have not. In fact more have been added to this release.

New Features:

  1. Invert Rotation - This will set the input rotation value to be an invert. This will effectively reverse the direction of your textures rotation.
  2. Limit Rotations - You can set the min and max rotation angles to Clamp how far your texture can rotate.
  3. Rotation Offset - You can set your starting angle and keep your Rotation Angle at 0. ( May be useful )

FX_GUI_2D v1.0.1

  1. Fixed a problem with the Pivot Offset not working correctly.

Oh man I can use this. Thanks for posting it. I have already wasted hours of painstaking (and painful) close up staring just to get my GUI’s dead on.

Glad it can help you along in your project. Check to make sure you downloaded ver 1.0.1. It corrects an issue with the Pivot Offset not working in std texture edit mode, and may fix problems with the texture loosing it’s center pivot location.

FX_GUI_2D v1.1.0

  1. Added new transform option: Difference Angle. (This will allow your to get the angle difference between two transforms and apply it to your texture.)

This new feature is help full if your want to represent something like a turret thats attached to another moving / rotating object and your camera is free to swing move around the object. This will keep the the rotations relative to there own rotations and not be affected by the camera.

To use Difference Angles apply your second Transform gameObject into the Difference Transform: field at the top of the Inspector, then select Use Difference Angles from the drop down menu under Transform Rotation Options and select an Axis to monitor.