コード例 #1
0
ファイル: PNet.cs プロジェクト: Antaresgames/PNet
        /// <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);
        }
コード例 #2
0
ファイル: ExamplePNet.cs プロジェクト: Antaresgames/PNet
 // Use this for initialization
 void Start()
 {
     var config = new ClientConfiguration(ip, port);
     Net.Connect(config);
 }
コード例 #3
0
ファイル: PNet.cs プロジェクト: Antaresgames/PNet
 public static void Connect(string ip, int port, int bindport = 0)
 {
     Configuration = new ClientConfiguration(ip, port, bindport);
     Connect(Configuration);
 }