Skip to content

Commit

Permalink
feat: adding attribute to show SyncSettings in networkBehaviour if no…
Browse files Browse the repository at this point in the history
… syncvars
  • Loading branch information
James-Frowen committed May 11, 2024
1 parent 2d8893c commit dd6a6d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Mirage/Editor/Drawers/SyncSettingsDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;

Expand All @@ -17,9 +18,16 @@ private static bool NoSyncInBehaviour(SerializedProperty property)
foreach (var target in targets)
{
Debug.Assert(target is NetworkBehaviour);

// show if syncvars
var syncAny = InspectorHelper.SyncsAnything(target);
if (syncAny)
return false;

// show if attribute
var showAttr = target.GetType().GetCustomAttributes<ShowSyncSettingsAttribute>(true);
if (showAttr != null)
return false;
}
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions Assets/Mirage/Runtime/CustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,10 @@ public sealed class ReadOnlyInspectorAttribute : PropertyAttribute { }
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class NetworkedPrefabAttribute : PropertyAttribute { }

/// <summary>
/// Add to NetworkBehaviour to force SyncSettings to be drawn, even if there are no syncvars
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class ShowSyncSettingsAttribute : Attribute { }
}

0 comments on commit dd6a6d6

Please sign in to comment.