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)
|
public static List<ItemInfo> GetItemsForType(ScriptType type, bool useProperties, bool useFields, bool usePropertiesWithoutSetter = false)
|
||||||
{
|
{
|
||||||
var items = new List<ItemInfo>();
|
var items = new List<ItemInfo>();
|
||||||
|
var isPlayMode = Editor.IsPlayMode;
|
||||||
|
|
||||||
if (useProperties)
|
if (useProperties)
|
||||||
{
|
{
|
||||||
@@ -278,7 +279,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip hidden fields, handle special attributes
|
// 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;
|
continue;
|
||||||
|
|
||||||
items.Add(new ItemInfo(p, attributes));
|
items.Add(new ItemInfo(p, attributes));
|
||||||
@@ -293,11 +294,10 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
for (int i = 0; i < fields.Length; i++)
|
for (int i = 0; i < fields.Length; i++)
|
||||||
{
|
{
|
||||||
var f = fields[i];
|
var f = fields[i];
|
||||||
|
|
||||||
var attributes = f.GetAttributes(true);
|
var attributes = f.GetAttributes(true);
|
||||||
|
|
||||||
// Skip hidden fields, handle special attributes
|
// 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;
|
continue;
|
||||||
|
|
||||||
items.Add(new ItemInfo(f, attributes));
|
items.Add(new ItemInfo(f, attributes));
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace FlaxEngine
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class HideInEditorAttribute : Attribute
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HideInEditorAttribute"/> class.
|
/// Initializes a new instance of the <see cref="HideInEditorAttribute"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user