Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- using System.Collections;
- using System.IO;
- public class AnchorToCorners : MonoBehaviour
- {
- [MenuItem("Custom Editor Tools/Anchors to Corners %[")]
- static void AnchorsToCorners()
- {
- RectTransform t = Selection.activeTransform as RectTransform;
- RectTransform pt = Selection.activeTransform.parent as RectTransform;
- if (t == null || pt == null)
- return;
- Vector2 newAnchorsMin = new Vector2(t.anchorMin.x + t.offsetMin.x / pt.rect.width,
- t.anchorMin.y + t.offsetMin.y / pt.rect.height);
- Vector2 newAnchorsMax = new Vector2(t.anchorMax.x + t.offsetMax.x / pt.rect.width,
- t.anchorMax.y + t.offsetMax.y / pt.rect.height);
- t.anchorMin = newAnchorsMin;
- t.anchorMax = newAnchorsMax;
- t.offsetMin = t.offsetMax = new Vector2(0, 0);
- }
- [MenuItem("Custom Editor Tools/Corners to Anchors %]")]
- static void CornersToAnchors()
- {
- RectTransform t = Selection.activeTransform as RectTransform;
- if (t == null)
- return;
- t.offsetMin = t.offsetMax = new Vector2(0, 0);
- }
- [MenuItem("Custom Editor Tools/Add Padding")]
- static void AddPadding()
- {
- foreach (var activeTransform in Selection.transforms) {
- RectTransform t = activeTransform as RectTransform;
- if (t == null)
- return;
- t.anchorMin = new Vector2(0, 0);
- t.anchorMax = new Vector2(1, 1);
- var padding = 5;
- t.offsetMin = new Vector2(padding, padding);
- t.offsetMax = new Vector2(-padding, -padding);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement