Exemple #1
0
        public NetClientP2p(ClientOption clientOption, ILoggerFactory loggerFactory = null)
            : base(clientOption, loggerFactory)
        {
            if (clientOption.IsServiceUdp == false)
            {
                throw new Exception("Must set true to ClientOption.IsServiceUdp.");
            }

            OnP2pReceived         = OnP2pReceive;
            OnViewRequestReceived = OnViewRequestReceiveEx;

            _views                 = new NetViews();
            _zeroDataWriter        = new NetDataWriter(false, 1);
            _readerForSendInternal = new NetDataReader();
        }
Exemple #2
0
        protected override void Awake()
        {
            if (s_instance == null)
            {
                s_instance = this;

                if (_isDontDestroyOnLoad)
                {
                    DontDestroyOnLoad(this.gameObject);
                }

                s_inited = true;
            }
            else
            {
                //Debug.LogErrorFormat(gameObject, "Already created singleton object {0}", typeof(NetP2pUnity));
                Destroy(this);
                return;
            }

            _clientOption.IsServiceUdp          = true;
            _clientOption.UdpServerAddress      = ServerAddress;
            _clientOption.UdpServerPort         = UdpServerPort;
            _clientOption.PingInterval          = PingInterval;
            _clientOption.MtuInterval           = MtuInterval;
            _clientOption.RudpDisconnectTimeout = RudpDisconnectTimeout;

            base.Awake();

            _client.OnP2pReceived        += OnP2pReceive;
            _client.OnViewRequestReceived = OnViewRequestReceive;

            _views                 = new NetViews();
            _zeroDataWriter        = new NetDataWriter(false, 1);
            _readerForSendInternal = new NetDataReader();

            if (_clientOption.IsServiceUdp == false)
            {
                Debug.LogError("[NetP2pUnity] require [IsServiceUdp] option");
            }
        }