Skip to content

Commit

Permalink
close #13; Preview soft mask buffer in inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Dec 17, 2018
1 parent 74b69ba commit 5cb2a86
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ namespace Coffee.UIExtensions.Editors
[CanEditMultipleObjects]
public class SoftMaskEditor : Editor
{
const string k_PrefsPreview = "SoftMaskEditor_Preview";
static readonly List<Graphic> s_Graphics = new List<Graphic> ();
static bool s_Preview;

private void OnEnable ()
{
s_Preview = EditorPrefs.GetBool (k_PrefsPreview, false);
}

public override void OnInspectorGUI ()
{
Expand Down Expand Up @@ -43,6 +50,22 @@ public override void OnInspectorGUI ()
GUILayout.EndVertical ();
GUILayout.EndHorizontal ();
}

// Preview buffer.
GUILayout.BeginHorizontal (EditorStyles.helpBox);
if (s_Preview != (s_Preview = EditorGUILayout.ToggleLeft ("Preview Buffer", s_Preview, GUILayout.MaxWidth (EditorGUIUtility.labelWidth))))
{
EditorPrefs.SetBool (k_PrefsPreview, s_Preview);
}
if (s_Preview)
{
var tex = current.softMaskBuffer;
var wtdth = tex.width * 64 / tex.height;
EditorGUI.DrawPreviewTexture (GUILayoutUtility.GetRect (wtdth, 64), tex, null, ScaleMode.ScaleToFit);
Repaint ();
}
GUILayout.FlexibleSpace ();
GUILayout.EndHorizontal ();
}


Expand Down
21 changes: 8 additions & 13 deletions Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,14 @@ void UpdateMaskTexture()
/// </summary>
void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = int.Parse(res[0]);
h = int.Parse(res[1]);
}
else
#endif
{
w = Screen.width;
h = Screen.height;
}
#if UNITY_EDITOR
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = int.Parse(res[0]);
h = int.Parse(res[1]);
#else
w = Screen.width;
h = Screen.height;
#endif

if (rate == DesamplingRate.None)
return;
Expand Down

0 comments on commit 5cb2a86

Please sign in to comment.