Skip to content

Commit

Permalink
1.0.0-preview.13
Browse files Browse the repository at this point in the history
# [1.0.0-preview.13](mob-sakai/SoftMaskForUGUI@v1.0.0-preview.12...v1.0.0-preview.13) (2020-10-01)

### Bug Fixes

* screen resolution in full screen mode is incorrect ([39e3084](mob-sakai@39e3084))
  • Loading branch information
semantic-release-bot committed Oct 1, 2020
1 parent db266a8 commit 7317708
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.0.0-preview.13](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.12...v1.0.0-preview.13) (2020-10-01)


### Bug Fixes

* screen resolution in full screen mode is incorrect ([39e3084](https://github.com/mob-sakai/SoftMaskForUGUI/commit/39e3084ec840293f2ad461f50d51eeafe66cbebf))

# [1.0.0-preview.12](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.11...v1.0.0-preview.12) (2020-09-28)


Expand Down
56 changes: 34 additions & 22 deletions Scripts/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.Serialization;
using UnityEngine.UI;
using Object = UnityEngine.Object;

Expand All @@ -14,9 +15,9 @@ namespace Coffee.UISoftMask
public class SoftMask : Mask, IMeshModifier
{
/// <summary>
/// Desampling rate.
/// Down sampling rate.
/// </summary>
public enum DesamplingRate
public enum DownSamplingRate
{
None = 0,
x1 = 1,
Expand Down Expand Up @@ -70,8 +71,8 @@ public enum DesamplingRate
private bool _hasStencilStateChanged = false;


[SerializeField, Tooltip("The desampling rate for soft mask buffer.")]
private DesamplingRate m_DesamplingRate = DesamplingRate.x1;
[FormerlySerializedAs("m_DesamplingRate")] [SerializeField, Tooltip("The down sampling rate for soft mask buffer.")]
private DownSamplingRate m_DownSamplingRate = DownSamplingRate.x1;

[SerializeField, Range(0, 1), Tooltip("The value used by the soft mask to select the area of influence defined over the soft mask's graphic.")]
private float m_Softness = 1;
Expand All @@ -93,15 +94,15 @@ public enum DesamplingRate
private bool m_IgnoreSelfStencil;

/// <summary>
/// The desampling rate for soft mask buffer.
/// The down sampling rate for soft mask buffer.
/// </summary>
public DesamplingRate desamplingRate
public DownSamplingRate downSamplingRate
{
get { return m_DesamplingRate; }
get { return m_DownSamplingRate; }
set
{
if (m_DesamplingRate == value) return;
m_DesamplingRate = value;
if (m_DownSamplingRate == value) return;
m_DownSamplingRate = value;
hasChanged = true;
}
}
Expand Down Expand Up @@ -182,7 +183,7 @@ public RenderTexture softMaskBuffer

// Check the size of soft mask buffer.
int w, h;
GetDesamplingSize(m_DesamplingRate, out w, out h);
GetDownSamplingSize(m_DownSamplingRate, out w, out h);
if (_softMaskBuffer && (_softMaskBuffer.width != w || _softMaskBuffer.height != h))
{
ReleaseRt(ref _softMaskBuffer);
Expand Down Expand Up @@ -470,7 +471,7 @@ protected override void OnValidate()
/// <summary>
/// Update all soft mask textures.
/// </summary>
static void UpdateMaskTextures()
private static void UpdateMaskTextures()
{
Profiler.BeginSample("UpdateMaskTextures");
foreach (var sm in s_ActiveSoftMasks)
Expand Down Expand Up @@ -552,7 +553,7 @@ static void UpdateMaskTextures()
#if UNITY_EDITOR
var w = s_PreviousWidth;
var h = s_PreviousHeight;
GetDesamplingSize(DesamplingRate.None, out s_PreviousWidth, out s_PreviousHeight);
GetDownSamplingSize(DownSamplingRate.None, out s_PreviousWidth, out s_PreviousHeight);
if (w != s_PreviousWidth || h != s_PreviousHeight)
{
Canvas.ForceUpdateCanvases();
Expand Down Expand Up @@ -670,20 +671,31 @@ private void UpdateMaskTexture()
}

/// <summary>
/// Gets the size of the desampling.
/// Gets the size of the down sampling.
/// </summary>
private static void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
private static void GetDownSamplingSize(DownSamplingRate rate, out int w, out int h)
{
#if UNITY_EDITOR
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = Mathf.Max(64, int.Parse(res[0]));
h = Mathf.Max(64, int.Parse(res[1]));
#else
w = Screen.width;
h = Screen.height;
if (!Application.isPlaying)
{
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = Mathf.Max(64, int.Parse(res[0]));
h = Mathf.Max(64, int.Parse(res[1]));
}
else
#endif
if (Screen.fullScreenMode == FullScreenMode.Windowed)
{
w = Screen.width;
h = Screen.height;
}
else
{
w = Screen.currentResolution.width;
h = Screen.currentResolution.height;
}

if (rate == DesamplingRate.None)
if (rate == DownSamplingRate.None)
return;

var aspect = (float) w / h;
Expand All @@ -702,7 +714,7 @@ private static void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
/// <summary>
/// Release the specified obj.
/// </summary>
/// <param name="obj">Object.</param>
/// <param name="tmpRT">Object.</param>
private static void ReleaseRt(ref RenderTexture tmpRT)
{
if (!tmpRT) return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.coffee.softmask-for-ugui",
"displayName": "UI Soft Mask",
"description": "UI Soft Mask is a smooth masking component for Unity UI (uGUI) elements.\nBy using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.",
"version": "1.0.0-preview.12",
"version": "1.0.0-preview.13",
"unity": "2017.1",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 7317708

Please sign in to comment.