Exemple #1
0
 /// <summary>
 /// cjson函数回调
 /// </summary>
 /// <param name="data"></param>
 /// <param name="func"></param>
 public static void OnJsonCallFunc(string data, LuaFunction func)
 {
     LogManager.Warning("OnJsonCallback data:>>" + data + " lenght:>>" + data.Length);
     if (func != null)
     {
         func.Call(data);
     }
 }
Exemple #2
0
 /// <summary>
 /// pbc/pblua函数回调
 /// </summary>
 /// <param name="func"></param>
 public static void OnCallLuaFunc(LuaByteBuffer data, LuaFunction func)
 {
     if (func != null)
     {
         func.Call(data);
     }
     LogManager.Warning("OnCallLuaFunc length:>>" + data.buffer.Length);
 }
 public void Release(string poolName, GameObject go)
 {
     if (m_GameObjectPools.ContainsKey(poolName))
     {
         GameObjectPool pool = m_GameObjectPools[poolName];
         pool.ReturnObjectToPool(poolName, go);
     }
     else
     {
         LogManager.Warning("No pool available with name: " + poolName);
     }
 }
Exemple #4
0
        /// <summary>
        /// 创建面板,请求资源管理器
        /// </summary>
        /// <param name="type"></param>
        public void CreatePanel(string name, LuaFunction func = null) {
            string assetName = name + "Panel";
            //string abName = name.ToLower() + AppConst.ExtName;
            string abName = "prefabs" + AppConst.ExtName;
            GameObject go;
            if (Parent.FindChild(assetName) != null)
            {
                go = Parent.FindChild(assetName).gameObject;
            }
            else
            {
#if ASYNC_MODE
            ResManager.LoadPrefab(abName, assetName, delegate(UnityEngine.Object[] objs) {
                if (objs.Length == 0) return;
                GameObject prefab = objs[0] as GameObject;
                if (prefab == null) return;

                GameObject go = Instantiate(prefab) as GameObject;
                go.name = assetName;
                go.layer = LayerMask.NameToLayer("Default");
                go.transform.SetParent(Parent);
                go.transform.localScale = Vector3.one;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent<LuaBehaviour>();

                if (func != null) func.Call(go);
                LogManager.Warning("CreatePanel::>> " + name + " " + prefab);
            });
#else
                GameObject prefab = ResManager.LoadAsset<GameObject>(abName, assetName);
                if (prefab == null) return;

                go = Instantiate(prefab) as GameObject;
            }
            go.name = assetName;
            go.layer = LayerMask.NameToLayer("Default");
            if (Parent!=null)
            go.transform.SetParent(Parent);
            go.transform.localScale = Vector3.one;
            go.transform.localPosition = Vector3.zero;
            go.AddComponent<LuaBehaviour>();

            if (func != null) func.Call(go);
            LogManager.Warning("CreatePanel::>> " + name );
#endif
        }
Exemple #5
0
        public GameObject NextAvailableObject()
        {
            GameObject go = null;

            if (availableObjStack.Count > 0)
            {
                go = availableObjStack.Pop();
            }
            else
            {
                LogManager.Warning("No object available & cannot grow pool: " + poolName);
            }
            if (go != null)
            {
                go.SetActive(true);
            }
            return(go);
        }
        public GameObject Get(string poolName)
        {
            GameObject result = null;

            if (m_GameObjectPools.ContainsKey(poolName))
            {
                GameObjectPool pool = m_GameObjectPools[poolName];
                result = pool.NextAvailableObject();
                if (result == null)
                {
                    LogManager.Warning("No object available in pool. Consider setting fixedSize to false.: " + poolName);
                }
            }
            else
            {
                //Debug.LogError("Invalid pool name specified: " + poolName);
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新
        /// </summary>
        IEnumerator OnUpdateResource()
        {
            if (!AppConst.UpdateMode)
            {
                OnResourceInited();
                yield break;
            }
            string dataPath = Util.DataPath;  //数据目录
            string url      = AppConst.WebUrl;
            string message  = string.Empty;
            string random   = DateTime.Now.ToString("yyyymmddhhmmss");
            string listUrl  = url + "files.txt?v=" + random;

            //string listUrl = url + "files.txt";
            LogManager.Warning("正在检测更新---->>>" + listUrl);
            message = "正在检测更新---->>>" + listUrl;
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            WWW www = new WWW(listUrl); yield return(www);

            if (www.error != null)
            {
                OnUpdateFailed(string.Empty);
                yield break;
            }
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            File.WriteAllBytes(dataPath + "files.txt", www.bytes);
            string filesText = www.text;

            string[] files = filesText.Split('\n');

            List <string> willDownLoadUrl         = new List <string>(); //from
            List <string> willDownLoadFileName    = new List <string>();
            List <string> willDownLoadDestination = new List <string>(); //to


            float countLength = 0;

            System.Net.HttpWebRequest request = null;
            System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                         System.Security.Cryptography.X509Certificates.X509Chain chain,
                         System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
                return(true);        // **** Always accept
            };
            for (int i = 0; i < files.Length; i++)
            {
                if (string.IsNullOrEmpty(files[i]))
                {
                    continue;
                }
                string[] keyValue  = files[i].Split('|');
                string   f         = keyValue[0];
                string   localfile = (dataPath + f).Trim();
                string   path      = Path.GetDirectoryName(localfile);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string fileUrl = url + f + "?v=" + random;
                //string fileUrl = url + f ;
                bool canUpdate = !File.Exists(localfile);

                if (!canUpdate)
                {
                    string remoteMd5 = keyValue[1].Trim();
                    string localMd5  = Util.md5file(localfile);
                    canUpdate = !remoteMd5.Equals(localMd5);

                    if (canUpdate)
                    {
                        File.Delete(localfile);
                    }
                }
                if (canUpdate)     //本地缺少文件

                //message = "正在检查更新>>" + fileUrl;
                //facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);

                /*
                 * www = new WWW(fileUrl);
                 * loadProgress.value = www.progress;
                 * progressText.text = Mathf.Round(loadProgress.value * 100).ToString() + "/100";
                 * yield return www;
                 * if (www.error != null) {
                 *  OnUpdateFailed(path);   //
                 *  yield break;
                 * }
                 * File.WriteAllBytes(localfile, www.bytes);
                 */
                //这里都是资源文件,用线程下载
                //BeginDownload(fileUrl, localfile);
                //while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); }

                {
                    willDownLoadUrl.Add(fileUrl);           //下载地址
                    willDownLoadFileName.Add(keyValue[0]);
                    willDownLoadDestination.Add(localfile); //目标文件路径

                    //计算文件大小
                    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fileUrl);
                    request.UseDefaultCredentials = true;
                    request.Method = "HEAD";
                    countLength   += request.GetResponse().ContentLength;
                }
            }

            //System.Net.HttpWebRequest request=null;
            ////计算文件大小
            //for (int i = 0; i < willDownLoadUrl.Count; i++)
            //{
            //    request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(willDownLoadUrl[i]);
            //    request.UseDefaultCredentials = true;
            //    request.Method = "HEAD";
            //    countLength += request.GetResponse().ContentLength;
            //    //UnityWebRequest uwr = UnityWebRequest.Head(willDownLoadUrl[i]);
            //    //yield return uwr.Send();
            //    //string size = uwr.GetResponseHeader("Content-Length");
            //    //if (!string.IsNullOrEmpty(size)) //{ OnUpdateFailed(null); yield break; }
            //    //    countLength += float.Parse(size);
            //}

            string value = string.Format("{0}", Math.Round(countLength / 1024, 2));

            facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNTLENGTH, value);
            if (willDownLoadUrl.Count > 0)
            {
                facade.SendMessageCommand(NotiConst.UPDATE_ALL_COUNT, willDownLoadUrl.Count);
            }
            for (int i = 0; i < willDownLoadUrl.Count; i++)
            {
                LogManager.Debug("要下载的文件:" + willDownLoadUrl[i]);
                //这里都是资源文件,用线程下载
                facade.SendMessageCommand(NotiConst.UPDATE_FILE_NAME, willDownLoadFileName[i]);
                BeginDownload(willDownLoadUrl[i], willDownLoadDestination[i]);
                while (!(IsDownOK(willDownLoadDestination[i])))
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            yield return(new WaitForEndOfFrame());

            //yield return new WaitForSeconds(0.1f);
            message = "更新完成!";
            facade.SendMessageCommand(NotiConst.CHECK_UPDATE, message);
            OnResourceInited();
        }
Exemple #8
0
 public static void LogWarning(string str)
 {
     LogManager.Warning(str);
 }