Two questions arise when trying to "play on the server":
- Can we setup as both client and server within the same instance? The answer is NO. Beyond the negative result, "Client" and "Server" roles are interchangeable for most practical purposes.
- Can we RPC from the server to itself? Somewhat surprisingly, the answer is, again NO. More generally it appears that you cannot unicast from a network player to the same network player.
Short of re-implementing all our input interface to invoke server instances locally, what do we do? Reflection will help overcome this hurdle:
private void ClientRequest(string name,params object[] args){
if (Network.isServer)
typeof(TargetType).GetMethod(name).Invoke(avatar,args);
else
if (Network.isServer)
typeof(TargetType).GetMethod(name).Invoke(avatar,args);
else
networkView.RPC (name, upstream, args);
}
}
In the above example...
- TargetType is the type of the object that you wish to invoke.
- networkView is the network view that you would normally send your RPC from.
- Remember using System.Reflection.
More powerful than MonoBehaviour.Invoke( name, delay ).
No comments:
Post a Comment