Skip to content

Commit

Permalink
feat: if the 'UIMask' sprite is specified as the source image, it is …
Browse files Browse the repository at this point in the history
…suggested to use another image

close #82
  • Loading branch information
mob-sakai committed Sep 8, 2020
1 parent 5f1035f commit ea904db
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Packages/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public override void OnInspectorGUI()
GUILayout.EndHorizontal();
}

var currentImage = current.graphic as Image;
if (currentImage && IsMaskUI(currentImage.sprite))
{
GUILayout.BeginHorizontal();
EditorGUILayout.HelpBox("SoftMask does not recommend to use 'UIMask' sprite as a source image.\n(It contains only small alpha pixels.)\nDo you want to use 'UISprite' instead?", MessageType.Warning);
GUILayout.BeginVertical();

if (GUILayout.Button("Fix"))
{
currentImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");
}

GUILayout.EndVertical();
GUILayout.EndHorizontal();
}

// Preview buffer.
GUILayout.BeginVertical(EditorStyles.helpBox);
if (s_Preview != (s_Preview = EditorGUILayout.ToggleLeft("Preview Soft Mask Buffer", s_Preview)))
Expand All @@ -76,6 +92,13 @@ public override void OnInspectorGUI()
GUILayout.EndVertical();
}

private static bool IsMaskUI(Object obj)
{
return obj
&& obj.name == "UIMask"
&& AssetDatabase.GetAssetPath(obj) == "Resources/unity_builtin_extra";
}


//%%%% Context menu for editor %%%%
[MenuItem("CONTEXT/Mask/Convert To SoftMask", true)]
Expand Down

0 comments on commit ea904db

Please sign in to comment.