/// <summary> /// Connect with the specified configuration /// </summary> /// <param name="configuration"></param> public static void Connect(ClientConfiguration configuration) { Configuration = configuration; if (peer != null && peer.Status != NetPeerStatus.NotRunning) { Debug.LogError("cannot connect while connected"); return; } //do we have an engine hook? if (!singletonEngineHook) { var gobj = new GameObject("UNet Singleton"); singletonEngineHook = gobj.AddComponent<EngineUpdateHook>(); GameObject.DontDestroyOnLoad(gobj); //gobj.hideFlags = HideFlags.DontSave; } //set up netclient... ResourceCache = new Dictionary<string, GameObject>(); singletonEngineHook.UpdateSubscription += Update; config = new NetPeerConfiguration(Configuration.AppIdentifier); config.Port = Configuration.BindPort; //so we can run client and server on the same machine.. peer = new NetClient(config); peer.Start(); var hailMessage = peer.CreateMessage(); WriteHailMessage(hailMessage); peer.Connect(Configuration.Ip, Configuration.Port, hailMessage); }
// Use this for initialization void Start() { var config = new ClientConfiguration(ip, port); Net.Connect(config); }
public static void Connect(string ip, int port, int bindport = 0) { Configuration = new ClientConfiguration(ip, port, bindport); Connect(Configuration); }