コード例 #1
0
        private void Awake()
        {
            if (Instance == null)
            {
                Instance = this;
            }
            else if (Instance != this)
            {
                Destroy(gameObject);
                return;
            }

            DontDestroyOnLoad(transform.root.gameObject);

            this.localIP = LocalNetworkUtils.GetLocalIPAddress();
            Debug.Log("My Local IP : " + this.localIP);
        }
コード例 #2
0
        // *************** The Most Important API' s *************** //

        public void HostAndRegisterToMaster(string password)
        {
            if (!ConnectionToMaster.initMasterConn || peer == null)
            {
                return;
            }

            Host();

            PortForwarder.ReleaseInstance();

            this.localIP    = LocalNetworkUtils.GetLocalIPAddress();
            this.internalEP = new IPEndPoint(IPAddress.Parse(this.localIP), peer.GetPort());

            Debug.Log("Internal EP : " + this.internalEP);

            ConnectionToMaster.Instance.StartClient(() =>
            {
                RequestExternalEP(OnRequestExternalEP: (ep) =>
                {
                    this.externalEP = ep;
                    Debug.Log("Network Peer External : " + this.externalEP);

                    ConnectionToMaster.Instance.RegisterToMaster(this.internalEP, this.externalEP, password,
                                                                 (hostID) =>
                    {
                        peer.OnHosted();
                        // try to forward port in case hole punching does not work
                        if (usePortForwarding)
                        {
                            PortForwarder.Instance.ForwardPort(internalEP.Port, externalEP.Port);
                        }
                    });
                });
            });
        }