using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace NEG.Utils.Editor.ComponentsAdditionalItems { public static class RectTransformSetBasedOnImage { [MenuItem("CONTEXT/RectTransform/Set as inside of Image", false, 2000)] public static void SetFillBasedOnImage(MenuCommand command) { var transform = (RectTransform)command.context; if (!transform.TryGetComponent(out Image image)) return; transform.anchorMin = Vector2.zero; transform.anchorMax = Vector2.one; transform.offsetMin = new Vector2(-image.sprite.border.x, -image.sprite.border.y); transform.offsetMax = new Vector2(image.sprite.border.z, image.sprite.border.w); } } }