Add ShowInPlayMode to HideInEditor attribute for properties/fields that should display in editor only during play mode
This commit is contained in:
@@ -261,6 +261,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
public static List<ItemInfo> GetItemsForType(ScriptType type, bool useProperties, bool useFields, bool usePropertiesWithoutSetter = false)
|
||||
{
|
||||
var items = new List<ItemInfo>();
|
||||
var isPlayMode = Editor.IsPlayMode;
|
||||
|
||||
if (useProperties)
|
||||
{
|
||||
@@ -278,7 +279,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
continue;
|
||||
|
||||
// Skip hidden fields, handle special attributes
|
||||
if ((!p.IsPublic && !showInEditor) || attributes.Any(x => x is HideInEditorAttribute))
|
||||
if ((!p.IsPublic && !showInEditor) || attributes.Any(x => x is HideInEditorAttribute hide && (!isPlayMode || !hide.ShowInPlayMode)))
|
||||
continue;
|
||||
|
||||
items.Add(new ItemInfo(p, attributes));
|
||||
@@ -293,11 +294,10 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
var f = fields[i];
|
||||
|
||||
var attributes = f.GetAttributes(true);
|
||||
|
||||
// Skip hidden fields, handle special attributes
|
||||
if ((!f.IsPublic && !attributes.Any(x => x is ShowInEditorAttribute)) || attributes.Any(x => x is HideInEditorAttribute))
|
||||
if ((!f.IsPublic && !attributes.Any(x => x is ShowInEditorAttribute)) || attributes.Any(x => x is HideInEditorAttribute hide && (!isPlayMode || !hide.ShowInPlayMode)))
|
||||
continue;
|
||||
|
||||
items.Add(new ItemInfo(f, attributes));
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace FlaxEngine
|
||||
[Serializable]
|
||||
public sealed class HideInEditorAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the variable only in play mode (when the game is running), otherwise it will be hidden. Useful for runtime fields or properties to remain invisible at edit time.
|
||||
/// </summary>
|
||||
public bool ShowInPlayMode;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HideInEditorAttribute"/> class.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user