Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by cjdev · Sep 24, 2015 at 09:01 PM · guirecttransform

Shortcut to set anchors at corners?

When working with GUI elements I most often find myself setting the anchors (the white arrows pointing inwards) to the corners of the element (the blue dots, not the edge of the screen) so that it scales with screen size. I've seen the shortcuts for a bunch of other anchor settings in the RectTransform so I was wondering, is there a shortcut to do this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by appicarts · Sep 25, 2015 at 07:21 AM

@cjdev go here uGUITools, search for uGUITools, Anchors to corners is the very first function plus there are meny more..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Gwom · Oct 20, 2016 at 08:41 AM

Bit of an old thread but i have added Stretch To Parent too (as found i was doing this often) - and contains a shortcut to basically resetting the object to stretch to parent.

         [MenuItem("uGUI/Stretch To Parent %,")]
         static void StretchToParent()
         {
             foreach (Transform transform in Selection.transforms)
             {
                 RectTransform t = transform as RectTransform;
 
                 if (t == null) return;
 
                 t.anchorMin = new Vector2(0, 0);
                 t.anchorMax = new Vector2(1, 1);
                 t.offsetMin = t.offsetMax = new Vector2(0, 0);
             }
         }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saschandroid · Oct 20, 2016 at 10:26 AM 0
Share

Doesn't the button in the inspector (anchor presets->bottom right + alt) do the same?

avatar image Gwom saschandroid · Oct 21, 2016 at 07:48 AM 0
Share

Good tip too!

avatar image
0

Answer by theforgot3n1 · Jan 29 at 01:04 PM

Gwoms answer is great. I created an editor script out of it that also has a default shortcut of Shift+Q.

 using UnityEditor;
 using UnityEngine;
 
 public class EditorStretchToParent : Editor
 {
     [MenuItem("uGUI/Stretch To Parent #q")]
     static void StretchToParent()
     {
         foreach (Transform transform in Selection.transforms)
         {
             RectTransform t = transform as RectTransform;
 
             if (t == null) return;
 
             t.anchorMin = new Vector2(0, 0);
             t.anchorMax = new Vector2(1, 1);
             t.offsetMin = t.offsetMax = new Vector2(0, 0);
         }
     }
 }

You can change the default shortcut by changing the "'#q" in the MenuItem string.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Good way to scale 3D GameObjects in a Canvas (Screen Space - Camera)? 1 Answer

Calculate pixel size of stretched RectTransform in editor 0 Answers

Move UI object to center of screen while maintaining its parenting 2 Answers

RectTransform Pivot Point in the new UI? 1 Answer

unity3d new UI - spacing in Scrollable items does not scale proportionally. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges