From 5ed1e48cb2c4bc41ec165da0212887de9935d774 Mon Sep 17 00:00:00 2001 From: "valtain@gmail.com" Date: Sat, 24 Dec 2016 05:18:01 +0900 Subject: [PATCH] Recomit softmask fix --HG-- branch : develop_5.3 --- Scripts/Effects/SoftMaskScript.cs | 189 ++++++------------------------ Shaders/SoftMaskShader.shader | 49 ++++---- Shaders/SoftMaskShaderText.shader | 140 +--------------------- 3 files changed, 61 insertions(+), 317 deletions(-) diff --git a/Scripts/Effects/SoftMaskScript.cs b/Scripts/Effects/SoftMaskScript.cs index 080462b..2d13b56 100644 --- a/Scripts/Effects/SoftMaskScript.cs +++ b/Scripts/Effects/SoftMaskScript.cs @@ -8,15 +8,12 @@ namespace UnityEngine.UI.Extensions public class SoftMaskScript : MonoBehaviour { Material mat; - Canvas canvas; + Canvas cachedCanvas= null; [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; @@ -30,27 +27,12 @@ namespace UnityEngine.UI.Extensions [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")] + [Tooltip("If Mask Scals 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; + Vector3[] worldCorners = new Vector3[4]; + Vector2 maskOffset = Vector2.zero; + Vector2 maskScale = Vector2.one; bool isText = false; @@ -59,167 +41,68 @@ namespace UnityEngine.UI.Extensions { myRect = GetComponent(); - if (!MaskArea) + if (MaskArea == null) { MaskArea = myRect; } - if (GetComponent() != null) - { - mat = new Material(Shader.Find("UI Extensions/SoftMaskShader")); - GetComponent().material = mat; - } - - if (GetComponent()) + var text = GetComponent(); + if (text != null) { isText = true; mat = new Material(Shader.Find("UI Extensions/SoftMaskShaderText")); - GetComponent().material = mat; - - GetCanvas(); + text.material = mat; + cachedCanvas = text.canvas; // 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