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); } }); } }
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); } }
public void RegistMessage(string szProtoName, Action <byte[]> pfCallBack) { if (m_mapCallBack.ContainsKey(szProtoName)) { SampleDebuger.LogError("already registed proto " + szProtoName); return; } m_mapCallBack[szProtoName] = pfCallBack; }
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); }
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); } }
/// <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 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 OnGameNotifyPlayerGameState(byte[] pBuf) { GameProto.GameNotifyPlayerGameState oRet = GameProto.GameNotifyPlayerGameState.Parser.ParseFrom(pBuf); if (oRet == null) { SampleDebuger.LogYellow("OnGameNotifyPlayerGameState error parse"); return; } SampleDebuger.LogBlue("game state : " + oRet.State.ToString()); GameData.Instance().SetGameSceneState(oRet.State); if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name != SysUtil.GetScesneNameBySceneState(oRet.State)) { AssetBundleLoader.Instance().LoadLevelAsset(SysUtil.GetScesneNameBySceneState(oRet.State), delegate() { SampleDebuger.LogBlue("game state load level : " + SysUtil.GetScesneNameBySceneState(oRet.State)); } ); } switch (oRet.State) { case GameProto.EGameSceneState.EssNone: break; case GameProto.EGameSceneState.EssPrepare: case GameProto.EGameSceneState.EssGameReady: { } break; case GameProto.EGameSceneState.EssGaming: { ReadyTime.SetGameBegin(); } break; case GameProto.EGameSceneState.EssTransact: { } break; default: { SampleDebuger.LogError("error game state : " + ((uint)(oRet.State)).ToString()); } break; } TetrisData.SetGameSceneState(oRet.State); }
/// <summary> /// 将文件拷贝到路径中 /// </summary> /// <param name="streamPath"></param> /// <returns></returns> IEnumerator BeginCopy(string path) { yield return(new WaitForSeconds(2.0f)); WWW www = new WWW(path + "/streamPath.txt"); yield return(www); string[] content = www.text.Split(new string[] { "\n" }, System.StringSplitOptions.RemoveEmptyEntries); www.Dispose(); int total = content.Length; int curIndex = 0; foreach (string item in content) { string it = item.Trim(); //window下会有\r,需要删除 int fileFlag = int.Parse(it.Split('|')[1]); it = it.Split('|')[0]; SampleDebuger.Log(path); it = it.Trim(); if (fileFlag == 1) { www = new WWW(path + it); yield return(www); File.WriteAllBytes(Application.persistentDataPath + it, www.bytes); //更新进度 SetProcess(curIndex, total); www.Dispose(); } else if (fileFlag == 0) { SampleDebuger.Log("Create dir " + Application.persistentDataPath + it); Directory.CreateDirectory(Application.persistentDataPath + it); } else { SampleDebuger.LogError("既不是文件夹也不是文件 路径为" + Application.persistentDataPath + it); } ++curIndex; } SampleDebuger.Log(" writeversion"); // 同步版本 VersionManager.Instance().proCurVersion = m_szCurrentVersion; _assetUpdater.CheckVersionWithServer(); }
public void OnServerInfo(string szData) { SampleDebuger.Log(szData); ServerListInfo oServerList = JsonUtility.FromJson <ServerListInfo>(szData); if (oServerList.server_infos.Count == 0) { SampleDebuger.LogError("can't find server list!!!!"); return; } AssetBundleLoader.Instance().LoadAsset( GameObjectConstant.GetABUIPath(GameObjectConstant.g_szLoginServerList), GameObjectConstant.GetABName(GameObjectConstant.g_szLoginServerList), delegate(UnityEngine.Object ob) { LoginServerList pList = LoginServerList.CreateInstance(ob, MainCanvas.Instance().transform); pList.SetServerListInfo(oServerList); } ); }
// Where we get all the dependencies and load them all. static protected void LoadDependencies(string assetBundleName) { if (m_AssetBundleManifest == null) { SampleDebuger.LogError("Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()"); return; } // Get dependecies from the AssetBundleManifest object.. string[] dependencies = m_AssetBundleManifest.GetAllDependencies(assetBundleName); if (dependencies.Length == 0) return; for (int i = 0; i < dependencies.Length; i++) dependencies[i] = RemapVariantName(dependencies[i]); // Record and load all dependencies.(因为现在有的assetbundle资源是可选为不释放的) if (!m_Dependencies.ContainsKey(assetBundleName)) m_Dependencies.Add(assetBundleName, dependencies); for (int i = 0; i < dependencies.Length; i++) LoadAssetBundleInternal(dependencies[i], false); }
public void IntoInviteTeam(object pParam) { GameProto.LoginNotifyPlayerInviteTeam oInvite = pParam as GameProto.LoginNotifyPlayerInviteTeam; if (oInvite == null) { SampleDebuger.LogError("IntoInviteTeam parse error!!!!"); return; } GameProto.PlayerRequestLoginEnterTeam oRequest = new GameProto.PlayerRequestLoginEnterTeam(); oRequest.DwTeamServerId = oInvite.DwTeamServerId; oRequest.QwTeamId = oInvite.QwTeamId; byte[] pData = new byte[1024]; FxNet.NetStream pStream = new FxNet.NetStream(FxNet.NetStream.ENetStreamType.ENetStreamType_Write, pData, 1024); pStream.WriteString("GameProto.PlayerRequestLoginEnterTeam"); byte[] pProto = new byte[oRequest.CalculateSize()]; Google.Protobuf.CodedOutputStream oStream = new Google.Protobuf.CodedOutputStream(pProto); oRequest.WriteTo(oStream); pStream.WriteData(pProto, (uint)pProto.Length); m_pSession.Send(pData, 1024 - pStream.GetLeftLen()); }
// Load level from the given assetBundle. static public AssetBundleLoadBaseOperation LoadLevelAsync(string assetBundleName, string levelName, bool isAdditive) { AssetBundleLoadBaseOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... SampleDebuger.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName); return null; } AssetBundleLoadLevelSimulationOperation temp = new AssetBundleLoadLevelSimulationOperation(); if (isAdditive) temp.m_sceneRequest = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]); else temp.m_sceneRequest = EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]); operation = temp; } else #endif { LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive); m_InProgressOperations.Add(operation); } return operation; }
public bool OnSessionDestroy() { SampleDebuger.LogError("session obj has destroy!!!!"); Destroy(this); return(false); }
public void OnClose() { SampleDebuger.LogError("session close"); }
public void OnError(uint dwErrorNo) { SampleDebuger.LogError("session error " + dwErrorNo.ToString()); }
public override void OnError(uint dwErrorNo) { SampleDebuger.LogError(m_pSocket.GetError()); m_oGameObject.OnError(dwErrorNo); }