With Untiy 3D, I am a real noob. So I had to work up a quick network example just so I could see where the calls go and how they show up so that I could have a better understanding of networking within Unity before I start investing serious man hours and money on third party tools.
Here is a simple script I put together that you can attach to any game object in the world. You will need one of the many multliplayer demos or the first hour or two of multiplayer tutorials completed.
Here is the code:
using UnityEngine;using System.Collections; /* ------------------------------------------------------------ This was the only two debug prints on client side: CLIENT:NetworkExample:OnConnectedToServer() (this server responded in its log here) CLIENT:NetworkExample:RPC:Client_PlayerExampleResponse(Client,1) ------------------------------------------------------------ This was the only debug print on server side: SERVER:NetworkExample:RPC:Server_PlayerExampleRequest(Client,1) */ //-------------------------------------------------------------------------------------------------- // VARIABLES //-------------------------------------------------------------------------------------------------- public bool debugactive = true; public string PlayerName; //----------- This is an example of having the Client send a request to the Server: { } //----------- This is an example of the Server receiving a request from the client and calling the client back. { //networkView.RPC("Client_PlayerExampleResponse",RPCMode.All, playername, view); networkView.RPC("Client_PlayerExampleResponse",view, playername, view); // responding only to the player 'view' that sent the RPC } //----------- This is an example of the Client receiving a call back from the server. { } // Use this for initialization } // Update is called once per frame } }
Run this in any network game you have compiled, run one copy as a server and run another copy (from another directory) as the client.... then check the logs and look at the output. You will see which game executed which functions and thus have a clearer understanding of just how easy networking is within Unity 3D!
No comments:
Post a Comment