Exemplo n.º 1
0
        //加载失败
        void OnUpdateFailed(string file)
        {
            string message = "游戏环境初始失败!>" + file;

            Debug.Log("更新失败!>" + file);
            GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, message);
        }
Exemplo n.º 2
0
 private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
 {
     e.Handled = true;
     GlobalDispatcher.BeginInvoke(new Action <Exception>(error =>
     {
         MessageBox.Show(error.Message, "Ошибка");
     }), e.Exception);
 }
Exemplo n.º 3
0
 void OnDestroy()
 {
     Timers.inst.Remove(TimeHandle);
     GlobalDispatcher.GetInstance().RemoveEventListener(NotiConst.LOADER_COMPLETED, OnCompleted);
     GlobalDispatcher.GetInstance().RemoveEventListener(NotiConst.LOADER_PROGRESS, OnProgress);
     GlobalDispatcher.GetInstance().RemoveEventListener(NotiConst.LOADER_ALL_COMPLETED, OnAllCompleted);
     loader.Dispose();
 }
Exemplo n.º 4
0
 static int GetInstance(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         GlobalDispatcher o = GlobalDispatcher.GetInstance();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 5
0
    static int _CreateGlobalDispatcher(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                GlobalDispatcher obj = new GlobalDispatcher();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: GlobalDispatcher.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 6
0
        /// 提取游戏包资源到本地目录中
        IEnumerator OnExtractResource()
        {
            string dataPath = Util.DataPath;           //数据目录
            string pkgPath  = Util.AppContentPath();   //游戏包资源目录

            if (Directory.Exists(dataPath))            //删除所有本地资源
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            string pkgMapFile   = pkgPath + "files.txt";
            string localMapFile = dataPath + "files.txt";

            if (File.Exists(localMapFile))             //删除旧的map文件
            {
                File.Delete(localMapFile);
            }

            GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)首次进入游戏,初始化中..." + pkgMapFile);
            if (Application.platform == RuntimePlatform.Android)
            {
                WWW www = new WWW(pkgMapFile);
                Debug.Log("大小:" + www.size);
                yield return(www);

                while (!www.isDone)
                {
                    GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)首次进入游戏,初始化中...|" + www.progress * 100);
                    yield return(null);
                }
                if (www.isDone)
                {
                    File.WriteAllBytes(localMapFile, www.bytes);
                }
            }
            else
            {
                File.Copy(pkgMapFile, localMapFile, true);
            }
            yield return(new WaitForEndOfFrame());

            string[] files    = File.ReadAllLines(localMapFile); //释放所有文件到数据目录
            int      count    = files.Length;                    //总文件
            int      step     = 0;                               //第N个文件
            string   lastLine = files[count - 1];

            lastAppVersion = Util.GetVersion(lastLine, 0);            //包中的版本号

            foreach (var file in files)
            {
                string[] fs = file.Split('|');
                if (fs.Length != 2)
                {
                    break;
                }
                pkgMapFile   = pkgPath + fs[0];
                localMapFile = dataPath + fs[0];
                GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)正在准备进入游戏中... |" + Mathf.FloorToInt((++step * 100 / count)));

#if !SyncLocal                                //进行更新场景
                if (fs[0].Contains("scene/")) //跳过场景资源,进行动态加载
                {
                    loaderMgr.CacheAssetBundleLoaderData(fs[0], fs[1]);
                    continue;
                }
#endif
                string dir = Path.GetDirectoryName(localMapFile);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (Application.platform == RuntimePlatform.Android)
                {
                    WWW www = new WWW(pkgMapFile);
                    yield return(www);

                    if (www.isDone)
                    {
                        File.WriteAllBytes(localMapFile, www.bytes);
                    }
                }
                else
                {
                    if (File.Exists(localMapFile))
                    {
                        File.Delete(localMapFile);
                    }
                    File.Copy(pkgMapFile, localMapFile, true);
                }
                yield return(null);
            }
            yield return(1);

            PlayerPrefs.SetString(appVesionKey, lastAppVersion); // 本地记录v1
            cacheAppVersion = lastAppVersion;                    //解压完成当前的版本号

            StartCoroutine(OnUpdateResource());                  //释放完成,开始启动更新资源
        }
Exemplo n.º 7
0
        /// 更新本地文件
        IEnumerator OnUpdateResource()
        {
            string dataPath = Util.DataPath;              //数据目录

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            string[] lastMapList = VersionUtil.GetVersionMap(dataPath + "files.txt");
            int      count       = lastMapList.Length; //总文件
            int      step        = 0;                  //第N个文件
            string   lastLine    = lastMapList[count - 1];
            string   lastVersion = lastLine;           //最近版本号

            gameVersion = lastVersion.Trim();
#if SyncLocal //不进行更新
            GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)更新资源中... |35");
            for (int i = 0; i < count; i++)
            {
                if (string.IsNullOrEmpty(lastMapList[i]))
                {
                    continue;
                }
                string[] keyValue = lastMapList[i].Split('|');
                if (keyValue.Length != 2)
                {
                    break;
                }
                string f = keyValue[0];

                //收集modules中的功能lua ab文件路径
                if (!string.IsNullOrEmpty(f) && f.IndexOf("lua/lua_skgame_modules_") != -1)
                {
                    if (f.IndexOf(".manifest") == -1)
                    {
                        moduleABPaths.Add(f);
                    }
                }
                GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)更新资源中... |" + Mathf.FloorToInt((++step * 100 / count)));
                // if(keyValue[0].Contains("scene/")){//跳过场景资源,进行动态加载
                //  loaderMgr.CacheAssetBundleLoaderData(keyValue[0], keyValue[1]);
                //  continue;
                // }
            }
#else
            bool hasUpdate = false;//是否存在必要更新
            #region 本地资源版本
            //收集当前版本文件信息
            for (int i = 0; i < count; i++)
            {
                if (string.IsNullOrEmpty(lastMapList[i]))
                {
                    continue;
                }
                string[] keyValue = lastMapList[i].Split('|');
                if (keyValue.Length != 2)
                {
                    break;
                }
                localVersionInfo.Add(keyValue[0].Trim(), keyValue[1].Trim());
            }
            lastAppVersion = Util.GetVersion(lastLine, 0);           //最近app v1
            string lv2 = Util.GetVersion(lastVersion, 1);            //非UI资源
            string lv3 = Util.GetVersion(lastVersion, 2);            //UI资源
            string lv4 = Util.GetVersion(lastVersion, 3);            //脚本资源
            #endregion

            #region  务器资源版本
            GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "正在通讯中... ");
            string remoteVersion = lastVersion;            //cdn版本号 暂定与本地一样
            string url           = AppConst.WebUrl;
            string random        = DateTime.Now.ToString("yyyymmddhhmmss");
            string webMapUrl     = url + "files.txt?v=" + random;
            WWW    www           = new WWW(webMapUrl);
            Debug.Log("资源位置:" + webMapUrl);
            yield return(www);

            if (www.error != null)
            {
                Debug.Log("可能网络问题,也可能服务器资源没提交!  此处可以考虑直接进游戏用本地资源[不进行更新 #SyncLocal]");

                #region 临时解决方案(没有连接上cdn 使用本地资源)
                GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "连接不到服务器中心,应用最近版本进入游戏,建议稍候重启游戏更新!! |100");
                for (int i = 0; i < count; i++)
                {
                    if (string.IsNullOrEmpty(lastMapList[i]))
                    {
                        continue;
                    }
                    string[] keyValue = lastMapList[i].Split('|');
                    if (keyValue.Length != 2)
                    {
                        break;
                    }
                    string f = keyValue[0];

                    //收集modules中的功能lua ab文件路径
                    if (!string.IsNullOrEmpty(f) && f.IndexOf("lua/lua_skgame_modules_") != -1)
                    {
                        if (f.IndexOf(".manifest") == -1)
                        {
                            moduleABPaths.Add(f);
                        }
                    }
                    if (keyValue[0].Contains("scene/"))                    //跳过场景资源,进行动态加载
                    {
                        loaderMgr.CacheAssetBundleLoaderData(keyValue[0], keyValue[1]);
                        continue;
                    }
                }
                yield return(new WaitForSeconds(1));

                OnResourceInited();
                yield break;
                #endregion

                GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)请求失败,您的网络可能不稳定,请稍后再重新启动游戏!");
                yield break;
            }
            else
            {
                Debug.Log("大小:" + www.size);
                int p    = Mathf.FloorToInt(www.progress * 100);
                int size = Mathf.CeilToInt(www.size * 0.001f);
                GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "加载版本配置中,需要消耗流量约 " + size + "kb, 已经完成 |" + p);
            }
            byte[]   webMapData = www.bytes;
            string   webMap     = www.text.Trim();
            string[] webMapList = webMap.Split('\n');
            count         = webMapList.Length;
            lastLine      = webMapList[count - 1];
            remoteVersion = lastLine;
            string remoteAppVersion = Util.GetVersion(lastLine, 0);
            string rv2 = Util.GetVersion(remoteVersion, 1);            //非UI资源
            string rv3 = Util.GetVersion(remoteVersion, 2);            //UI资源
            string rv4 = Util.GetVersion(remoteVersion, 3);            //脚本资源
            #endregion
            Debug.Log("服务器版本:" + remoteVersion);
            bool updateV1 = !remoteAppVersion.Equals(lastAppVersion);
            bool updateV2 = (!lv2.Equals(rv2)) || updateV1;
            bool updateV3 = (!lv3.Equals(rv3)) || updateV1;
            bool updateV4 = (!lv4.Equals(rv4)) || updateV1;

            int resCount = 0;
            int resStep  = 0;
            int uiCount  = 0;
            int uiStep   = 0;
            int luaCount = 0;
            int luaStep  = 0;
            if (updateV2 || updateV3 || updateV4)             //需要更新时,计算各部分文件总量
            {
                for (int i = 0; i < count; i++)
                {
                    if (string.IsNullOrEmpty(webMapList[i]))
                    {
                        continue;
                    }
                    string[] keyValue = webMapList[i].Split('|');
                    if (keyValue.Length != 2)
                    {
                        break;
                    }
                    string n = VersionUtil.GetResNormalName(keyValue[0].Trim());
                    if (n == " UI ")
                    {
                        uiCount++;
                    }
                    else if (n == "配置")
                    {
                        luaCount++;
                    }
                    else if (n == "环境")
                    {
                        resCount++;
                    }
                }
            }

            for (int i = 0; i < count; i++)
            {
                if (string.IsNullOrEmpty(webMapList[i]))
                {
                    continue;
                }
                string[] keyValue = webMapList[i].Split('|');
                if (keyValue.Length != 2)
                {
                    break;
                }
                string f = keyValue[0].Trim();

                //收集modules中的功能lua ab文件路径
                if (!string.IsNullOrEmpty(f) && f.IndexOf("lua/lua_skgame_modules_") != -1)
                {
                    if (f.IndexOf(".manifest") == -1)
                    {
                        moduleABPaths.Add(f);
                    }
                }
                if (keyValue[0].Contains("scene/"))                //跳过场景资源,进行动态加载
                {
                    loaderMgr.CacheAssetBundleLoaderData(keyValue[0], keyValue[1]);
                    continue;
                }
                if (lastVersion == remoteVersion)                //版本一样,不用更新
                {
                    GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)初始化游戏环境中... |" + Mathf.FloorToInt((++step * 100 / count)));
                    continue;
                }

                string fileUrl     = url + f + "?v=" + random; //接取服务器资源
                string localfile   = (dataPath + f).Trim();
                bool   canUpdate   = false;                    // 是否需要更新
                string path        = "";
                string message     = "";
                string msgRes      = "";
                bool   checkUpdate = false;
                msgRes      = VersionUtil.GetResNormalName(f);           // 一般资源的代表名字
                checkUpdate = (msgRes == "" && updateV2) || (msgRes == "环境" && updateV2) || (msgRes == " UI " && updateV3) || (msgRes == "配置" && updateV4);

                if (checkUpdate)
                {
                    canUpdate = !File.Exists(localfile);
                    path      = Path.GetDirectoryName(localfile);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    if (!canUpdate)                     //检查是否更新
                    {
                        string localKey = "*";
                        if (localVersionInfo.ContainsKey(f))
                        {
                            localKey = localVersionInfo[f];
                        }
                        string remoteKey = keyValue[1].Trim();
                        canUpdate = !remoteKey.Equals(localKey);
                        if (canUpdate)
                        {
                            File.Delete(localfile);
                        }
                    }
                }

                if (canUpdate)                 //更新或新增文件
                {
                    //方式1 www更新
                    hasUpdate = true;                     //Debug.Log("更新-->" + fileUrl);
                    www       = new WWW(fileUrl);
                    yield return(www);

                    if (www.error != null)
                    {
                        OnUpdateFailed(path);
                        yield break;
                    }
                    int size = 0;//Mathf.CeilToInt(www.size * 0.001f);
                    //ui 300kb/g
                    //lua 6kb/g
                    if (msgRes == " UI ")
                    {
                        size    = 311 * uiCount;
                        message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb@", msgRes, size);
                        GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, message + Mathf.FloorToInt((++uiStep) * 100 / uiCount));
                    }
                    else if (msgRes == "配置")
                    {
                        size    = 6 * luaCount;
                        message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb@", msgRes, size);
                        GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, message + Mathf.FloorToInt((++luaStep) * 100 / luaCount));
                    }
                    else if (msgRes == "环境")
                    {
                        size    = 151 * resCount;
                        message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb@", msgRes, size);
                        GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, message + Mathf.FloorToInt((++resStep) * 100 / resCount));
                    }
                    //float r = UnityEngine.Random.Range(0.1f, 0.15f); //双进度条时可以用这个,要关掉前面的  yield return www;
                    //while (!www.isDone)
                    //{
                    //    GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_PROGRESS, String.Format("更新{0}资源进度: |", msgRes) + Mathf.FloorToInt(Mathf.Max(www.progress, r) * 100));
                    //    yield return 0;
                    //}
                    File.WriteAllBytes(localfile, www.bytes);
                    yield return(null);
                }
            }
            if (hasUpdate)
            {
                File.WriteAllBytes(dataPath + "files.txt", webMapData);
                PlayerPrefs.SetString(appVesionKey, remoteAppVersion); // 本地记录v1
                cacheAppVersion = remoteAppVersion;                    //解压完成当前的版本号
                gameVersion     = remoteVersion.Trim();
                Debug.Log("写入版本号");
            }
#endif
            //Debug.Log("=================版本:===================>>最近:" + lastVersion + "| 远程:" + remoteVersion);
            yield return(new WaitForEndOfFrame());

            GlobalDispatcher.GetInstance().DispatchEvent(NotiConst.LOADER_COMPLETED, " 游戏环境初始成功!!");
            OnResourceInited();
            yield return(0);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Publish an Event. This will find the dictionary containing only BoolActions
 /// and then find the event with a key attached named the same as the passed string.
 ///
 /// This publish will be used if we are connected to some sort of "CanMove"-like
 /// event, where we want to determine if it's possible to enact an event.
 /// </summary>
 /// <param name="key">Name of the Event in Dictionary</param>
 /// <param name="g">Game Object where the Event took place </param>
 /// <param name="returnValue">Boolean returned from the publish event</param>
 public bool GlobalPublishBool(string key, GameObject g)
 {
     return(GlobalDispatcher.PublishBool(key, g));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Publish an Event. This will find the dictionary containing only VoidActions
 /// and then find the event with a key attached named the same as the passed string.
 /// </summary>
 /// <param name="key">Name of the Event in Dictionary</param>
 /// <param name="g">Game Object where the Event took place </param>
 public void GlobalPublish(string key, GameObject g)
 {
     GlobalDispatcher.Publish(key, g);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Subscribe to an event in the pub sub dictionaries. This will attach
 /// to the dictionary containing only VoidActions, which do not return values
 /// on execution.
 /// </summary>
 /// <param name="key">Name of Value in Dictionary</param>
 /// <param name="sub">Subscription of methods to Key</param>
 public void GlobalSubscribe(string key, Action <GameObject> sub)
 {
     actionEvents.Add(new KeyValuePair <string, Action <GameObject> >(key, sub));
     GlobalDispatcher.Subscribe(key, sub);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Subscribe to an event in the pub sub dictionaries. This will attach
 /// to the dictionary containing only BoolActions, which return bool values
 /// on execution.
 /// </summary>
 /// <param name="key">Name of Value in Dictionary</param>
 /// <param name="sub">Subscription of methods to Key</param>
 public void GlobalSubscribeBool(string key, Func <GameObject, bool> b)
 {
     funcEvents.Add(new KeyValuePair <string, Func <GameObject, bool> >(key, b));
     GlobalDispatcher.SubscribeBool(key, b);
 }
Exemplo n.º 12
0
 /// <summary>Call Ubsubscribe in the Event Dispatcher</summary>
 /// <param name="key">key Subscribed to</param>
 /// <param name="sub">sub Method to be called</param>
 void UnsubscribeBoolDispatcher(string key, Func <GameObject, bool> sub)
 {
     GlobalDispatcher.UnsubscribeBool(key, sub);
 }
Exemplo n.º 13
0
 /// <summary>Call Unsubscribe in the Event Dispatcher</summary>
 /// <param name="key">key Subscribed to</param>
 /// <param name="sub">sub Method to be called</param>
 void UnsubscribeDispatcher(string key, Action <GameObject> sub)
 {
     GlobalDispatcher.Unsubscribe(key, sub);
 }
Exemplo n.º 14
0
 public void IOSCallPayClosedCallBack(string param)
 {
     Debug.Log(">>>>>>>>>>>>IOSCallPayClosedCallBack " + param);
     GlobalDispatcher.GetInstance().DispatchEvent("IOSCallPayClosedCallBack", param);
 }
Exemplo n.º 15
0
 void InitEvent()
 {
     GlobalDispatcher.GetInstance().AddEventListener(NotiConst.LOADER_ALL_COMPLETED, OnAllCompleted);
     GlobalDispatcher.GetInstance().AddEventListener(NotiConst.LOADER_COMPLETED, OnCompleted);
     GlobalDispatcher.GetInstance().AddEventListener(NotiConst.LOADER_PROGRESS, OnProgress);
 }