//接收数据 protected void AsynRecive() { try { //开始接收数据 //该步骤只读取长度 clear_receive_buffers(CommandCollection.SOCK_CONTEXT_LENGTH); _socket.BeginReceive(receive_buffers, 0, receive_buffers.Length, SocketFlags.None, readMessageLength => { _socket.EndReceive(readMessageLength); msg_length = readUShort(); clear_receive_buffers(msg_length); _socket.BeginReceive(receive_buffers, 0, receive_buffers.Length, SocketFlags.None, receiveMessage => { _socket.EndReceive(receiveMessage); ///---------读取数据 SASocketDataDAO sdd = new SASocketDataDAO(readUShort(), readBytes(msg_length - CommandCollection.SOCK_TYPE_LENGTH)); //CommandCollection.getDataModel((ProtoTypeEnum)sdd.type, sdd.bytes); SAUtils.Log("收到消息号 : " + (ProtoTypeEnum)sdd.type); dispatchEvent(Command + (ProtoTypeEnum)sdd.type, sdd); AsynRecive(); }, null); }, null); } catch (Exception ex) { SAUtils.LogError("异常信息:" + ex.Message); AsynRecive(); } }
public SocketDataWorker(string name, string command) : base(name, command) { random = new System.Random(); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SAUtils.Log("Socket Init"); }
IEnumerator OnUpdateResource() { string random = DateTime.Now.ToString("yyyymmddhhmmss"); string versionFile = SAGameVersion.asset_path + SAAppConfig.LanguagePlatform + "/" + MD5_NAME + "?rd=" + random; WWW www = new WWW(versionFile); yield return(www); if (www.error != null) { //抱错喽~~~ print("抱错喽~~~ : " + versionFile); yield break; } SAUtils.Log("文件加载完毕"); convertXML = SALang.stringConvertXML(www.text);//等待写入 newVersion = getXmlToDictionary(convertXML.DocumentElement.ChildNodes); progressData.info = "更新资源..."; resListEN = newVersion.GetEnumerator(); totalNum = newVersion.Count; currentNum = 0; dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile); yield return(StartCoroutine(download())); }
override protected void mainStart() { SAUtils.Log("start heart"); base.mainStart(); SAAppConfig.Thread = true; sock = (SocketDataWorker)IOCManager.Instance.getIOCDataWorker("Datas.SocketDataWorker"); new Thread(heart).Start(); }
public void hit() { if ((life -= 30) <= 0) { gameObject.GetComponent <Animator> ().Play("die"); gameObject.GetComponent <Collider> ().enabled = false; graph.dispatchEvent(SAACollection.AddScore, fd); SAUtils.Log("加分"); } }
override protected void onRegister() { base.onRegister(); //addEventDispatcherWithHandle(SAACollection.NewTarget, newTargetHandler); addEventDispatcherWithHandle(SAACollection.FishDie, fishDieHandler); addEventDispatcherWithHandle(CommandCollection.Sock + ProtoTypeEnum.SFishChapter, fishChapterHandler); //获取房间信息 CEnterRoom.Builder enterRoom = CEnterRoom.CreateBuilder(); sock.sendMessage(ProtoTypeEnum.CEnterRoom, enterRoom.Build().ToByteArray()); SAUtils.Log("onRegister"); }
protected void connectComplete(IAsyncResult ar) { try { _socket.EndConnect(ar); update(SAACollection.COMPLETE); SAUtils.Log("Success ... "); AsynRecive(); } catch (SocketException e) { update(SAACollection.ERROR); SAUtils.Log("ErrorCode ... " + e.ErrorCode); } }
protected override void onSrart(System.Object args) { base.onSrart(args); SAUtils.Log("load resource..."); if (true || !PlayerPrefs.HasKey("resources_version") || PlayerPrefs.GetInt("resources_version") != SAGameVersion.Instance.ioc_version) {//更新资源 refreshLocalVersionInfo(); } else { SAUtils.Log("load version..."); dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile + SAACollection.COMPLETE);//更新完成 } //initSocket();//临时直接初始化socket }
private IEnumerator download() { if (resListEN.MoveNext()) { string fileKey = resListEN.Current.Key; localFilePath = Path.Combine(SAAppConfig.RemotePath, fileKey); bool isExist = File.Exists(localFilePath);//判断本地文件 progressData.info = "正在更新资源 : " + fileKey; dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile); if (isExist) { isExist = version.ContainsKey(fileKey) && version[fileKey].Equals(resListEN.Current.Value); if (!isExist) { File.Delete(localFilePath); } } if (!isExist)//需要下载 { progressData.name = resListEN.Current.Key; stopWatch.Start(); //loadFileWithName(fileKey); string remoteFilePath = SAGameVersion.asset_path + fileKey; WWW www = new WWW(remoteFilePath); yield return(www); if (www.error != null) { //抱错喽~~~ SAUtils.Log("抱错喽~~~ : " + remoteFilePath); yield break; } SALang.writeLocalByteWithName(www.bytes, resListEN.Current.Key); } ++currentNum; yield return(StartCoroutine(download())); } else { progressData.info = "更新完毕"; dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile); downloadComplete(); } }
/// <summary> /// 更新本地版本信息缓存 /// </summary> protected void refreshLocalVersionInfo() { SAUtils.Log("refresh version..."); //获取当前(旧的)版本 version = getXmlToDictionary(SALang.getLocalXMLWithName(MD5_NAME).DocumentElement.ChildNodes); //加载远程(最新)版本信息 progressData.info = "加载版本文件信息..."; addEventDispatcherWithHandle(SAACollection.REFRESH + ActionCollection.LocalFile + SAACollection.COMPLETE, updateLocalFileComplete);//资源加载完成 //加载 if (SAAppConfig.UIRelease) { addEventDispatcherWithHandle(SAACollection.REFRESH + ActionCollection.LocalFile, updateLocalFile);//资源加载 StartCoroutine(OnUpdateResource()); } else { dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile + SAACollection.COMPLETE);//更新完成 } }
/// <summary> /// 资源加载完成 /// </summary> /// <param name="e"></param> private void updateLocalFileComplete(SAFactoryEvent e) { removeEventDispatcher(SAACollection.REFRESH + ActionCollection.LocalFile + SAACollection.COMPLETE);//资源加载完成 //初始化 AssetBundleRemoteLua string localFilePath = Path.Combine(SAAppConfig.LuaRelease?SAAppConfig.RemoteLuaDir : SAAppConfig.DevLuaDir, originName + ".lua"); bool isExist = File.Exists(localFilePath);//判断本地文件 if (isExist) { luaEnv = new LuaEnv(); luaEnv.AddLoader(LuaFile); luaEnv.DoString("require '" + localFilePath + "'"); //################以下按照流程顺序补齐lua操作 base.callLuaFun(SAACollection.luaNew, this); //初始化 base.callLuaFun(SAACollection.luaRegister); //注册 base.callLuaFun(SAACollection.luaStart); //启动 //内部自动处理加载关闭以及接下来的执行任务 base.callLuaFun(SAACollection.luaRegisterComplete); //启动完毕 } SAUtils.Log("AssetBundleFactory complete"); int w = Screen.width; int h = Screen.height; //test = Instantiate((GameObject)SACache.getObjectWithName("model/cheqiyu/cheqiyu")); //test.GetComponent<Animator>().Play("swim"); //ProtoTypeEnum.CLogin.ToString() //GameObject test = Instantiate(SACache.getResWithName<GameObject>("Model.FightPanelUI.FightPanelMap")); //GameObject test = Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>("Assets/_Resources/Model/FightPanelUI/FightPanelMap.prefab")); //test.transform.FindChild("Ground").transform.localPosition = new Vector3(0, 0.7f, 0); //test.transform.FindChild("FourDimensional").transform.localPosition = new Vector3(0, 0.7f, 0); //SALaunch.UIRootCamera.gameObject.SetActive(false); }
override protected void onDispose() { base.onDispose(); SAUtils.Log("onDispose"); }
override protected void onRegisterComplete() { base.onRegisterComplete(); SAUtils.Log("onRegisterComplete"); }
override protected void onSrart(System.Object args) { base.onSrart(args); SAUtils.Log("onSrart"); }
override protected void mainStart() { base.mainStart(); SAUtils.Log("mainStart"); }
override protected void onRemove() { base.onRemove(); SAUtils.Log("onRemove"); }