public ETTask <IResponse> Call(IRequest request) { int rpcId = ++RpcId; var tcs = new ETTaskCompletionSource <IResponse>(); this.requestCallback[rpcId] = (response) => { try { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { Game.EventSystem.Run(CowCowEventIdType.ServerMaintenance); throw new RpcException(response.Error, response.Message); } tcs.SetResult(response); } catch (Exception e) { tcs.SetException(new Exception($"Rpc Error: {request.GetType().FullName}", e)); } }; request.RpcId = rpcId; this.Send(request); return(tcs.Task); }
public ETTask <IResponse> Call(IRequest request) { int rpcId = ++RpcId; var tcs = new ETTaskCompletionSource <IResponse>(); EventMsgMgr.SendEvent(CommEventID.CallRequest); this.requestCallback[rpcId] = (response) => { try { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { throw new RpcException(response.Error, response.Message); } EventMsgMgr.SendEvent(CommEventID.CallResponse); tcs.SetResult(response); } catch (Exception e) { tcs.SetException(new Exception($"Rpc Error: {request.GetType().FullName}", e)); } }; request.RpcId = rpcId; this.Send(0x00, request); return(tcs.Task); }
public static ETTask <IActorResponse> Call(this ActorMessageSenderComponent self, long actorId, IActorRequest message) { if (actorId == 0) { throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}"); } string address = StartConfigComponent.Instance.GetProcessInnerAddress(IdGenerater.GetProcessId(actorId)); Session session = NetInnerComponent.Instance.Get(address); message.ActorId = actorId & IdGenerater.HeadMask | IdGenerater.Head; message.RpcId = ++self.RpcId; var tcs = new ETTaskCompletionSource <IActorResponse>(); self.requestCallback.Add(message.RpcId, new ActorMessageSender((response) => { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}")); return; } tcs.SetResult(response); })); session.Send(message); return(tcs.Task); }
public ETTask PostData(string url, string data) { this.tcs = new ETTaskCompletionSource(); this.Request = UnityWebRequest.Post(url, data); this.Request.SendWebRequest(); return(this.tcs.Task); }
public static ETTask <IActorResponse> Call(this ActorMessageSenderComponent self, long actorId, IActorRequest message, bool exception = true) { if (actorId == 0) { throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}"); } var tcs = new ETTaskCompletionSource <IActorResponse>(); int process = IdGenerater.GetProcess(actorId); string address = StartProcessConfigCategory.Instance.Get(process).InnerAddress; Session session = NetInnerComponent.Instance.Get(address); InstanceIdStruct instanceIdStruct = new InstanceIdStruct(actorId); instanceIdStruct.Process = IdGenerater.Process; message.ActorId = instanceIdStruct.ToLong(); message.RpcId = ++self.RpcId; self.requestCallback.Add(message.RpcId, new ActorMessageSender((response) => { if (exception && ErrorCode.IsRpcNeedThrowException(response.Error)) { tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}")); return; } tcs.SetResult(response); })); session.Send(message); return(tcs.Task); }
//assetbundle_get public ETTask GetAssetBundle(string url) { this.tcs = new ETTaskCompletionSource(); this.Request = UnityWebRequestAssetBundle.GetAssetBundle(url); this.Request.SendWebRequest(); return(this.tcs.Task); }
public ETTask <IResponse> Call(IRequest request, CancellationToken cancellationToken) { int rpcId = ++RpcId; var tcs = new ETTaskCompletionSource <IResponse>(); this.requestCallback[rpcId] = (response) => { try { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { throw new RpcException(response.Error, response.Message); } tcs.SetResult(response); } catch (Exception e) { tcs.SetException(new Exception($"Rpc Error: {request.GetType().FullName}", e)); } }; cancellationToken.Register(() => { this.requestCallback.Remove(rpcId); }); request.RpcId = rpcId; this.Send(request); return(tcs.Task); }
public ETTask <IResponse> Query(long ActorId, int opcode, float timeOut) { var tcs = new ETTaskCompletionSource <IResponse>(); if (timeOut != 0) { tcs.SetTimeOut(timeOut, null); } QueryData data = new QueryData(); data.ActorId = ActorId; data.opcode = opcode; data.callback = (response) => { try { tcs.SetResult(response); } catch (Exception e) { tcs.SetException(new Exception($"Message Error: {data.opcode}", e)); } }; this.requestCallback[data.opcode] = data; return(tcs.Task); }
public ETTask <IResponse> Call(IRequest request) { int rpcId = ++RpcId; var tcs = new ETTaskCompletionSource <IResponse>(); //向字典压入响应请求的处理方法 //方法要当做参数保存 肯定是使用委托 //而以后要调用方法 实际就是执行委托 this.requestCallback[rpcId] = (response) => { try { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { throw new RpcException(response.Error, response.Message); } //返回await等待的地方 继续执行下半部分的代码 //或者说 执行缓存了await下半部分的代码,并传递返回的网络数据反序列化后得到的proto对象 tcs.SetResult(response); } catch (Exception e) { tcs.SetException(new Exception($"Rpc Error: {request.GetType().FullName}", e)); } }; request.RpcId = rpcId; this.Send(request); //返回task return(tcs.Task); }
public async ETVoid Execute(string skillId) { try { if (usingSkill) { return; } if (!skillList.ContainsKey(skillId)) { return; } if (!SkillHelper.CheckIfSkillCanUse(skillId, GetParent <Unit>())) { return; } ActiveSkillData activeSkillData = Game.Scene.GetComponent <SkillConfigComponent>().GetActiveSkill(skillId); SkillHelper.ExecuteSkillParams excuteSkillParams = new SkillHelper.ExecuteSkillParams(); excuteSkillParams.skillId = skillId; excuteSkillParams.source = GetParent <Unit>(); excuteSkillParams.skillLevel = 1; usingSkill = true; bool canUse = await SkillHelper.CheckInput(excuteSkillParams); if (GetParent <Unit>() == UnitComponent.Instance.MyUnit) { //联网模式玩家主动使用技能需要等待服务器确认消息,以决定技能是否真的可以使用 tcs = new ETTaskCompletionSource <bool>(); canUse = await tcs.Task; tcs = null; usingSkill = false; } if (!canUse) { return; } usingSkill = false; currUsingSkillId = skillId; // 联网模式非玩家单位使用技能直接跳过检测,因为是收到使用技能的确定消息了才开始执行技能. //TODO: 暂时先直接取消之前的行动 cancelToken?.Cancel(); Game.EventSystem.Run(EventIdType.CancelPreAction, GetParent <Unit>()); CharacterStateComponent characterStateComponent = GetParent <Unit>().GetComponent <CharacterStateComponent>(); characterStateComponent.Set(SpecialStateType.NotInControl, true); cancelToken = new CancellationTokenSource(); excuteSkillParams.cancelToken = cancelToken; await SkillHelper.ExecuteActiveSkill(excuteSkillParams); cancelToken = null; characterStateComponent.Set(SpecialStateType.NotInControl, false); currUsingSkillId = string.Empty; } catch (Exception e) { Log.Error(e.ToString()); } }
//File_get public ETTask GetFile(string url, string filePath) { this.tcs = new ETTaskCompletionSource(); this.Request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET); this.Request.downloadHandler = new DownloadHandlerFile(filePath); this.Request.SendWebRequest(); return(this.tcs.Task); }
public static ETTask <TargetArrow> Create(Vector3 InitPos, PlayerCube playerCube, UI AttackUI) { ETTaskCompletionSource <TargetArrow> tcs = new ETTaskCompletionSource <TargetArrow>(); CreateTargetArrow(InitPos, playerCube, AttackUI.GetComponent <VariableJoystickComponent>(), tcs).Coroutine(); return(tcs.Task); }
public ETTask ChangeSceneAsync(string sceneName) { this.tcs = new ETTaskCompletionSource(); // 加载map this.loadMapOperation = SceneManager.LoadSceneAsync(sceneName); return(this.tcs.Task); }
public static ETTask <OtherCube> Create(int account, Vector3 InitPosition) { ETTaskCompletionSource <OtherCube> tcs = new ETTaskCompletionSource <OtherCube>(); CreateOtherCube(account, InitPosition, tcs).Coroutine(); return(tcs.Task); }
public static ETTask <UI> Create() { ETTaskCompletionSource <UI> tcs = new ETTaskCompletionSource <UI>(); CreateJoystickUI(tcs).Coroutine(); return(tcs.Task); }
public static ETTask <PlayerCube> Create(Vector3 InitPos) { ETTaskCompletionSource <PlayerCube> tcs = new ETTaskCompletionSource <PlayerCube>(); CreatePlayerCube(InitPos, tcs).Coroutine(); return(tcs.Task); }
public static ETTask <GoldenToShopBtn> CreateInstanceAsync(Entity domain) { ETTaskCompletionSource <GoldenToShopBtn> tcs = new ETTaskCompletionSource <GoldenToShopBtn>(); CreateGObjectAsync((go) => { tcs.SetResult(ComponentFactory.Create <GoldenToShopBtn, GObject>(go)); }); return(tcs.Task); }
public static ETTask <SkillSmallProBar> CreateInstanceAsync(Entity domain) { ETTaskCompletionSource <SkillSmallProBar> tcs = new ETTaskCompletionSource <SkillSmallProBar>(); CreateGObjectAsync((go) => { tcs.SetResult(ComponentFactory.Create <SkillSmallProBar, GObject>(go)); }); return(tcs.Task); }
public static ETTask <one_confirm> CreateInstanceAsync(Entity domain) { ETTaskCompletionSource <one_confirm> tcs = new ETTaskCompletionSource <one_confirm>(); CreateGObjectAsync((go) => { tcs.SetResult(ComponentFactory.Create <one_confirm, GObject>(go)); }); return(tcs.Task); }
public static ETTask <Btn_GMController_Disable> CreateInstanceAsync(Entity domain) { ETTaskCompletionSource <Btn_GMController_Disable> tcs = new ETTaskCompletionSource <Btn_GMController_Disable>(); CreateGObjectAsync((go) => { tcs.SetResult(ComponentFactory.Create <Btn_GMController_Disable, GObject>(go)); }); return(tcs.Task); }
public static ETTask <Btn_VersionInfo> CreateInstanceAsync(Entity domain) { ETTaskCompletionSource <Btn_VersionInfo> tcs = new ETTaskCompletionSource <Btn_VersionInfo>(); CreateGObjectAsync((go) => { tcs.SetResult(ComponentFactory.Create <Btn_VersionInfo, GObject>(go)); }); return(tcs.Task); }
public ETTask <KeyValuePair <RedisChannel, RedisValue> > Get(RedisEventSolverComponent self) { if (self.receivedQueue.TryDequeue(out var kp)) { return(ETTask.FromResult(kp)); } ETTaskCompletionSource <KeyValuePair <RedisChannel, RedisValue> > t = new ETTaskCompletionSource <KeyValuePair <RedisChannel, RedisValue> >(); self.tcs = t; return(t.Task); }
public static ETTask <IActorLocationResponse> Call(this ActorLocationSender self, IActorLocationRequest request) { if (request == null) { throw new Exception($"actor location call message is null"); } ETTaskCompletionSource <IActorLocationResponse> tcs = new ETTaskCompletionSource <IActorLocationResponse>(); ActorTask task = new ActorTask(request, tcs); self.Add(task); return(task.Tcs.Task); }
private static ETTask <bool> WaitLock(this LockComponent self) { if (self.status == LockStatus.Locked) { return(ETTask.FromResult(true)); } ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>(); self.queue.Enqueue(tcs); return(tcs.Task); }
//text_get public ETTask Get(string url) { this.tcs = new ETTaskCompletionSource(); this.Request = UnityWebRequest.Get(url); this.Request.SendWebRequest(); if (this.Request == null) { Log.Info("null le"); } return(this.tcs.Task); }
//form post public ETTask Post(string url, Dictionary <string, string> headers = null, WWWForm formData = null) { this.tcs = new ETTaskCompletionSource(); this.Request = UnityWebRequest.Post(url, formData); if (headers != null) { foreach (var key in headers.Keys) { this.Request.SetRequestHeader(key, headers[key]); } } this.Request.SendWebRequest(); return(this.tcs.Task); }
//urlencode post public ETTask PostUrlEncode(string url, string content, Dictionary <string, string> headers = null) { this.tcs = new ETTaskCompletionSource(); this.Request = CreatUnityWebRequest(url, content, "application/x-www-form-urlencoded"); if (headers != null) { foreach (var key in headers.Keys) { this.Request.SetRequestHeader(key, headers[key]); } } this.Request.SendWebRequest(); return(this.tcs.Task); }
public static ETTask Lock(this MasterComponent self, IPEndPoint address) { if (self.lockedAddress == null) { self.lockedAddress = address; return(ETTask.FromResult(true)); } ETTaskCompletionSource tcs = new ETTaskCompletionSource(); LockInfo lockInfo = new LockInfo(address, tcs); self.queue.Enqueue(lockInfo); return(tcs.Task); }
private static async ETVoid CreatePlayerCube(Vector3 InitPos, ETTaskCompletionSource <PlayerCube> tcs) { try { //创建一个cube角色的3D物体 GameObject resObj = await ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>().LoadAssetAsync <GameObject>(Assets.LoadAssetAsync("Assets/Bundles/Prefab/PlayerCube.prefab", typeof(GameObject))); ReferenceCollector rc = resObj.GetComponent <ReferenceCollector>(); GameObject playerCubeObj = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("PlayerCube")); playerCubeObj.transform.position = InitPos; //创建cube角色实体脚本 PlayerCube playerCube = ComponentFactory.Create <PlayerCube, GameObject>(playerCubeObj, false); //创建控制UI UI ui = await UIJoystickFactory.Create(); Game.Scene.GetComponent <UIComponent>().Add(ui); //添加控制组件 PlayerCubeControllerComponent playerCubeControllerComponent = playerCube.AddComponent <PlayerCubeControllerComponent, UI>(ui); //创建准星控制UI UI AttackUI = await UIAttackDirstickFactory.Create(); Game.Scene.GetComponent <UIComponent>().Add(AttackUI); //创建准星3D物品 TargetArrow targetArrow = await TargetArrowFactory.Create(Vector3.zero, playerCube, AttackUI); //管理准星与cube playerCubeControllerComponent.targetArrow = targetArrow; //添加攻击脚本 playerCube.AddComponent <PlayerCubeAttackComponent>(); //添加生命值信息UI playerCube.AddComponent <PlayerCubeHealthComponent>(); //添加攻击伤害同步脚本 playerCube.AddComponent <HurtSyncComponent>(); tcs.SetResult(playerCube); } catch (Exception e) { Log.Error(e); tcs.SetResult(null); } }
//xml post public ETTask PostXml(string url, string content, Dictionary <string, string> headers = null) { this.tcs = new ETTaskCompletionSource(); this.Request = CreatUnityWebRequest(url, content, "text/xml"); if (headers != null) { foreach (var key in headers.Keys) { this.Request.SetRequestHeader(key, headers[key]); } } this.Request.SendWebRequest(); return(this.tcs.Task); }