[Scripts] Useful 4.6 Scripts Collection

I decided to make this thread after I stumbled upon Riolis’ window script. Please contribute any scripts that you think are useful when working with 4.6 UI. Also, don’t forget about the cool scripts included in the UI Example Project, but I won’t be listing them here.

  • UIWindowBase by Riolis - create draggable windows in 1 click - just drag this script to a panel with your window. Approved by Tim C :sunglasses:
  • ReturnKeyTriggersButton - if put on an input field, makes pressing a Return key highlight and trigger a specified button. The highlight is optional.
  • TabNavigation - a temporary solution to Tab key currently not triggering the navigation to the next element. Should be placed on a persistent object in the scene, will trigger on all GUI elements. Works with “Select On Down” and all navigation types. By me, as is the previous script.
  • RayCastMask by senritsu - a must if you want to create a round button or a button of any other shape that’s not rect. Change the button sprite texture to Advanced and check “Read/Write Enabled”, then just add this script to your button.
  • ComboBox by jbooth - creates selection/dropdown lists for you! Especially useful since 4.6 won’t have selection lists at the time of the release. Much like the official controls, it can be styled without any coding. I took the liberty to put the files in a .unitypackage for those who prefer it this way. Screenshot | Forum thread
  • uGUITools by Senshi - after you’ve resized a GUI element, positioning anchors to corners precisely can be difficult. With this script you can automatically position them from the menu or by pressing ctrl + [ , and do the reverse (corners to anchors) with ctrl + ] . Place the script in the Editor folder.
  • Interactable Text by Breyer - lets you add clickable links to your text! Instructions | Gif explanation
  • Accordion Type Layout by ChoMPi - if you’re not familiar with accordion effect, take a look at the example video. Also has a collapsible version. Thread
  • RTS Style Selection Box by Korindian - the title is self-explanatory :slight_smile: Thread
  • NicerOutline and BestFitOutline by me - a modified version of built-in Outline effect, but with a radius that scales along with Best Fit. Just use in place of the default outline, the radius that you set will be applied to the max font size, it will scale down from it when a smaller font is used. Screenshot NicerOutline also fixes the “holes” that Outline sometimes has - screenshot
  • Canvas Groups Activator by dakka - editor window, show and hide canvas groups
  • CurvedText by Breyer - lets you position the test on a curve for a cool effect!
  • Gradient Fill by Breyer - with a lot of possibilities like vertical, horizontal and diagonal gradient direction + global/local mode
  • ColorPicker by judah4 Screenshot

1746852–110354–UIWindowBase.cs (476 Bytes)
1746852–110359–ReturnKeyTriggersButton.cs (896 Bytes)
1746852–110360–TabNavigation.cs (865 Bytes)
1746852–110369–ComboBox by jbooth.unitypackage (15.2 KB)
1746852–110370–RaycastMask.cs (3.54 KB)

42 Likes

I just added my stylable combo box to this thread:

3 Likes

This is another good one (see second last post):

2 Likes

Thanks! Added both scripts to the list.

The screenshot of the combo box is the “before” picture - the after one doesn’t have all that junk in the hierarchy…

Are Editor scripts allowed on the list? I had an annoyance in that, after positioning a UI element, I couldn’t easily/ nicely/ precisely move the anchors to the element’s corners. To that end I created a simple Editor script that adds a uGUI menubar item, with “Anchors to Corners” mapped to cmd+[ and “Corners to Anchors” mapped to cmd+]. Perhaps someone else will find this useful as well!

EDIT: Updated version posted here.

1747611–110408–uGUITools.cs (1015 Bytes)

14 Likes

Sure, added it to the list. Thanks!

I’ve reached the max number of attachments in the first post, so gonna be adding the scripts as links to your attachments from now on.

Some extensions for adding a listener to an EventTrigger and for setting the currently selected object : Unity3D new UI convienience extensions · GitHub

It would be nice to get a sample for how to get to the built in Images, or a way to initiate the default ui components with their graphics.

This works as long as the images are already in the scene somewhere:

void GetImages() {
        var images = Resources.FindObjectsOfTypeAll<Image>();
        foreach( var image in images ) {
            string name = image.name;
            if( name.Contains( "Button" ) ) {
                buttonImage = image;
                Debug.Log( "Button set" );
            } else if( name == "Panel" ) {
                panelImage = image;
                Debug.Log( "Panel set" );
            } else {
                Debug.Log( name );
            }
        }
    }

So the images live in the DefaultResourcesExtra package. What this means is that they only get included in a build if they are referenced by a scene / prefab that is included in the build. So if you want them included include them in some scene and then include that scene in the build… even if it is never used.

1 Like

Is there a way to load/retrieve them while within the editor? Or a way to instantiate the default properties for scripts.
Creating a button currently involves a prefab or assigning a texture before hand. Creating custom controls would be easier to share / create if the workflow for adding them to the UI is the same.

What I / we need is a way for the rightclick on gameobject in hierarchy, add UI / CustomControl to work identical to say UI / Button, where it populates the field with initial values. It’s fine if we have to include some Editor only code here, it’s just so that we can share a script instead of a whole package that just works out of the box without needing to assign some base textures manually.

As an attribute this would rock
[DefaultSprite(“Button”)]
public Sprite image;

Just wanted to say thanks to Senshi for this awesome “anchors to corners” solution. It allows to position anchors for stretching even when the parent rect is smaller than the child rect - totally impossible by default unless i missed something.

This results in anchor values that are < 0 and >1 and they don’t display correctly but they seem to work so far, nice!

1 Like

Ha, I found out about that unintended side-effect after posting as well! I was originally going to fix it as it doesn’t seem very stable/ sustainable, but I hadn’t gotten around to it yet. It also seems to save and load just fine, so… magic? Anyway, thanks for the thanks! =)

Canvas Groups Activator editor window, show and hide canvas groups.

Mod from Yilmaz Kiymaz’s editor scripts presentation at Unite 2013

1752415–110821–CanvasGroupActivator.cs (2.51 KB)

Finally i decided to finish project with interactable text. check lighting scene in package and last sentence on screen. this is very little presentation but there is too late for more. maybe later i will add more explanation. I hope this is bug free (i bug hunted a lot) but i think it still could be optimized (i made some already but not 100%). If anyone need extends or optimize this i added some comment to code but this isnt very professional.

maybe i will improve this but as Pro (paid version)

NOTE: this not support fade-in/out like button and animation nor spriteswap (sprite of course isnt supported for text while animation will be added later if it is possible but probably as Pro)

if u need link in text type link if u need dynamic color then type classic before WARNING! use always html tag before link or u maybe see some strange shape in interactable area and color must be without “”, with 8 length color declaration (never 6) and always first before link like <color=#ffffffff>link. This is due to optimization and no source code access constraint

to install it - FIRST download unity ui example project into your project, delete old Lighting scene then download my package and open Lighting scene

Enjoy!

1753530–110913–InteractableText.unitypackage (25.2 KB)
1805552–115181–TextWithEvents.cs (8.75 KB)
1753530–115183–TextButton.cs (4.42 KB)
1753530–115184–TextClassHandler.cs (1.53 KB)
1753530–115185–TexButtonHandler.cs (1.1 KB)

6 Likes

I created gif which explain how my package should look and behave in play mode

1754106--110961--activetext1.gif

BTW i forgot to add that child button for text should have identical rect to parent (and recommend adjust anchors to parents corner

@Melang

Exactly

2 Likes

Just tested your package and it works great, thanks for sharing this with the community. With this, everyone can start making WoW-style chat links, and ingame encyclopedias. :slight_smile:

Here’s a modified Outline script, its radius scales along with Best Fit font scale. By default, when outlined text gets scaled down, its outline radius remains the same, and can look too bold, this fixes it.

1755685–111109–BestFitOutline.cs (1.57 KB)

4 Likes

Some excellent additions here at the moment. I can’t wait for the source to be released and see where the community helps take uGUI =).

@Senshi - thank you :slight_smile:

1 Like