Move & Resize UI: Scripts for UI Windows and Objects 5.0 [RELEASED]

Move & Resize UI: Scripts for UI Windows and Objects
Version 5.0

Price: $5

Newest Webplayer Demo and Full Readme

Scale/Anchor Webplayer Demo

Move/Resize Webplayer Demo

These scripts were written specifically for use with mouse controls, so it will unlikely work with other forms of controllers without modification.
These scripts are tested using a single canvas set to Screen Space - Overlay with default settings. Any changes to the canvas’ settings may cause the scripts to not work as intended.

Move & Resize on the Asset Store

Description:

This is a collection of scripts that allow the user to move and resize UI windows and objects in various ways at runtime. For descriptions of the various methods, see the “Included Scripts” section below. They are written for use with Unity’s new UI system. Version 4 completely overhauled most of the existing scripts to use a single script as a main controller.

Version 5 adds limited functionality to canvases not set to Screen Space - Overlay as well as a movement multiplier setting.

Script Features:

  • Simplicity:

They are simply scripts that attach to objects. The only requirement is a version of Unity 4.6.0f1 BETA or newer.

  • No jumping to the cursor:

The object will not jump to center around the cursor. If you begin dragging an object from the corner, your drag will remain at the corner of the object.

  • Move smoothly or by intervals:

You have the options to move and resize objects smoothly or by defined intervals. Smooth is the default method, however, the interval method may be desired if using a grid-based system or if you want easier alignment.

  • Customizable border and inset sizes:

Variable-based thickness of borders and insets for easy customization. Borders are used for resizing. Insets are used for moving. They can easily be configured to work together.

  • Set minimum size:

You can set how small your objects can resize to both vertically and horizontally. They will never shrink so small that they cannot be enlarged again… unless you want them to.

  • Event friendly:

Use in accordance with events to make a window work how you want it to work. Do you want to be able to choose between the smooth and interval methods at runtime? All you need is a button or toggle. Do you want to lock the window in place for now, but unlock it later? A single button is the answer. Do you want to be able to drag your mouse freely in a window without moving anything? A panel with Pointer Enter/Exit events can do the job!

  • Fully commented scripts:

Want to know how the scripts work? Just follow along. It should make it much easier to add onto or modify.

  • Demonstration scenes:

Multiple scenes using the various scripts. See how the scripts work independently and together.

  • Customizable cursors (limited):

Set your own images to be used as custom cursors when the cursor is over a moveable/resizable position.

  • Restrain to screen/parent:

Restrain an object from being moved or resized off the screen or outside of its parent. Completely optional.

  • Single control script:

A new script has been added to control raycasting, custom cursors, and activation of other scripts.

NEW IN VERSION 5

  • Unity 5:

Officially for Unity 5!

  • Movement multiplier:

The ratio of movement or resizing based on the mouse movement can be customized.

Included Scripts:

  • Move:

Moves the scripted object when the mouse is dragged.

  • MoveParent:

Moves the direct parent of the scripted object when the mouse is dragged.

  • MoveOther:

Moves an object that has a distant or no relation to the scripted object when the mouse is dragged. Suggested use is for relations more distant than direct parent-child, though there may be other creative uses.

  • Resize:

Resizes the scripted object when the mouse drags its borders (edges).

  • ResizeParent:

Resizes the direct parent of the scripted object when the mouse is dragged.

  • ResizeOther:

Resizes an object that has a distant or no relation to the scripted object when the mouse is dragged. Suggested use is for relations more distant than direct parent-child, though there may be other creative uses.

  • BringToFront:

Brings the object and its children to the front of the UI overlay by clicking or automatically.
Note: This feature is included in all of the above scripts as well. This script is only needed if an object has no script attached to itself or to its (grand)parent(s), but you still wish to bring the object to the front of the UI overlay.

  • DisableMoveResize:

A script used as a reference to the Move and Resize series of scripts to disable their actions if the object this script is attached to is clicked. It affects only its object, not its children or grandchildren. This script is the suggested method of disabling the other scripts’ actions for simple “mouse over clicks,” though events may be used as a less effective alternative.

  • ScaleHorizontal:

Scales two objects horizontally when the scripted object is dragged. As one gets wider, the other gets thinner.

  • ScaleVertical:

Scales two objects vertically when the scripted object is dragged. As one gets taller, the other gets shorter.

  • Anchor:

Anchors the alignment and/or positioning of one object to the scripted object. User can define the alignment and positioning in the inspector or can use the current alignment and positioning of the object.

  • MaximizeMinimizeRestore:

As the name implies, this script gives the ability to maximize an object to the size of its parent or screen, to minimize it to pre-defined or user-defined positions and sizes, and to restore its original size and position.

  • PushPull:

Allows one object to push another object or its edge then pull it back by defined amounts. Similar to anchoring, but with more versatility.

  • Ignore:

Used as a reference for raycasting. Any object with this script attached will be ignored by a raycast, returning the object that is behind it.

  • UIController:

Controls the raycasting and activation of the other scripts. Also sets the cursor to the correct custom cursor depending on the cursor position.

I’m considering buying this asset, but before that I’d want to make sure whether it works with world space overlay canvases, because that’s what I need it for.

Hello! I apologize for the late reply.

Version 4 is currently in progress of being approved. As soon as it is, I will post an update.

As for a world space canvas, I can say that I’ve never gotten Version 3 to work. Version 4 seems to be hit and miss. So I would definitely not say it works. That is the bad news.

The good news is that the project’s scope has changed. Originally, I intended it as a simple way to move and resize a UI object, so I wrote the scripts to suit that. But now, Version 4 updates it to a much more efficient and effective system. Instead of each script being completely independent, doing all of the work for themselves (which could get very messy), there is now a single script to control the rest.

So after seeing what possibilities Version 4 opens up, I’m hoping to see what I can do to support more canvas settings. I don’t really like to make guarantees, so I won’t say it WILL happen. But with this being my first project, I am very interested in seeing how much I can improve it. It has been an amazing learning experience for me.

Ideally, the main goal is for the scripts to work on any canvas setting. If and when that will happen, I do not know. But that is what I’m working toward.

For a reference, may I ask what your need is specifically? To move/resize UI objects inside of a world space canvas, or to move/resize the actual canvas in world space?

Thank you for the question!

Version 4.0 is live! It’s a big update as far as the way the scripts function.

The main feature is a single control script called UIController. It alone controls raycasting, meaning there should only be a single raycast no matter how many scripts are in play. It also controls what custom cursor is being used at any given point. And finally, it actually enables and disables the dependent scripts, meaning only one Update() is being run each frame unless interacting with the objects with dependent scripts attached.

Just attach the control script to an empty or permanent gameobject, and all other scripts should work as usual. Be sure to set the UIController’s optional settings in the Inspector as you like. “Every Frame” must be checked for custom cursors to work.

Note: Some scripts such as Anchor and PushPull are not dependent upon the UIController script. They will continue to run unless manually disabled. The BringToFront script is semi-dependent on the UIController script; its LateUpdate() will continue to run unless manually disabled.

Version 5.0 is up and running! How appropriate, because it officially works in Unity 5!

A new handy feature is the movement multiplier. If you want just a little mouse movement to move an object a long way to speed things up, if you want a lot of mouse movement to move an object very little to get the details just right, or even if you want to move the mouse one way to make the object move the other (yes, in reverse), this can make is happen.

Also, I added some checks in some of the scripts to help with canvases that are not set to Screen Space - Overlay. I haven’t done thorough testing with those canvas settings, so I would not suggest using them, but if you do, these changes may help. The main changes were made to the Move(Parent/Other) scripts. I would also suggest to never use the basic Resize script for any canvas that is not set to Screen Space - Overlay. If you must resize an object, the ResizeParent/Other scripts are much more dependable, though they do take more time to set up. It’s just a matter of how the scripts detect where the cursor is located.

I wish you much success in your projects!