IEnumerator CheckVersion() { string path = Globals.wwwPersistenPath + "/version.txt"; WWW www = new WWW(path); yield return(www); string oldVersionStr = "0.0.0"; if (www.error == null) { oldVersionStr = www.text.Trim(); } Version oldVersion = new Version(oldVersionStr); www = new WWW(Globals.wwwStreamingPath + "/version.txt"); yield return(www); string curVersionStr = www.text.Trim(); Version curVersion = new Version(curVersionStr); SampleDebuger.Log("old version : " + oldVersion.proCurVersion + ", cur version : " + curVersion.proCurVersion); if (oldVersion.IsLower(curVersion)) { DeleteUpdateBundle(); } }
public override IFxClientSocket Reconnect() { SampleDebuger.Log("Reconnect"); m_pSocket.Init(this); m_pSocket.Connect(m_oGameObject, m_szIp, m_wPort); return(m_pSocket); }
public string GetBundleUrl(string fileName) { string szUrl = ""; #if UNITY_EDITOR szUrl = Application.dataPath + "/../AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName; //szUrl = m_szAssetUrl + "/AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName; //return Application.streamingAssetsPath + "/AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName; #elif UNITY_WEBGL string szPrefix = ""; if (m_szAssetUrl.Length != 0) { szPrefix = m_szAssetUrl; } else { szPrefix = Application.streamingAssetsPath; } szUrl = szPrefix + "/AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName + "?" + VersionManager.Instance().GetVersionUrl(); #else szUrl = Application.streamingAssetsPath + "/AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName; string szUpdatePath = Application.persistentDataPath + "/AssetBundles/" + SysUtil.GetPlatformName() + "/" + fileName; if (File.Exists(szUpdatePath)) { szUrl = szUpdatePath; } #endif SampleDebuger.LogGreen("bundle url : " + szUrl); return(szUrl); }
public void OnLoginNotifyPlayerTeamInfo(byte[] pBuf) { GameProto.LoginNotifyPlayerTeamInfo oRet = GameProto.LoginNotifyPlayerTeamInfo.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnLoginNotifyPlayerTeamInfo error parse"); return; } string szContent = "OnLoginNotifyPlayerTeamInfo team id : " + oRet.QwTeamId.ToString() + "\n"; for (int i = 0; i < oRet.TeamRoleData.Count; ++i) { szContent += "playerid : " + oRet.TeamRoleData[i].RoleData.QwPlayerId.ToString() + ", slot id : " + oRet.TeamRoleData[i].DwSlotId.ToString() + ", serverid : " + oRet.TeamRoleData[i].DwServerId.ToString() + "\n"; } SampleDebuger.Log(szContent); TeamData.Instance().SetTeamRoleData(oRet.TeamRoleData); if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name != GameConstant.g_szLobbyTeamScene) { AssetBundleLoader.Instance().LoadLevelAsset(GameConstant.g_szLobbyTeamScene, delegate() { } ); } else { TeamPlayerManager.SyncTeamInfo(oRet); } }
public void Init(string szUrl) { SampleDebuger.Log(szUrl); Uri uri = new Uri(szUrl); string szBaseUrl; NameValueCollection nvcParam; ParseUrl(szUrl, out szBaseUrl, out nvcParam); PlayerData.Instance().SetPlatform(nvcParam.Get("platform")); PlayerData.Instance().SetName(nvcParam.Get("name")); PlayerData.Instance().SetHeadImage(nvcParam.Get("head_img")); StartCoroutine(H5Helper.SendGet(PlayerData.Instance().proHeadImage, delegate(Texture2D tex) { PlayerData.Instance().SetHeadTex(tex); }) ); PlayerData.Instance().SetAccessToken(nvcParam.Get("access_token")); PlayerData.Instance().SetOpenId(nvcParam.Get("openid")); string szSex = nvcParam.Get("sex"); string szExpiresDate = nvcParam.Get("expires_date"); uint dwSex = 0; uint dwExpiresDate = 0; uint.TryParse(szSex, out dwSex); uint.TryParse(szExpiresDate, out dwExpiresDate); PlayerData.Instance().SetSex(dwSex); PlayerData.Instance().SetExpiresDate(dwExpiresDate); }
private IEnumerator OnLoadAssetList(PreloadFileModel model, CallBackWithPercent cb) { List <string> list = model.fileList; for (int i = 0; i < list.Count; i++) { string path = list[i]; string bundleName = path.ToLower(); string assetName = path + ".prefab"; AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(bundleName, assetName, typeof(UnityEngine.Object)); if (request != null) { yield return(StartCoroutine(request)); GameObject obj = request.GetAsset <UnityEngine.GameObject>(); _cachePrefabs.Add(bundleName, new ABPrefabInfo(obj)); } else { SampleDebuger.LogError("bundle ++" + bundleName + "++ can't loading"); } cb(i + 1, list.Count); } }
private byte[] StreamingLoader(ref string szFileName) { string szFilePath = ""; #if (UNITY_EDITOR && DEVELOP_VERSION) || UNITY_WEBGL szFilePath = Globals.streamingPath + "/Lua/" + szFileName; #else szFilePath = Globals.persistenPath + "/Lua/" + szFileName; #endif string ext = System.IO.Path.GetExtension(szFilePath).ToLower(); if (!ext.Equals("lua")) { szFilePath += ".lua"; } if (!System.IO.File.Exists(szFilePath)) { SampleDebuger.LogColorAquamarine("can't find file " + szFilePath); return(null); } SampleDebuger.LogColorAquamarine(szFilePath); return(System.IO.File.ReadAllBytes(szFilePath)); //return System.Text.ASCIIEncoding.UTF8.GetBytes(System.IO.File.ReadAllText(szFilePath)); }
IEnumerator GetServerVersion() { string szVersion = GameInstance.Instance().proServerUrl + GameInstance.Instance().proServerVersion + "?" + Time.realtimeSinceStartup.ToString(); WWW www = new WWW(szVersion); yield return(www); if (!string.IsNullOrEmpty(www.error)) { //无法连接资源服务器 SampleDebuger.LogWarning("url " + www.url + " ,error:" + www.error); m_comEnvChecker.GameInit(); yield break; } if (!www.isDone) { yield return(www); } string versionStr = www.text.Trim(); m_verServerVersion = new Version(versionStr); SampleDebuger.Log(" server version = " + m_verServerVersion.ToString()); if (VersionManager.Instance().m_verVersion.IsLower(m_verServerVersion)) { StartCoroutine(CheckVersionContent()); } else { //进入游戏 m_comEnvChecker.GameInit(); } }
public bool InitSession(SessionType eType, string szIp, UInt16 wPort) { SampleDebuger.Log("type : " + eType.ToString() + ", ip : " + szIp + ", port : " + wPort); m_szIP = szIp; m_wPort = wPort; m_eSessionType = eType; switch (m_eSessionType) { case SessionType.SessionType_TCP: { m_pSession = new BinarySession(this); } break; case SessionType.SessionType_WebSocket: { m_pSession = new WebSocketSession(this); } break; default: { return(false); //throw new ArgumentException("error session type : " + m_eSessionType.ToString()); } } m_pSession.Init(m_szIP, m_wPort); m_pClientSocket = m_pSession.Reconnect(); return(true); }
public void OnGameNotifyPlayerGameSceneInfo(byte[] pBuf) { GameProto.GameNotifyPlayerGameSceneInfo oRet = GameProto.GameNotifyPlayerGameSceneInfo.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.LogYellow("OnGameNotifyPlayerGameSceneInfo error parse"); return; } SampleDebuger.LogBlue("game scene state : " + oRet.State.ToString()); for (int i = 0; i < oRet.Players.Count; i++) { if (oRet.Players[i].QwPlayerId != 0) { SampleDebuger.LogBlue(string.Format("game scene info : [{0}, {1}, {2}, {3}]", oRet.Players[i].QwPlayerId.ToString(), oRet.Players[i].SzNickName, oRet.Players[i].SzAvatar, oRet.Players[i].DwSex.ToString())); GameData.Instance().SetSlotId((uint)i, oRet.Players[i].QwPlayerId); GameData.Instance().SetRoleDate(oRet.Players[i].QwPlayerId, oRet.Players[i]); TetrisDataManager.Instance().SetPlayer(oRet.Players[i].QwPlayerId); } } if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name != SysUtil.GetScesneNameBySceneState(oRet.State)) { AssetBundleLoader.Instance().LoadLevelAsset(SysUtil.GetScesneNameBySceneState(oRet.State), delegate() { SampleDebuger.LogBlue("scene info load level : " + SysUtil.GetScesneNameBySceneState(oRet.State)); } ); } }
/// <summary> /// 更新下载进度 /// </summary> /// <param name="done"></param> /// <param name="total"></param> public void DownloadProcess(long done, long total) { SampleDebuger.Log("++ done: " + done + " total: " + total); progressSlider.value = done > 0 ? (float)done / (float)total : 0; //descText.text = LangSetting.GetWord("UI_DownLoadingRes_desc"); //statusText.text = Mathf.Floor(done / 1024).ToString() + "KB /" + Mathf.Floor(total / 1024).ToString() + "KB"; }
public void GetEnityFromPoolAsync(string assetName, Action <GameObject> cb) { Queue <AssetPoolItem> pool = null; _entityPoolMap.TryGetValue(assetName, out pool); GameObject obj = null; if (pool != null && pool.Count > 0) { AssetPoolItem item = pool.Dequeue(); obj = item.gameObject; obj.SetActive(true); cb(obj); } else { GetEntityPrefabAsync(assetName, (prefab) => { obj = GameObject.Instantiate <GameObject>(prefab); if (obj != null) { AssetPoolItem item = obj.GetComponent <AssetPoolItem>(); if (item != null) { item.SetAssetName(assetName); } else { SampleDebuger.LogError("asset " + assetName + " is not a pool item"); } cb(obj); } }); } }
public void RegistMessage(string szProtoName, Action <byte[]> pfCallBack) { if (m_mapCallBack.ContainsKey(szProtoName)) { SampleDebuger.LogError("already registed proto " + szProtoName); return; } m_mapCallBack[szProtoName] = pfCallBack; }
/// <summary> /// 下载进度变化回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDownloadProcess(object sender, DownloadProgressChangedEventArgs e) { SampleDebuger.Log(string.Format("received: {0} total: ", e.BytesReceived, e.TotalBytesToReceive)); lock (AssetDownloader.Instance().m_lockWeb) { m_qwLoaded = e.BytesReceived; m_qwTotal = e.TotalBytesToReceive; } }
public void OnGameNotifyPlayerGameRoleData(byte[] pBuf) { GameProto.GameNotifyPlayerGameRoleData oRet = GameProto.GameNotifyPlayerGameRoleData.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnGameNotifyPlayerGameRoleData error parse"); return; } }
public void OnLoginNotifyPlayerGameKick(byte[] pBuf) { GameProto.LoginNotifyPlayerGameKick oRet = GameProto.LoginNotifyPlayerGameKick.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnLoginNotifyPlayerGameKick error parse"); return; } SampleDebuger.Log("game kick ret : " + oRet.DwResult.ToString()); }
public void OnGameNotifyPlayerDead(byte[] pBuf) { GameProto.GameNotifyPlayerDead oRet = GameProto.GameNotifyPlayerDead.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.LogYellow("GameNotifyPlayerDead error parse"); return; } SampleDebuger.LogGreen("player : " + oRet.DwPlayerId.ToString() + " dead"); }
public void OnGameNotifyPlayeGameEnd(byte[] pBuf) { GameProto.GameNotifyPlayeGameEnd oRet = GameProto.GameNotifyPlayeGameEnd.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.LogYellow("OnGameNotifyPlayeGameEnd error parse"); return; } SampleDebuger.LogGreen("game end!!!!!!!!!"); }
public void OnLoginAckPlayerInviteTeam(byte[] pBuf) { GameProto.LoginAckPlayerInviteTeam oRet = GameProto.LoginAckPlayerInviteTeam.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnLoginAckPlayerInviteTeam error parse"); return; } SampleDebuger.Log("invite team ret : " + oRet.DwResult.ToString()); }
public void Sync(GameProto.GameNotifyPlayerNextTetris oTetris) { if (m_oNextTetris == null) { m_oNextTetris = new Tetris(); } m_oNextTetris.Init(oTetris.NextTetris); SampleDebuger.LogGreen(string.Format("next tetris [{0},{1}]", oTetris.NextTetris.DwTetrisShape, oTetris.NextTetris.DwTetrisDirect)); m_bNeedRefresh = true; }
public IEnumerator Reload() { var request = AssetBundleManager.ReloadManifest(GetBundleDirName()); if (request != null) { SampleDebuger.Log("reloading manifest"); yield return(StartCoroutine(request)); } }
public void OnGameNotifyPlayerGameConfig(byte[] pBuf) { GameProto.GameNotifyPlayerGameConfig oRet = GameProto.GameNotifyPlayerGameConfig.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.LogYellow("OnGameNotifyPlayerGameConfig error parse"); return; } TetrisData.InitGameConfig(oRet); }
public void OnConnect() { SampleDebuger.Log("game connected"); GameData.Instance().Reset(); GameProto.PlayerRequestGameEnter oRequest = new GameProto.PlayerRequestGameEnter(); oRequest.QwPlayerId = PlayerData.Instance().proPlayerId; SysUtil.SendMessage(m_pSession, oRequest, "GameProto.PlayerRequestGameEnter"); }
public void OnLoginNotifyPlayerRefuseEnterTeam(byte[] pBuf) { GameProto.LoginNotifyPlayerRefuseEnterTeam oRet = GameProto.LoginNotifyPlayerRefuseEnterTeam.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnLoginNotifyPlayerRefuseEnterTeam error parse"); return; } SampleDebuger.LogError("OnLoginNotifyPlayerRefuseEnterTeam reason : " + oRet.SzReason); }
IEnumerator CheckVersionContent() { string szVersionMark = GameInstance.Instance().proServerUrl + string.Format(GameInstance.Instance().proServerMarkPath, VersionManager.Instance().GetVersionUrl()) + "?" + Time.realtimeSinceStartup.ToString(); WWW www = new WWW(szVersionMark); SampleDebuger.Log("+++++++++++ checkVersionContent +++++++++++ "); yield return(www); if (!string.IsNullOrEmpty(www.error)) { SampleDebuger.Log(szVersionMark); AssetBundleLoader.Instance().LoadAsset(GameObjectConstant.GetABUIPath(GameObjectConstant.g_szConfirmPanel), GameObjectConstant.g_szConfirmPanel, delegate(UnityEngine.Object ob) { GameObject go_RoleList = Instantiate((GameObject)ob, MainCanvas.Instance().transform); go_RoleList.GetComponent <ConfirmPanel>().Init("检测到大版本更新,请前往官网或者应用商店下载最新版本", delegate(object ob1) { //todo 下载 SampleDebuger.LogGreen("begin down load"); }, null, delegate(object ob1) { //todo 取消下载 SampleDebuger.LogGreen("cancel down load"); }, null ); } ); yield break; } //下载更新包 if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) { m_comEnvChecker.StartDownload(); } else { AssetBundleLoader.Instance().LoadAsset(GameObjectConstant.GetABUIPath(GameObjectConstant.g_szConfirmPanel), GameObjectConstant.g_szConfirmPanel, delegate(UnityEngine.Object ob) { GameObject go_RoleList = Instantiate((GameObject)ob, MainCanvas.Instance().transform); go_RoleList.GetComponent <ConfirmPanel>().Init("检测到游戏更新,请点击更新!", delegate(object ob1) { m_comEnvChecker.StartDownload(); }, null, delegate(object ob1) { //todo 取消下载 SampleDebuger.LogGreen("cancel down load"); }, null ); } ); } }
public void OnLoginAckPlayerGameStart(byte[] pBuf) { GameProto.LoginAckPlayerGameStart oRet = GameProto.LoginAckPlayerGameStart.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.Log("OnLoginAckPlayerGameStart error parse"); return; } SampleDebuger.Log("game start : " + oRet.DwResult.ToString()); H5Manager.Instance().ConnectGame(oRet.SzListenIp, (ushort)oRet.DwPlayerPort); }
public override bool IsDone() { // Return if meeting downloading error. // m_DownloadingError might come from the dependency downloading. if (m_sceneRequest == null && m_DownloadingError != null) { SampleDebuger.LogError(m_DownloadingError); return(true); } return(m_sceneRequest != null && m_sceneRequest.isDone); }
public void DownloadUrl(string url) { m_dwCurFileCount++; Uri uri = new Uri(url, UriKind.Absolute); string tmpFile = m_szTempPath + "/" + m_dwCurFileCount + "-" + DateTime.Now.Ticks.ToString(); m_webClient.DownloadFileAsync(uri, tmpFile, tmpFile); SampleDebuger.Log("++++ downloading url: " + uri.ToString()); }
/// <summary> /// 解压文件到指定路径 /// </summary> /// <param name="targetPath">绝对路径</param> /// <param name="zipFilePath">绝对路径</param> public static void DecompressToDirectory(string targetPath, string zipFilePath) { if (File.Exists(zipFilePath)) { var compressed = File.OpenRead(zipFilePath); DecompressToDirectory(targetPath, compressed); } else { SampleDebuger.LogError("Zip不存在: " + zipFilePath); } }
public bool Send(byte[] pBuf, uint dwLen) { if (m_pSession != null) { return(m_pSession.Send(pBuf, dwLen)); } else { SampleDebuger.LogError("session is null"); return(false); } }