Update SoftMaskAlpha with new "fix"
Patched UISelectableExtension from issue #47 Added new UI Polygon control --HG-- branch : develop_5.2pull/413/head
parent
077fbcbc51
commit
38650cc536
|
@ -30,6 +30,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
[Tooltip("Flip the masks alpha value")]
|
[Tooltip("Flip the masks alpha value")]
|
||||||
public bool FlipAlphaMask = false;
|
public bool FlipAlphaMask = false;
|
||||||
|
|
||||||
|
[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;
|
||||||
|
|
||||||
Vector3[] worldCorners;
|
Vector3[] worldCorners;
|
||||||
|
|
||||||
Vector2 AlphaUV;
|
Vector2 AlphaUV;
|
||||||
|
@ -173,6 +176,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
mat.SetTexture("_AlphaMask", AlphaMask);
|
mat.SetTexture("_AlphaMask", AlphaMask);
|
||||||
mat.SetInt("_FlipAlphaMask", FlipAlphaMask ? 1 : 0);
|
mat.SetInt("_FlipAlphaMask", FlipAlphaMask ? 1 : 0);
|
||||||
|
|
||||||
|
mat.SetInt("_NoOuterClip", DontClipMaskScalingRect && maskScalingRect != null ? 1 : 0);
|
||||||
|
|
||||||
if (!isText) // No mod needed for Text
|
if (!isText) // No mod needed for Text
|
||||||
mat.SetVector("_AlphaUV", AlphaUV);
|
mat.SetVector("_AlphaUV", AlphaUV);
|
||||||
|
|
||||||
|
|
|
@ -82,9 +82,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
return vbo;
|
return vbo;
|
||||||
}
|
}
|
||||||
protected override void OnPopulateMesh(VertexHelper vh)
|
protected override void OnPopulateMesh(Mesh toFill)
|
||||||
{
|
{
|
||||||
vh.Clear();
|
toFill.Clear();
|
||||||
|
var vbo = new VertexHelper(toFill);
|
||||||
|
|
||||||
Vector2 prevX = Vector2.zero;
|
Vector2 prevX = Vector2.zero;
|
||||||
Vector2 prevY = Vector2.zero;
|
Vector2 prevY = Vector2.zero;
|
||||||
Vector2 uv0 = new Vector2(0, 0);
|
Vector2 uv0 = new Vector2(0, 0);
|
||||||
|
@ -129,7 +131,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
prevX = pos1;
|
prevX = pos1;
|
||||||
prevY = pos2;
|
prevY = pos2;
|
||||||
vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
|
vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vbo.currentVertCount > 3)
|
||||||
|
{
|
||||||
|
vbo.FillMesh(toFill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fcd1b8078a416f844b695454a4358409
|
||||||
|
timeCreated: 1450200166
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -2,6 +2,7 @@
|
||||||
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1796783
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1796783
|
||||||
/// Extended to include a HELD state that continually fires while the button is held down.
|
/// Extended to include a HELD state that continually fires while the button is held down.
|
||||||
/// Refactored so it can be added to any button and expose the events in the editor.
|
/// Refactored so it can be added to any button and expose the events in the editor.
|
||||||
|
/// Unselect fix by @Sfyne
|
||||||
|
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
@ -108,5 +109,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
Debug.Log("Control Held");
|
Debug.Log("Control Held");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Fixed UISelectableExtension inactive bug (if gameObject becomes inactive while button is held down it never goes back to _pressed = false)
|
||||||
|
void OnDisable ()
|
||||||
|
{
|
||||||
|
_pressed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
[MaterialToggle]
|
[MaterialToggle]
|
||||||
_HardBlend("HardBlend",Float) = 0
|
_HardBlend("HardBlend",Float) = 0
|
||||||
_FlipAlphaMask("Flip Alpha Mask",int) = 0
|
_FlipAlphaMask("Flip Alpha Mask",int) = 0
|
||||||
|
_NoOuterClip("Outer Clip",int) = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
SubShader
|
SubShader
|
||||||
|
@ -43,6 +44,8 @@
|
||||||
WriteMask[_StencilWriteMask]
|
WriteMask[_StencilWriteMask]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOD 0
|
||||||
|
|
||||||
Cull Off
|
Cull Off
|
||||||
Lighting Off
|
Lighting Off
|
||||||
ZWrite Off
|
ZWrite Off
|
||||||
|
@ -120,13 +123,14 @@
|
||||||
float _CutOff;
|
float _CutOff;
|
||||||
|
|
||||||
bool _HardBlend = false;
|
bool _HardBlend = false;
|
||||||
|
bool _NoOuterClip = false;
|
||||||
|
|
||||||
fixed4 frag(v2f IN) : SV_Target
|
fixed4 frag(v2f IN) : SV_Target
|
||||||
{
|
{
|
||||||
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
|
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
|
||||||
|
|
||||||
// Do we want to clip the image to the Mask Rectangle?
|
// Do we want to clip the image to the Mask Rectangle?
|
||||||
if (IN.texcoord.x < _Min.x || IN.texcoord.x > _Max.x || IN.texcoord.y < _Min.y || IN.texcoord.y > _Max.y) // Yes we do
|
if (!_NoOuterClip && (IN.texcoord.x < _Min.x || IN.texcoord.x > _Max.x || IN.texcoord.y < _Min.y || IN.texcoord.y > _Max.y)) // Yes we do
|
||||||
color.a = 0;
|
color.a = 0;
|
||||||
else // It's in the mask rectangle, so apply the alpha of the mask provided.
|
else // It's in the mask rectangle, so apply the alpha of the mask provided.
|
||||||
{
|
{
|
||||||
|
@ -143,7 +147,8 @@
|
||||||
if (_FlipAlphaMask == 1)
|
if (_FlipAlphaMask == 1)
|
||||||
a = 1 - a;
|
a = 1 - a;
|
||||||
|
|
||||||
color.a = a;
|
if(!(IN.texcoord.x < _Min.x || IN.texcoord.x > _Max.x || IN.texcoord.y < _Min.y || IN.texcoord.y > _Max.y))
|
||||||
|
color.a *= a;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_UseClipRect)
|
if (_UseClipRect)
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
float _Value;
|
float _Value;
|
||||||
int _LeftToRight;
|
int _LeftToRight;
|
||||||
|
|
||||||
bool _HardBlend = false;
|
int _HardBlend = false;
|
||||||
|
|
||||||
int _FlipAlphaMask = 0;
|
int _FlipAlphaMask = 0;
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@
|
||||||
float2 _Mul;
|
float2 _Mul;
|
||||||
|
|
||||||
float _CutOff;
|
float _CutOff;
|
||||||
|
int _NoOuterClip;
|
||||||
|
|
||||||
fixed4 frag(v2f IN) : SV_Target
|
fixed4 frag(v2f IN) : SV_Target
|
||||||
{
|
{
|
||||||
|
@ -134,6 +135,7 @@
|
||||||
else // It's in the mask rectangle, so apply the alpha of the mask provided.
|
else // It's in the mask rectangle, so apply the alpha of the mask provided.
|
||||||
{
|
{
|
||||||
float a = tex2D(_AlphaMask, (IN.worldPosition2.xy - _Max) / (_Max-_Min)).a;
|
float a = tex2D(_AlphaMask, (IN.worldPosition2.xy - _Max) / (_Max-_Min)).a;
|
||||||
|
|
||||||
if (a <= _CutOff)
|
if (a <= _CutOff)
|
||||||
a = 0;
|
a = 0;
|
||||||
else
|
else
|
||||||
|
@ -145,7 +147,8 @@
|
||||||
if (_FlipAlphaMask == 1)
|
if (_FlipAlphaMask == 1)
|
||||||
a = 1 - a;
|
a = 1 - a;
|
||||||
|
|
||||||
color.a = a * color.a;
|
if(!(IN.worldPosition2.x <= _Min.x || IN.worldPosition2.x >= _Max.x || IN.worldPosition2.y <= _Min.y || IN.worldPosition2.y >= _Max.y))
|
||||||
|
color *= a;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_UseClipRect)
|
if (_UseClipRect)
|
||||||
|
|
Loading…
Reference in New Issue