uGUI UI, what is the best way to surround an element with anchors? how to move a UI element with anchors attached?

Both questions have to do with the anchor system in the new GUI UI in 4.6.

I find it very usefull to surround my UI element with anchors, as it means that it will keep its relevant size compared to its parent. However there is no actual shortcut for doing so and it requires me to manually place the anchors around the UI element each time, many times a day.

I find the surrounding anchors constalation the most common by far, so there should be a shortcut for it.

The second thing that I do is move UI elements around. Is there a way to move the anchors (surrounding) with them? I know if I hold shift and move an anchor it moves the element, But I could reallly use the other feature which again I can’t find.

Apparently there is a place where all the cool kids go to. There is a script there called uGUITools written by senshi. Follow the instructions.

This is his code with variables renamed for clarity.

		RectTransform myTransform = transform as RectTransform;
		RectTransform parentTransform = transform.parent as RectTransform;
		Vector2 newAnchorsMin = new Vector2(myTransform.anchorMin.x + myTransform.offsetMin.x / parentTransform.rect.width,
		                                    myTransform.anchorMin.y + myTransform.offsetMin.y / parentTransform.rect.height);
		Vector2 newAnchorsMax = new Vector2(myTransform.anchorMax.x + myTransform.offsetMax.x / parentTransform.rect.width,
		                                    myTransform.anchorMax.y + myTransform.offsetMax.y / parentTransform.rect.height);

		myTransform.anchorMin = newAnchorsMin;
		myTransform.anchorMax = newAnchorsMax;
		myTransform.offsetMin = myTransform.offsetMax = new Vector2(0, 0);

What this does is basically repositions the anchors acording to the current anchors position and the offsets. and then sets the offsets to “Vector2(0, 0)” so the element would fit exactly where the anchors are.

I use this code as an extension to the editor workflow. But I believe it could also work dinamically, not tested though.