Skip to content

Commit

Permalink
feat: remove menu in inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Sep 1, 2020
1 parent 30b4703 commit e7f8f51
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal class UIParticleEditor : GraphicEditor
//################################
private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order");
private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh");
private static readonly GUIContent s_ContentFix = new GUIContent("Fix");
private static readonly List<UIParticle> s_TempParents = new List<UIParticle>();
private static readonly List<UIParticle> s_TempChildren = new List<UIParticle>();

private SerializedProperty _spScale;
private SerializedProperty _spIgnoreCanvasScaler;
Expand Down Expand Up @@ -101,6 +104,8 @@ public override void OnInspectorGUI()

_ro.DoLayoutList();

serializedObject.ApplyModifiedProperties();

// Does the shader support UI masks?
if (current.maskable && current.GetComponentInParent<Mask>())
{
Expand All @@ -118,7 +123,46 @@ public override void OnInspectorGUI()
}
}

serializedObject.ApplyModifiedProperties();
// Does the shader support UI masks?

if (FixButton(current.m_IsTrail,"This UIParticle component should be removed. The UIParticle for trails is no longer needed."))
{
DestroyUIParticle(current);
return;
}
current.GetComponentsInParent(true, s_TempParents);
if (FixButton(1 < s_TempParents.Count,"This UIParticle component should be removed. The parent UIParticle exists."))
{
DestroyUIParticle(current);
return;
}
current.GetComponentsInChildren(true, s_TempChildren);
if (FixButton(1 < s_TempChildren.Count,"The children UIParticle component should be removed."))
{
s_TempChildren.ForEach(child => DestroyUIParticle(child, true));
}
}

void DestroyUIParticle(UIParticle p, bool ignoreCurrent = false)
{
if (!p || ignoreCurrent && target == p) return;

var cr = p.canvasRenderer;
DestroyImmediate(p);
DestroyImmediate(cr);
}

bool FixButton(bool show, string text)
{
if (!show) return false;
using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
{
EditorGUILayout.HelpBox(text, MessageType.Warning, true);
using (new EditorGUILayout.VerticalScope())
{
return GUILayout.Button(s_ContentFix, GUILayout.Width(30));
}
}
}
}
}
2 changes: 1 addition & 1 deletion Packages/UIParticle/Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UIParticle : MaskableGraphic
, ISerializationCallbackReceiver
#endif
{
[HideInInspector] [SerializeField] bool m_IsTrail = false;
[HideInInspector] [SerializeField] internal bool m_IsTrail = false;

[Tooltip("Ignore canvas scaler")] [SerializeField] [FormerlySerializedAs("m_IgnoreParent")]
bool m_IgnoreCanvasScaler = true;
Expand Down

0 comments on commit e7f8f51

Please sign in to comment.