//连接 public void SocketConnect() { if (isConnected || m_ConnectState == ConnectStateType.Connecting) { ZLogger.Info("Socket已经连接上了,别再重复进行连接"); return; } string tempStrNewIp = ""; AddressFamily tempAddressFamily = AddressFamily.InterNetwork; //这里准备以后引入一个解析IP地址的库,从而可以ipv4,还是ipv6 no edit ZLogger.Info("Socket AddressFaminly:{0} 原始IP:{1}, 结果IP:{2}, 端口:{3}", tempAddressFamily, m_IP, tempStrNewIp, m_Port); m_ClientSocket = new Socket(tempAddressFamily, SocketType.Stream, ProtocolType.Tcp); m_ClientSocket.SendTimeout = 1000; //指定同步 Send 调用将超时的时间长度 m_ClientSocket.ReceiveTimeout = 5000; //指定同步 Receive 调用将超时的时间长度 m_ClientSocket.NoDelay = true; //指定流 Socket 是否正在使用 Nagle 算法 m_ClientSocket.SendBufferSize = 1024 * 8; //指定 Socket 发送缓冲区的大小 m_ClientSocket.ReceiveBufferSize = NetConst.TEMP_MSG_SIZE; //获取或设置此 ServicePoint 使用的套接字的接收缓冲区的大小 m_ClientSocket.Blocking = true; //指示 Socket 是否处于阻止模式 m_ConnectState = ConnectStateType.Connecting; try { m_ClientSocket.BeginConnect(tempStrNewIp, m_Port, new AsyncCallback(OnConnectCB), m_ClientSocket); } catch (Exception e) { //设置失败次数++ ZLogger.Info("连接不通:{0} ==> {1}", e.Message, e.ToString()); m_ConnectState = ConnectStateType.ConnectFail; OnDisconnect(NetResultType.ConnectTimeOut, "连接游戏服务器失败!(-1)"); } }
//加载失败 void OnUpdateFailed(string file) { string message = "游戏环境初始失败!>" + file; ZLogger.Info("更新失败!>" + file); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, message, 0); }
/// <summary> /// 连接服务器 /// </summary> public void LinkServer(string canIP, int canPort) { m_Ip = canIP; m_Port = canPort; ZLogger.Info("连接------->>id: {0} , port: {1}", m_Ip, m_Port); NetMgr.Instance.SendConnect(m_Ip, m_Port); }
//连接上服务器回调 private void OnConnectCB(IAsyncResult asr) { try { Socket tempClientSocket = (Socket)asr.AsyncState; if (tempClientSocket.Connected) { tempClientSocket.EndConnect(asr); //重置失败次数=0 tempClientSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); m_ConnectState = ConnectStateType.Connected; m_DispatchConnectBoo = true; //进行广播 ZLogger.Info("socket 连接成功 net Connected ip={0},prot={1}", m_IP, m_Port); } else { //设置连接失败次数++ m_ConnectState = ConnectStateType.ConnectFail; OnDisconnect(NetResultType.ConnectTimeOut, "连接超时!(404)"); } } catch (Exception e) { //设置连接失败次数++ m_ConnectState = ConnectStateType.ConnectFail; OnDisconnect(NetResultType.Exception, "连接超时:" + e.Message); } }
public void Init() { ZLogger.Info("数据管理层初始化"); m_DataDic.Clear(); EventMgr.Instance.AddEventListener(ABMgrConst.AB_CONFIG_LOAD_COMPLETE, ExtractData); }
public void Init() { ZLogger.Info("UTexture层初始化"); EventMgr.Instance.AddEventListener(ABMgrConst.AB_CONFIG_LOAD_COMPLETE, LoasHoldTexture); EventMgr.Instance.AddEventListener(SceneConst.SWITCH_SCENE_STAR_LOAD, ClearCache); }
public void Init(Transform canObjTrs) { ZLogger.Info("USprite层初始化"); USpriteRecyclePoolTrs = canObjTrs; USpriteRecyclePoolTrs.gameObject.SetActive(false); EventMgr.Instance.AddEventListener(ABMgrConst.AB_CONFIG_LOAD_COMPLETE, LoadHoldUSprite); EventMgr.Instance.AddEventListener(SceneConst.SWITCH_SCENE_STAR_LOAD, ClearCache); }
public void Init() { ZLogger.Info("UI管理层辅助层初始化"); UIClassList = new List <string>(); ModelDic = new List <InterfaceModel>(); ControlDic = new List <InterfaceControl>(); EventMgr.Instance.AddEventListener(DataConst.DATA_LOAD_COMPLETE, _InitUIClassList); }
public void OnDestroy() { if (m_ClientSocket != null) { m_ClientSocket.Close(); m_ClientSocket = null; } CloseReceiveThreadAndDealMsgCor(); ZLogger.Info("NetworkManager was destroy"); }
public DDictionary <int, WeaponComponent> WeaponComDic = new DDictionary <int, WeaponComponent>(); // public void Init(Transform canSceneTrs, Transform canRecycleTrs) { ZLogger.Info("世界角色中心层初始化"); sceneTrs = canSceneTrs; recycleTrs = canRecycleTrs; recycleTrs.gameObject.SetActive(false); //--------系统数量-------目前:1 GameObjectSystem.Instance.Init(); }
public void Init(Transform recycleTrs, Transform sceneTrs) { ZLogger.Info("对象池管理层初始化"); m_ResourceObjClassPool = GetOrCreateClassPool <ResourceObj>(1000); RecyclePoolTrs = recycleTrs; RecyclePoolTrs.gameObject.SetActive(false); SceneTrs = sceneTrs; EventMgr.Instance.AddEventListener(SceneConst.SWITCH_SCENE_STAR_LOAD, ClearCache); }
public void Init(Transform canTrs) { ZLogger.Info("音效管理层初始化"); SoundStageTrs = canTrs; bgAudio = GameObject.Find("BGStage").GetComponent <AudioSource>(); bgAudio.loop = true; uiAudio = GameObject.Find("UIStage").GetComponent <AudioSource>(); EventMgr.Instance.AddEventListener(ABMgrConst.AB_CONFIG_LOAD_COMPLETE, LoadHoldAudio); EventMgr.Instance.AddEventListener(SceneConst.SWITCH_SCENE_STAR_LOAD, ClearCache); }
public void Init(MonoBehaviour mono) { ZLogger.Info("资源管理层初始化"); for (int i = 0; i < (int)LoadResPriority.RES_NUM; i++) { m_LoadingAssetList[i] = new List <AsynvLoadResParam>(); } //m_StarMono = mono; //m_StarMono.StartCoroutine(AsyncLoadCor()); CoroutineMgr.Instance.StartCoroutine(resourcesLoadCor, AsyncLoadCor()); EventMgr.Instance.AddEventListener(SceneConst.SWITCH_SCENE_STAR_LOAD, ClearCache); }
public void Init() { ZLogger.Info("UI管理层初始化"); uiRoot = GameObject.Find("UIRoot"); _layerTypeDic = new Dictionary <int, GameObject>(); closeViewLayer = GameObject.Find(CLOSE_LAYER); _layerTypeDic.Add(CLOSE_LAYER_INT, closeViewLayer); nickLayer = GameObject.Find(NICK_LAYER); _layerTypeDic.Add(NICK_LAYER_INT, nickLayer); lowLayer = GameObject.Find(LOW_LAYER); _layerTypeDic.Add(LOW_LAYER_INT, lowLayer); middleLayer = GameObject.Find(MIDDLE_LAYER); _layerTypeDic.Add(MIDDLE_LAYER_INT, middleLayer); dialogLayer = GameObject.Find(DIALOG_LAYER); _layerTypeDic.Add(DIALOG_LAYER_INT, dialogLayer); highLayer = GameObject.Find(HIGH_LAYER); _layerTypeDic.Add(HIGH_LAYER_INT, highLayer); topLayer = GameObject.Find(TOP_LAYER); _layerTypeDic.Add(TOP_LAYER_INT, topLayer); canvas = GameObject.Find(CANVAS_LAYER); WaitOpenViewList = new List <InterfaceView>(); OpeningViewsDic = new Dictionary <int, InterfaceView>(); ForeverCacheViewDic = new List <InterfaceView>(); CacheViewDic = new List <InterfaceView>(); SortOpenViewsList = new List <InterfaceView>(); UpdateErrorViewDic = new Dictionary <string, bool>(); _PopViewNameDic = new Dictionary <string, int>(); openViewCountDic = new Dictionary <int, int>(); topView = null; //打开界面数计数器 ResetOpenViewIndex(); InitHideLayer(); RegisterHandler(); InitBoo = true; }
//委托,在每个界面发生状态变化时候需要做的操作 private void _ViewStateChange(InterfaceView viewCan, UIMgr.ViewStateType type) { List <UiExcel> tempUiExcelList = DataMgr.Instance.tableUI.GetInfoByNameAndValue("name", viewCan.ViewName()); if (tempUiExcelList.Count < 1) { ZLogger.Error("找不到界面的信息,请查看UIExcel表配置是否正确!"); return; } UiExcel uiData = tempUiExcelList[0]; switch (type) { case ViewStateType.CLOSE: UpdateErrorViewDic.Remove(viewCan.ViewName()); _UpdateCacheView(uiData.id, viewCan, false, uiData.holdBoo); _AdjustMaskAndActive(); break; case ViewStateType.LOAD_COMPLETE: break; case ViewStateType.UNLOAD: _UpdateDel(uiData.id, viewCan); break; case ViewStateType.LOAD_FAIL: _RemoveWaitOpenValue(viewCan); break; case ViewStateType.GIVE_UP_LOAD: ZLogger.Info("请注意:{0}放弃加载!!!,原因是:没加载完成之前,有人调用了closeview()", viewCan.ViewName()); _RemoveWaitOpenValue(viewCan); break; case ViewStateType.OPEN: _RemoveWaitOpenValue(viewCan); _UpdateCacheView(uiData.id, viewCan, true, uiData.holdBoo); _CheckExclusion(uiData, viewCan); _SortOpeningView(); _AdjustMaskAndActive(); break; case ViewStateType.LOAD_SUCESS: break; } }
//失去连接或连接失败 private void OnDisconnect(NetResultType canType, string canStr = "") { CloseSocket();//关闭Socket //以下是根据不同情况输出 if (canType == NetResultType.Disconnect) { ZLogger.Info("net 正常主动断线"); } else if (canType == NetResultType.ConnectTimeOut) { ZLogger.Info("net 连接服务器超时"); } else if (canType == NetResultType.Exception) { ZLogger.Error("net 异常断开服务器:{0}, type:{1}", canStr, canType.ToString()); } }
//更新函数 lua private void UpdateForLua() { if (m_ConnectState == ConnectStateType.Connected) { if (m_DispatchConnectBoo) { m_DispatchConnectBoo = false; ++connectTimes; if (connectTimes > 1) { NetCallMethod("OnReConnect"); ZLogger.Info("重新连接到 网关服务器 ---> 重新请求"); } else { NetCallMethod("OnConnect"); ZLogger.Info("成功连接到 网关服务器 ---> 开始游戏"); } } } else if (m_ConnectState != ConnectStateType.None) { if (m_ConnectState == ConnectStateType.ConnectFail) { NetCallMethod("ShowTimeOut", "连接游戏服务器失败, 请稍候再尝试连接!"); } else if (m_ConnectState == ConnectStateType.Disconnect) { NetCallMethod("OnDisconnect"); } //多次心跳接收不到掉线 else if (m_ConnectState == ConnectStateType.OffLine) { NetCallMethod("ShowTimeOut", "您的网络已断开, 请稍候再尝试连接!"); } } }
public void Init() { ZLogger.Info("AB包管理层初始化"); EventMgr.Instance.AddEventListener(UpdataConst.LOADER_ALL_COMPLETED, LoadAssetBundleConfig); }
public void Init() { ZLogger.Info("GameObject系统层初始化"); world = GameWorld.Instance; }
public void Init() { ZLogger.Info("事件管理层初始化"); }
/// <summary> /// 更新本地文件 /// </summary> /// <returns></returns> IEnumerator OnUpdateResource() { string dataPath = UtilTool.DataPath; //数据目录 if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } string[] lastMapList = UtilTool.GetVersionMap(dataPath + "files.txt"); int count = lastMapList.Length; //总文件 int step = 0; //第N个文件 string lastLine = lastMapList[count - 1]; string lastVersion = lastLine; //最近版本号 gameVersion = lastVersion.Trim(); //不进行更新 no edit 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 = UtilTool.GetVersion(lastLine, 0); //最近app v1 string lv2 = UtilTool.GetVersion(lastVersion, 1); //非UI资源 string lv3 = UtilTool.GetVersion(lastVersion, 2); //UI资源 string lv4 = UtilTool.GetVersion(lastVersion, 3); //脚本资源 #endregion #region 务器资源版本 EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, "正在通讯中... ", 0); string remoteVersion = lastVersion;//cdn版本号 暂定与本地一样 string url = AppConst.WebUrl; string random = DateTime.Now.ToString("yyyymmddhhmmss"); string webMapUrl = url + "files.txt?v=" + random; UnityWebRequest unityWeb = new UnityWebRequest(webMapUrl); ZLogger.Info("资源位置:" + webMapUrl); yield return(unityWeb); if (unityWeb.error != null) { ZLogger.Info("可能网络问题,也可能服务器资源没提交! 此处可以考虑直接进游戏用本地资源[不进行更新 #SyncLocal]"); #region 临时解决方案(没有连接上cdn 使用本地资源) EventMgr.Instance.TriggerEvent(UpdataConst.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]; //if (keyValue[0].Contains("scene/")) //{//跳过场景资源,进行动态加载 // loaderMgr.CacheAssetBundleLoaderData(keyValue[0], keyValue[1]); // continue; //} } yield return(new WaitForSeconds(1)); OnResourceInited(); yield break; #endregion //EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, "(此过程不消耗任何流量,请放心等待)请求失败,您的网络可能不稳定,请稍后再重新启动游戏!"); yield break; } else { int p = Mathf.FloorToInt(unityWeb.downloadProgress * 100); int size = Mathf.CeilToInt(9877); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, "加载版本配置中,需要消耗流量约 " + size + "kb, 已经完成", p); } byte[] webMapData = unityWeb.downloadHandler.data; string webMap = unityWeb.downloadHandler.text.Trim(); string[] webMapList = webMap.Split('\n'); count = webMapList.Length; lastLine = webMapList[count - 1]; remoteVersion = lastLine; string remoteAppVersion = UtilTool.GetVersion(lastLine, 0); string rv2 = UtilTool.GetVersion(remoteVersion, 1); //非UI资源 string rv3 = UtilTool.GetVersion(remoteVersion, 2); //UI资源 string rv4 = UtilTool.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; } if (keyValue[0].Contains("/UI/")) { uiCount++; } else if (keyValue[0].Contains("/Lua/")) { luaCount++; } else { 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(); //if (keyValue[0].Contains("scene/")) //{//跳过场景资源,进行动态加载 // loaderMgr.CacheAssetBundleLoaderData(keyValue[0], keyValue[1]); // continue; //} if (lastVersion == remoteVersion)//版本一样,不用更新 { EventMgr.Instance.TriggerEvent(UpdataConst.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 = ""; bool checkUpdate = false; checkUpdate = ((f.Contains("/UI/") && updateV3) || (f.Contains("/Lua/") && updateV4) || updateV2); 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 UnityWebRequest更新 hasUpdate = true; //Debug.Log("更新-->" + fileUrl); unityWeb = new UnityWebRequest(fileUrl); yield return(unityWeb); if (unityWeb.error != null) { OnUpdateFailed(path); yield break; } int size = 0; if (f.Contains("/UI/")) { size = 311 * uiCount; message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb", "UI", size); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, message, Mathf.FloorToInt((++uiStep) * 100 / uiCount)); } else if (f.Contains("/Lua/")) { size = 6 * luaCount; message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb", "Lua", size); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, message, Mathf.FloorToInt((++luaStep) * 100 / luaCount)); } else { size = 151 * resCount; message = String.Format("正在更新{0}文件, 需要消耗流量约 {1} kb", "环境", size); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_PROGRESS, message, Mathf.FloorToInt((++resStep) * 100 / resCount)); } //byte[] tempDownByte = unityWeb.downloadHandler.data; File.WriteAllBytes(localfile, unityWeb.downloadHandler.data); yield return(null); } } if (hasUpdate) { File.WriteAllBytes(dataPath + "files.txt", webMapData); PlayerPrefs.SetString(appVesionKey, remoteAppVersion); // 本地记录v1 cacheAppVersion = remoteAppVersion; //解压完成当前的版本号 gameVersion = remoteVersion.Trim(); ZLogger.Info("写入版本号"); } //Debug.Log("=================版本:===================>>最近:" + lastVersion + "| 远程:" + remoteVersion); yield return(new WaitForEndOfFrame()); EventMgr.Instance.TriggerEvent(UpdataConst.LOADER_COMPLETED, " 游戏更新检查完毕!!", 100); OnResourceInited(); yield return(0); }
public void Init() { ZLogger.Info("资源更新管理层初始化"); }
public void AfterInit() { ZLogger.Info("资源更新检查开始"); cacheAppVersion = PlayerPrefs.GetString(appVesionKey, ""); CheckExtractResource(); }
public void Init() { ZLogger.Info("网络管理基础层初始化"); StarDealMsgCor(); StarReceiveThread(); }
public void Init() { ZLogger.Info("场景管理层初始化"); CoroutineMgr.Instance.StartCoroutine(sceneLoadCor, SceneLoadAsyncCor()); }
public void Init(GameObject canMainCameraObj) { ZLogger.Info("摄像机管理层初始化"); mainCameraObj = canMainCameraObj; mainCemara = canMainCameraObj.GetComponent <Camera>(); }
private void Awake() { DontDestroyOnLoad(this); ZLogger.Info("<游戏启动初始化"); this.Init(); }
public void Init() { ZLogger.Info("Move系统层初始化"); world = GameWorld.Instance; }