close #13; Preview soft mask buffer in inspector

pull/87/head
mob-sakai 2018-12-16 14:29:59 +09:00
parent f9caefec68
commit 782289612b
2 changed files with 31 additions and 13 deletions

View File

@ -15,7 +15,14 @@ namespace Coffee.UIExtensions.Editors
[CanEditMultipleObjects] [CanEditMultipleObjects]
public class SoftMaskEditor : Editor public class SoftMaskEditor : Editor
{ {
const string k_PrefsPreview = "SoftMaskEditor_Preview";
static readonly List<Graphic> s_Graphics = new List<Graphic> (); 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 () public override void OnInspectorGUI ()
{ {
@ -43,6 +50,22 @@ namespace Coffee.UIExtensions.Editors
GUILayout.EndVertical (); GUILayout.EndVertical ();
GUILayout.EndHorizontal (); 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 ();
} }

View File

@ -414,19 +414,14 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
void GetDesamplingSize(DesamplingRate rate, out int w, out int h) void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
if (!Application.isPlaying) var res = UnityEditor.UnityStats.screenRes.Split('x');
{ w = int.Parse(res[0]);
var res = UnityEditor.UnityStats.screenRes.Split('x'); h = int.Parse(res[1]);
w = int.Parse(res[0]); #else
h = int.Parse(res[1]); w = Screen.width;
} h = Screen.height;
else #endif
#endif
{
w = Screen.width;
h = Screen.height;
}
if (rate == DesamplingRate.None) if (rate == DesamplingRate.None)
return; return;