Exemplo n.º 1
0
        //加载结束
        private void OnLoadEnd(Object obj, object parm, Callback_0 callback)
        {
            if (m_panelState == PanelState.Destroy)//刚打开就要销毁
            {
                Debug.Log("Destroy on Load End");
            }

            if (obj == null)
            {
                GLog.E("Load UI Error:: file: " + name + ", assetPath: " + assetPath);
                m_panelState = PanelState.Showing;
                if (callback != null)
                {
                    callback();
                }
            }
            else
            {
                gameObject = GameObject.Instantiate(obj) as GameObject;
                transform  = gameObject.transform;
                transform.SetParent(GetParent());
                transform.localPosition = Vector3.zero;

                Init();
                Localize();
                Resize();
                OnShow(parm);
                m_panelState = PanelState.Showing;
                if (callback != null)
                {
                    callback();
                }
            }
        }
Exemplo n.º 2
0
        public void Connect(string ip, int port)
        {
            if (IsConnected)
            {
                GLog.W("Connect Warrming:: Already Connected!");
                return;
            }
            OnStateChanged(SocketState.Connecting);

            IPAddress  address  = Dns.GetHostAddresses(ip)[0];
            IPEndPoint endPoint = new IPEndPoint(address, port);

            m_socket = new Socket(address.AddressFamily, m_socketType, m_protocolType)
            {
                NoDelay        = true,
                SendTimeout    = Timeout,
                ReceiveTimeout = Timeout
            };
            try
            {
                m_socket.BeginConnect(endPoint, BeginConnect, m_socket);
            }
            catch (Exception e)
            {
                GLog.E("Connect Error:: " + e);
            }
        }
Exemplo n.º 3
0
        private void CombineDownloadList(JsonNode root, Dictionary <string, DownState> downloaded)
        {
            m_waitingList.Clear();
            m_root = root;
            JsonNode curVer = FileManager.bundles;

            m_writer = new StreamWriter(m_temPath + "download.list", false);
            var assets = (Dictionary <string, JsonNode>)root["BundleManifest"];
            var eor    = assets.GetEnumerator();

            while (eor.MoveNext())
            {
                DownState state;
                if (downloaded.TryGetValue(eor.Current.Value["BundleName"].ToString(), out state))
                {
                    if (state.Hash == eor.Current.Value["Hash"].ToString())
                    {
                        if (state.IsDone)
                        {
                            m_writer.Write(eor.Current.Value["BundleName"].ToString() + ":" + state.Hash + ":1\n");
                        }
                        else
                        {
                            m_writer.Write(eor.Current.Value["BundleName"].ToString() + ":" + state.Hash + "\n");
                            m_waitingList.Enqueue(eor.Current.Value);
                        }
                        continue;
                    }
                    File.Delete(m_temPath + eor.Current.Value["BundleName"].ToString());
                }

                if (curVer[eor.Current.Key].IsTable() && curVer[eor.Current.Key]["Hash"].ToString() == eor.Current.Value["Hash"].ToString())
                {
                    continue;
                }
                m_waitingList.Enqueue(eor.Current.Value);
            }
            eor.Dispose();

            if (m_webAgent == null)
            {
                m_webAgent = new WebRequestAgent();
            }
            m_webAgent.onDownloadSuccess = StartDown;
            m_webAgent.onDownloadFailed  = () =>
            {
                GLog.E("Down Error");
            };
            StartDown();
        }
Exemplo n.º 4
0
        private void BeginConnect(IAsyncResult ar)
        {
            Socket socket = ar.AsyncState as Socket;

            if (socket != null && socket.Connected)
            {
                socket.EndConnect(ar);
                OnStateChanged(SocketState.Connected);
                StartThread();
            }
            else
            {
                OnStateChanged(SocketState.BreakOff);
                GLog.E("Socket Connect Failed.");
            }
        }
Exemplo n.º 5
0
        //加载Bundle数据文件
        void LoadManifest()
        {
            if (!Config.BundleMode)
            {
                return;
            }

            string        path  = FileManager.GetBundleRealPath(Config.BundleManifest);
            FileLoadAgent agent = new FileLoadAgent();

            m_startCoroutine(agent.LoadSync(path, bytes =>
            {
                FileManager.LoadMenifest(bytes);
            }, error =>
            {
                GLog.E(error);
            }));
        }
Exemplo n.º 6
0
        private void DownLoadManifest(Callback_0 onSuccess)
        {
            if (m_webAgent == null)
            {
                m_webAgent = new WebRequestAgent();
            }
            if (File.Exists(m_temPath + Config.BundleManifest))
            {
                File.Delete(m_temPath + Config.BundleManifest);
            }

            long length = m_webAgent.GetLength(m_remoteUrl + Config.BundleManifest);

            m_webAgent.onDownloadSuccess = onSuccess;
            m_webAgent.onDownloadFailed  = () =>
            {
                GLog.E("下载manifest失败,提示重试");
            };
            StartCoroutine(m_webAgent.Download(m_remoteUrl + Config.BundleManifest, m_temPath + Config.BundleManifest,
                                               length));
        }
Exemplo n.º 7
0
        public void Close()
        {
            AbortThread();
            if (m_socket != null)
            {
                try
                {
                    m_socket.Close();
                    m_socket = null;
                }
                catch (Exception e)
                {
                    GLog.E(e.ToString());
                }
            }

            lock (m_sendBuffer)
            {
                m_sendBuffer.Clear();
            }
            m_receiveBuffer.Clear();
        }