Skip to content

Commit

Permalink
feat: adding helper methods for networkWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 31, 2023
1 parent aa6a6e4 commit 5ad1f83
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Assets/Mirage/Runtime/NetworkWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,37 @@ public NetworkWorld()

}
}

public static class NetworkWorldExtensions
{
/// <summary>
/// adds an event handler, and invokes it on current objects in world
/// </summary>
/// <param name="action"></param>
public static void AddAndInvokeOnSpawn(this NetworkWorld world, Action<NetworkIdentity> action)
{
world.onSpawn += action;
foreach (var identity in world.SpawnedIdentities)
{
action.Invoke(identity);
}
}

/// <summary>
/// adds an event handler, and invokes it on current objects in world
/// </summary>
/// <param name="action"></param>
public static void AddAndInvokeOnAuthorityChanged(this NetworkWorld world, AuthorityChanged action)
{
world.OnAuthorityChanged += action;
foreach (var identity in world.SpawnedIdentities)
{
if (identity.HasAuthority)
{
// owner might be null, but that is fine
action.Invoke(identity, true, identity.Owner);
}
}
}
}
}

0 comments on commit 5ad1f83

Please sign in to comment.