Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Connect to the specified ip on the specified port
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="bindport">port to actually listen on. Default is just the first available port</param>
        public static void Connect(string ip, int port, int bindport = 0)
        {
            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.HideAndDontSave;

            }
            //set up netclient...

            ResourceCache = new Dictionary<string, GameObject>();

            singletonEngineHook.UpdateSubscription += Update;

            config = new NetPeerConfiguration("PNet");
            config.Port = 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(ip, port, hailMessage);
        }