From 5cb2a868dfaed6467a43e37ec15c9f4db75f72fe Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sun, 16 Dec 2018 14:29:59 +0900 Subject: [PATCH] close #13; Preview soft mask buffer in inspector --- .../Scripts/Editor/SoftMaskEditor.cs | 23 +++++++++++++++++++ .../SoftMaskForUGUI/Scripts/SoftMask.cs | 21 +++++++---------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs index f81cb45..64543ea 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs @@ -15,7 +15,14 @@ namespace Coffee.UIExtensions.Editors [CanEditMultipleObjects] public class SoftMaskEditor : Editor { + const string k_PrefsPreview = "SoftMaskEditor_Preview"; static readonly List s_Graphics = new List (); + static bool s_Preview; + + private void OnEnable () + { + s_Preview = EditorPrefs.GetBool (k_PrefsPreview, false); + } public override void OnInspectorGUI () { @@ -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 (); } diff --git a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs index b88b0f8..dc75177 100644 --- a/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs +++ b/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/SoftMask.cs @@ -414,19 +414,14 @@ void UpdateMaskTexture() /// 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;