static public bool RemoveAllEventListener(GameObject go) { UIEventListener listener = go.GetComponent <UIEventListener>(); if (listener == null) { ZLogger.Error("GameObject {0} don't have UIEventListener", go.name); return(false); } if (listener.onClick != null) { listener.onClick = null; } if (listener.onDown != null) { listener.onDown = null; } if (listener.onEnter != null) { listener.onEnter = null; } if (listener.onExit != null) { listener.onExit = null; } if (listener.onUp != null) { listener.onUp = null; } if (listener.onSelect != null) { listener.onSelect = null; } if (listener.onUpdateSelect != null) { listener.onUpdateSelect = null; } return(true); }
//更新函数 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", "您的网络已断开, 请稍候再尝试连接!"); } } }
/// <summary> /// 根据路径的CRC加载中间类resourceItem /// </summary> /// <param name="crc"></param> /// <returns></returns> public ResourceItem LoadResourceAssetBundle(uint crc) { ResourceItem item = null; if (!m_ResourceItemDic.TryGetValue(crc, out item) || item == null) { ZLogger.Error("LoadResourceAssetBundle can not find crc {0} in assetbundleconfig", crc.ToString()); return(item); } if (item.m_AssetBundel != null) { return(item); } item.m_AssetBundel = LoadAssetBundle(item.m_ABName); if (item.m_DependenAssetBundle != null) { for (int i = 0; i < item.m_DependenAssetBundle.Count; i++) { LoadAssetBundle(item.m_DependenAssetBundle[i]); } } return(item); }
public static IZServersListParser CreateServersListInfoParser(uint myId, ZGame gameContext, ZLogger logger) => new ZServersListParser(myId, gameContext, logger);
public void Init() { ZLogger.Info("网络管理基础层初始化"); StarDealMsgCor(); StarReceiveThread(); }
public void Init() { ZLogger.Info("Move系统层初始化"); world = GameWorld.Instance; }
/// <summary> /// 回收资源 /// </summary> /// <param name="obj"></param> /// <param name="maxCacheCount"></param> /// <param name="destoryCache"></param> /// <param name="recycleParent"></param> public void ReleaseObject(GameObject obj, int maxCacheCount = -1, bool destoryCache = false, bool recycleParent = true) { if (obj == null) { return; } ResourceObj resObj = null; int tempGuid = obj.GetInstanceID(); if (!m_ResourceObjDic.TryGetValue(tempGuid, out resObj)) { ZLogger.Error("{0} 对象不是ObjectManager创建的!", obj.name); return; } if (resObj == null) { ZLogger.Error("缓存的ResourObj为空"); return; } if (resObj.m_Already) { ZLogger.Error("该对象已经返回对象池了,检查自己是否清空引用"); return; } #if UNITY_EDITOR obj.name += "(Recycle)"; #endif List <ResourceObj> st = null; if (maxCacheCount == 0) { m_ResourceObjDic.Remove(tempGuid); ResourcesMgr.Instance.ReleaseResource(resObj, destoryCache); resObj.Reset(); m_ResourceObjClassPool.Recycle(resObj); } else//回到到对象池 { if (!m_ObjectPoolDic.TryGetValue(resObj.m_Crc, out st) || st == null) { st = new List <ResourceObj>(); m_ObjectPoolDic.Add(resObj.m_Crc, st); } if (resObj.m_CloneObj) { if (recycleParent) { resObj.m_CloneObj.transform.SetParent(RecyclePoolTrs); } else { resObj.m_CloneObj.SetActive(false); } } if (maxCacheCount < 0 || st.Count < maxCacheCount) { st.Add(resObj); resObj.m_Already = true; //ResourcesMgr做一个引用计数 ResourcesMgr.Instance.DecreaseResourceRef(resObj); } else { m_ResourceObjDic.Remove(tempGuid); ResourcesMgr.Instance.ReleaseResource(resObj, destoryCache); resObj.Reset(); m_ResourceObjClassPool.Recycle(resObj); } } }
public void Init(GameObject canMainCameraObj) { ZLogger.Info("摄像机管理层初始化"); mainCameraObj = canMainCameraObj; mainCemara = canMainCameraObj.GetComponent <Camera>(); }
public void AfterInit() { ZLogger.Info("资源更新检查开始"); cacheAppVersion = PlayerPrefs.GetString(appVesionKey, ""); CheckExtractResource(); }
/// <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 SetLogger(ZLogger logger) { Logger = logger; }
public void Init() { ZLogger.Info("GameObject系统层初始化"); world = GameWorld.Instance; }
private bool ParseCmd(string cmdStr) { bool isSucess = false; try { string[] strs = cmdStr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (strs.Length > 0) { string cmd = strs[0]; if (cmd.Equals("add")) { if (strs.Length < 3) { return(isSucess); } string src = Settings.CurrentDir + "package" + strs[1]; if (!IsExists(src)) { return(isSucess); } string dest = Settings.CurrentDir + strs[2]; string destDir = Path.GetDirectoryName(dest); if (Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } File.Create(dest); File.Move(src, dest); isSucess = true; } else if (cmd.Equals("delete")) { if (strs.Length < 2) { return(isSucess); } string dest = Settings.CurrentDir + strs[1]; if (File.Exists(dest)) { File.Delete(dest); } isSucess = true; } else if (cmd.Equals("modify")) { if (strs.Length < 3) { return(isSucess); } string src = Settings.CurrentDir + "package" + strs[1]; if (!IsExists(src)) { return(isSucess); } string dest = Settings.CurrentDir + strs[2]; string destDir = Path.GetDirectoryName(dest); if (Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } if (File.Exists(dest)) { File.Delete(dest); } File.Create(dest); File.Move(src, dest); isSucess = true; } } } catch (Exception e) { ZLogger.Error(e); } return(isSucess); }
public void Init() { ZLogger.Info("事件管理层初始化"); }
static public bool RemoveEventListener(GameObject go, UIEventEnum tempEnum) { UIEventListener listener = go.GetComponent <UIEventListener>(); if (listener == null) { ZLogger.Error("GameObject {0} don't have UIEventListener", go.name); return(false); } switch (tempEnum) { case UIEventEnum.ON_CLICK: if (listener.onClick != null) { listener.onClick = null; } return(true); case UIEventEnum.ON_DOWN: if (listener.onDown != null) { listener.onDown = null; } return(true); case UIEventEnum.ON_ENTER: if (listener.onEnter != null) { listener.onEnter = null; } return(true); case UIEventEnum.ON_EXIT: if (listener.onExit != null) { listener.onExit = null; } return(true); case UIEventEnum.ON_UP: if (listener.onUp != null) { listener.onUp = null; } return(true); case UIEventEnum.ON_SELECT: if (listener.onSelect != null) { listener.onSelect = null; } return(true); case UIEventEnum.ON_UPDATESELECT: if (listener.onUpdateSelect != null) { listener.onUpdateSelect = null; } return(true); } return(false); }
public void Init() { ZLogger.Info("AB包管理层初始化"); EventMgr.Instance.AddEventListener(UpdataConst.LOADER_ALL_COMPLETED, LoadAssetBundleConfig); }
public void Init() { ZLogger.Info("场景管理层初始化"); CoroutineMgr.Instance.StartCoroutine(sceneLoadCor, SceneLoadAsyncCor()); }
public static List <MaterialInfo> GetRendererInfo(this GameObject gameObject) { if (ShaderPropertyKeywords == null) { ShaderPropertyKeywords = ShaderHelper.CreateShaderPropertyList(); } List <MaterialInfo> materialInfos = new List <MaterialInfo>(); Renderer renderer = gameObject.GetComponent <Renderer>(); if (renderer == null) { renderer = gameObject.GetComponentInChildren <Renderer>(true); } else if (renderer == null) { ZLogger.Error($"Object: {gameObject.name} has no renderers!"); } List <string> keywords = new List <string>(); for (int i = 0; i < renderer.materials.Length; i++) { Material material = renderer.materials[i]; materialInfos.Add(new MaterialInfo(material, i)); int activeIndex = 0; keywords.Clear(); material.GetTexturePropertyNames(keywords); for (int j = 0; j < keywords.Count; j++) { string keyword = keywords[j]; if (material.HasProperty(keyword)) { string value; try { value = material.GetTexture(Shader.PropertyToID(keyword)).name; materialInfos[i].ActiveShaders.Add(new ShaderInfo(material.shader.name, activeIndex, material.shader, keyword, value)); activeIndex++; } catch { } for (int k = 0; k < ShaderPropertyKeywords.Count; k++) { string keyword2 = ShaderPropertyKeywords[j]; try { Color color = material.GetColor(keyword2); //if (color != transparent) //{ materialInfos[i].ActiveShaders.Add(new ShaderInfo(material.shader.name, activeIndex, material.shader, keyword2, color.ToString())); activeIndex++; //} } catch { } } } } foreach (string item in material.shaderKeywords) { materialInfos[i].ShaderKeywords.Add(item); } } return(materialInfos); }
private List <Node> DijkstraConnect(Node source, Node sink, out float routeCost) { string lastKey = "nokey"; routeCost = -1; StringBuilder sb = new StringBuilder(); try { List <Node> ret = null; Dictionary <Node, float> distances = new Dictionary <Node, float>(nodes.Count); Dictionary <Node, Node> previousNodes = new Dictionary <Node, Node>(nodes.Count); HashSet <Node> Q = new HashSet <Node>(nodes); Q.Add(sink); foreach (Node nd in nodes) { distances.SetOrAdd(nd, Single.PositiveInfinity); previousNodes.SetOrAdd(nd, null); } distances.SetOrAdd(sink, float.PositiveInfinity); previousNodes.SetOrAdd(sink, null); previousNodes.SetOrAdd(source, null); ZLogger.Message("DijkstraConnect", debugLevel: DebugLevel.Pathfinding); lastKey = "distances/source"; distances.SetOrAdd(source, 0); foreach (Node neighbor in source.neighbors) { distances[neighbor] = source.neighborDistances[neighbor]; } bool found = false; Node u = source; while (Q.Count > 0) { sb.Clear(); u = Q.MinBy((x) => distances[x]); //foreach (Node nd in u.neighbors) //{ // sb.Append($"nd = {nd}, distance = {distances[nd]}"); //} sb.Append($"Chose {u} as shortest with {distances[u]}- looking for sink {sink}"); ZLogger.Message(sb.ToString(), debugLevel: DebugLevel.Pathfinding); //Console.WriteLine(sb.ToString()); Q.Remove(u); if (u == sink) { break; } foreach (Node v in u.neighbors) { float altDistance = distances[u] + u.neighborDistances[v]; if (altDistance < distances[v]) { distances[v] = altDistance; previousNodes[v] = u; } } } sb.Clear(); foreach (Node node in previousNodes.Keys) { sb.Append($"Node:{node}, previous: {previousNodes[node]}, cumulative distance: {distances[node]}"); } ret = new List <Node>(); routeCost = distances[sink]; sb.Clear(); while (sink != null) { sb.AppendLine($"{sink}"); ret.Add(sink); sink = previousNodes[sink]; } ret.Add(source); sb.AppendLine($"Source Key = {source}"); ZLogger.Message(sb.ToString(), debugLevel: DebugLevel.Pathfinding); ret.Reverse(); return(ret); } catch (Exception e) { sb = new StringBuilder(); foreach (object v in e.Data.Keys) { sb.Append($"{e.Data[v]}: {v}"); } ZLogger.Message($"Couldn't find key! Or key was null... {lastKey} Exception data of type {e.GetType()} follows: {sb}", debugLevel: DebugLevel.Pathfinding); return(new List <Node>()); } }
private void Awake() { DontDestroyOnLoad(this); ZLogger.Info("<游戏启动初始化"); this.Init(); }
public ZLog(IMapper imap) { this.exec = new ExecResult(); this.imap_ = imap; _obj = new ZLogger(); }