@@ -358,8 +358,8 @@ internal void HandleNetworkedVarUpdate(BitReader reader, uint clientId)
358
358
#region MESSAGING_SYSTEM
359
359
private static readonly Dictionary < Type , Dictionary < ulong , ClientRPC > > CachedClientRpcs = new Dictionary < Type , Dictionary < ulong , ClientRPC > > ( ) ;
360
360
private static readonly Dictionary < Type , Dictionary < ulong , ServerRPC > > CachedServerRpcs = new Dictionary < Type , Dictionary < ulong , ServerRPC > > ( ) ;
361
- private static readonly HashSet < Type > CachedTypes = new HashSet < Type > ( ) ;
362
361
private static readonly Dictionary < ulong , string > HashResults = new Dictionary < ulong , string > ( ) ;
362
+ private static readonly HashSet < Type > CachedTypes = new HashSet < Type > ( ) ;
363
363
364
364
private ulong HashMethodName ( string name )
365
365
{
@@ -562,30 +562,63 @@ internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, BitWri
562
562
if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Only clients and host can invoke ClientRPC" ) ;
563
563
return ;
564
564
}
565
-
566
- for ( int i = 0 ; i < clientIds . Count ; i ++ )
565
+
566
+ using ( BitWriter rpcWriter = BitWriter . Get ( ) )
567
567
{
568
- if ( isHost && clientIds [ i ] == NetworkingManager . singleton . LocalClientId )
568
+ writer . WriteUInt ( networkId ) ;
569
+ writer . WriteUShort ( networkedObject . GetOrderIndex ( this ) ) ;
570
+ writer . WriteULong ( hash ) ;
571
+
572
+ writer . WriteWriter ( writer ) ;
573
+
574
+ for ( int i = 0 ; i < clientIds . Count ; i ++ )
569
575
{
570
- using ( BitReader reader = BitReader . Get ( writer . Finalize ( ) ) )
576
+ if ( isHost && clientIds [ i ] == NetworkingManager . singleton . LocalClientId )
571
577
{
572
- InvokeClientRPCLocal ( hash , NetworkingManager . singleton . LocalClientId , reader ) ;
578
+ using ( BitReader reader = BitReader . Get ( writer . Finalize ( ) ) )
579
+ {
580
+ InvokeClientRPCLocal ( hash , NetworkingManager . singleton . LocalClientId , reader ) ;
581
+ }
582
+ }
583
+ else
584
+ {
585
+ InternalMessageHandler . Send ( clientIds [ i ] , "MLAPI_CLIENT_RPC" , "MLAPI_USER_CHANNEL" , rpcWriter ) ;
573
586
}
574
587
}
575
- else
588
+ }
589
+ }
590
+
591
+ internal void SendClientRPCPerformance ( ulong hash , uint clientId , BitWriter writer )
592
+ {
593
+ Type type = GetType ( ) ; //This is cached by CLR
594
+
595
+ if ( ! isServer )
596
+ {
597
+ //We are NOT a server.
598
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Only clients and host can invoke ClientRPC" ) ;
599
+ return ;
600
+ }
601
+
602
+ using ( BitWriter rpcWriter = BitWriter . Get ( ) )
603
+ {
604
+ writer . WriteUInt ( networkId ) ;
605
+ writer . WriteUShort ( networkedObject . GetOrderIndex ( this ) ) ;
606
+ writer . WriteULong ( hash ) ;
607
+
608
+ writer . WriteWriter ( writer ) ;
609
+
610
+ if ( isHost && clientId == NetworkingManager . singleton . LocalClientId )
576
611
{
577
- using ( BitWriter rpcWriter = BitWriter . Get ( ) )
612
+ using ( BitReader reader = BitReader . Get ( writer . Finalize ( ) ) )
578
613
{
579
- writer . WriteUInt ( networkId ) ;
580
- writer . WriteUShort ( networkedObject . GetOrderIndex ( this ) ) ;
581
- writer . WriteULong ( hash ) ;
582
-
583
- writer . WriteWriter ( writer ) ;
584
-
585
- InternalMessageHandler . Send ( clientIds [ i ] , "MLAPI_CLIENT_RPC" , "MLAPI_USER_CHANNEL" , rpcWriter ) ;
614
+ InvokeClientRPCLocal ( hash , NetworkingManager . singleton . LocalClientId , reader ) ;
586
615
}
587
616
}
588
- }
617
+ else
618
+ {
619
+ InternalMessageHandler . Send ( clientId , "MLAPI_CLIENT_RPC" , "MLAPI_USER_CHANNEL" , rpcWriter ) ;
620
+ }
621
+ }
589
622
}
590
623
#endregion
591
624
@@ -596,48 +629,65 @@ internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, BitWri
596
629
public delegate void Action < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( T1 t1 , T2 t2 , T3 t3 , T4 t4 , T5 t5 , T6 t6 , T7 t7 , T8 t8 ) ;
597
630
public delegate void Action < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( T1 t1 , T2 t2 , T3 t3 , T4 t4 , T5 t5 , T6 t6 , T7 t7 , T8 t8 , T9 t9 ) ;
598
631
public delegate void Action < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( T1 t1 , T2 t2 , T3 t3 , T4 t4 , T5 t5 , T6 t6 , T7 t7 , T8 t8 , T9 t9 , T10 t10 ) ;
599
-
600
- //BOXED
601
- public void InvokeServerRPC ( Action method )
632
+
633
+ //BOXED SERVER RPC
634
+ public void InvokeServerRpc ( string methodName , params object [ ] parameters )
635
+ {
636
+ SendServerRPCBoxed ( HashMethodName ( methodName ) , parameters ) ;
637
+ }
638
+
639
+ public void InvokeServerRpc ( Action method )
602
640
{
603
641
SendServerRPCBoxed ( HashMethodName ( method . Method . Name ) ) ;
604
642
}
605
643
606
- public void InvokeServerRPC < T1 > ( Action < T1 > method , T1 t1 )
644
+ public void InvokeServerRpc < T1 > ( Action < T1 > method , T1 t1 )
607
645
{
608
646
SendServerRPCBoxed ( HashMethodName ( method . Method . Name ) , t1 ) ;
609
647
}
610
-
611
- public void InvokeClientRPC ( Action method , List < uint > clientIds )
648
+
649
+ public void InvokeServerRpc < T1 > ( Action < T1 > method , T1 t1 )
650
+ {
651
+ SendServerRPCBoxed ( HashMethodName ( method . Method . Name ) , t1 ) ;
652
+ }
653
+
654
+ //BOXED CLIENT RPC
655
+ public void InvokeClientRpc ( Action method , List < uint > clientIds )
612
656
{
613
657
SendClientRPCBoxed ( HashMethodName ( method . Method . Name ) , clientIds ) ;
614
658
}
615
659
616
- public void InvokeClientRPC < T1 > ( Action < T1 > method , List < uint > clientIds , T1 t1 )
660
+ public void InvokeClientRpc < T1 > ( Action < T1 > method , List < uint > clientIds , T1 t1 )
617
661
{
618
662
SendClientRPCBoxed ( HashMethodName ( method . Method . Name ) , clientIds , t1 ) ;
619
663
}
620
664
621
- //Performance
622
- public void InvokeServerRPC ( RpcDelegate method , BitWriter writer )
665
+ //PERFORMANCE SERVER RPC
666
+ public void InvokeServerRpc ( RpcDelegate method , BitWriter writer )
623
667
{
624
668
SendServerRPCPerformance ( HashMethodName ( method . Method . Name ) , writer ) ;
625
669
}
626
-
627
- public void InvokeClientRPC ( RpcDelegate method , BitWriter writer )
670
+
671
+ public void InvokeServerRpc ( string methodName , BitWriter writer )
628
672
{
629
- SendServerRPCPerformance ( HashMethodName ( method . Method . Name ) , writer ) ;
673
+ SendServerRPCPerformance ( HashMethodName ( methodName ) , writer ) ;
630
674
}
631
-
632
- public void InvokeServerRPC ( string methodName , BitWriter writer )
675
+
676
+ //PERFORMANCE CLIENT RPC
677
+ public void InvokeClientRpc ( RpcDelegate method , BitWriter writer )
633
678
{
634
- SendServerRPCPerformance ( HashMethodName ( methodName ) , writer ) ;
679
+ SendServerRPCPerformance ( HashMethodName ( method . Method . Name ) , writer ) ;
635
680
}
636
681
637
- public void InvokeClientRPC ( string methodName , List < uint > clientIds , BitWriter writer )
682
+ public void InvokeClientRpc ( string methodName , List < uint > clientIds , BitWriter writer )
638
683
{
639
684
SendClientRPCPerformance ( HashMethodName ( methodName ) , clientIds , writer ) ;
640
685
}
686
+
687
+ public void InvokeClientRpcOnOwner ( string methodName , BitWriter writer )
688
+ {
689
+ SendClientRPCPerformance ( HashMethodName ( methodName ) , OwnerClientId , writer ) ;
690
+ }
641
691
#endregion
642
692
643
693
/// <summary>
0 commit comments