/// Credit NemoKrad (aka Charles Humphrey) /// Sourced from - http://www.randomchaos.co.uk/SoftAlphaUIMask.aspx namespace UnityEngine.UI.Extensions { [ExecuteInEditMode] [AddComponentMenu("UI/Effects/Extensions/SoftMaskScript")] public class SoftMaskScript : MonoBehaviour { Material mat; Canvas canvas; [Tooltip("The area that is to be used as the container.")] public RectTransform MaskArea; RectTransform myRect; [Tooltip("A Rect Transform that can be used to scale and move the mask - Does not apply to Text UI Components being masked")] public RectTransform maskScalingRect; [Tooltip("Texture to be used to do the soft alpha")] public Texture AlphaMask; [Tooltip("At what point to apply the alpha min range 0-1")] [Range(0, 1)] public float CutOff = 0; [Tooltip("Implement a hard blend based on the Cutoff")] public bool HardBlend = false; [Tooltip("Flip the masks alpha value")] public bool FlipAlphaMask = false; [Tooltip("If Mask Scaling Rect is given and this value is true, the area around the mask will not be clipped")] public bool DontClipMaskScalingRect = false; [Tooltip("If set to true, this mask is applied to all child Text and Graphic objects belonging to this object.")] public bool CascadeToALLChildren; Vector3[] worldCorners; Vector2 AlphaUV; Vector2 min; Vector2 max = Vector2.one; Vector2 p; Vector2 siz; Vector2 tp = new Vector2(.5f, .5f); bool MaterialNotSupported; // UI items like toggles, we can stil lcascade down to them though :) Rect maskRect; Rect contentRect; Vector2 centre; bool isText = false; // Use this for initialization void Start() { myRect = GetComponent(); if (!MaskArea) { MaskArea = myRect; } if (GetComponent() != null) { mat = new Material(Shader.Find("UI Extensions/SoftMaskShader")); GetComponent().material = mat; } if (GetComponent()) { isText = true; mat = new Material(Shader.Find("UI Extensions/SoftMaskShaderText")); GetComponent().material = mat; GetCanvas(); // For some reason, having the mask control on the parent and disabled stops the mouse interacting // with the texture layer that is not visible.. Not needed for the Image. if (transform.parent.GetComponent