private void DestroyGameObject() { actionTimeout = null; OnDestroy.Invoke(); InteractingAgents.ForEach(agent => agent.GetComponent <HitAnimation>().PlayHitAnimation(gameObject)); EndInteraction(InteractingAgents); }
public void InitializeInteraction(Agent agent) { interactingAgent = agent; PlayerAgent.Instance.ReachTargetChecker.OnDestinationReached = null; actionTimeout = new ActionTimeout(Delay, () => OnTimerEnd.Invoke()); TimerIconAnimation.StartAnim(Delay); }
public override void Reset() { IsInteracting = false; IsComplete = false; actionTimeout = null; OnReset.Invoke(); InteractingAgents.Clear(); }
protected override void AiAgentApproachTarget(Agent agent) { (agent as AIAgent).ReachTargetChecker.OnDestinationReached -= AiAgentApproachTarget; if (!IsInteracting) { return; } actionTimeout = new ActionTimeout(DestructionTime, DestroyGameObject); }
public void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } // 加载日志数据发布服务所需配置文件信息 this.mqttParam = new MQTTParam(); if (!LoadConfig(out errMsg)) { return; } // 检查端口是否空闲 if (!IPTool.IsValidPort(this.mqttParam.port)) { errMsg = "日志服务器的发布端口被占用,请更换端口号"; return; } // 开启MQTT服务当做发布器 mqttServer = new MQTTServer(mqttParam); mqttServer.Start(out errMsg); if (!mqttServer.IsRuning || !string.IsNullOrWhiteSpace(errMsg)) { Stop(); return; } // 开启消息队列的消费器 queue = new BlockingCollection <TraceItem>(); task = new Task(() => { foreach (TraceItem item in queue.GetConsumingEnumerable()) { try { ActionTimeout <TraceItem> timeout = new ActionTimeout <TraceItem>(); timeout.Do = Excute; bool isTimeout = timeout.DoWithTimeout(item, TimeSpan.FromSeconds(5)); //只等待5秒 if (isTimeout) // 超时 { GC.Collect(); } } catch { } } }, TaskCreationOptions.LongRunning); task.Start(); IsRuning = true; }
void Update() { if (actionTimeout != null) { actionTimeout.Tick(Time.deltaTime); if (!interactingAgent.NavMeshAgent.IsDestinationReached()) { actionTimeout = null; TimerIconAnimation.StopAnim(); } } }
void Update() { if (actionTimeout != null && IsInteracting) { actionTimeout.Tick(Time.deltaTime); if (IsComplete && InteractingPlayer != null && !InteractingPlayer.NavMeshAgent.IsDestinationReached()) { actionTimeout = null; TimerIconAnimation.StopAnim(); } } }
public void Start(out string errMsg) { errMsg = ""; if (IsRuning) { return; } // 加载日志数据发布服务所需配置文件信息 this.mqttParam = new MQTTParam(); if (!LoadConfig(this.configPath, out errMsg)) { return; } // 开启MQTT服务当做发布器 mqttServer = new MQTTServer(mqttParam); mqttServer.Start(out errMsg); if (!mqttServer.IsRuning || !string.IsNullOrWhiteSpace(errMsg)) { Stop(); return; } // 开启消息队列的消费器 queue = new BlockingCollection <PublishData>(); task = new Task(() => { foreach (PublishData item in queue.GetConsumingEnumerable()) { try { ActionTimeout <PublishData> timeout = new ActionTimeout <PublishData>(); timeout.Do = Excute; bool isTimeout = timeout.DoWithTimeout(item, new TimeSpan(0, 0, 0, 5)); //只等待5秒 if (isTimeout) // 超时 { GC.Collect(); } } catch { } } }, TaskCreationOptions.LongRunning); task.Start(); IsRuning = true; }
// 命令消费-设定超时功能 private void Excute(RequestCommand command) { // 设定超时功能 ActionTimeout <RequestCommand> timeout = new ActionTimeout <RequestCommand>(); timeout.Do = ExcuteHandle; bool bo = timeout.DoWithTimeout(command, new TimeSpan(0, 0, 0, command.timeoutSeconds + 3));//设定基础多等待3秒,防止调用着也做了超时功能 if (bo) { CommandManager.MakeTimeout("会话ID:" + command.sensorID + "执行命令超时", ref command); CommandManager.CompleteCommand(command); TraceManagerForCommand.AppendErrMsg(command.message); GC.Collect(); } }
public override void PlayerApproachTarget(Agent agent) { InteractingPlayer = agent as PlayerAgent; InteractingPlayer.ReachTargetChecker.OnDestinationReached = null; actionTimeout = null; if (IsComplete) { IsInteracting = true; actionTimeout = new ActionTimeout(3, Reset); TimerIconAnimation.StartAnim(3); } else { if (!CanInteract()) { return; } OnPlayerApproach.Invoke(); EndInteraction(InteractingAgents); } }
// 任务执行口--并附带超时功能 public void Excute() { ActionTimeout timeoutObj = new ActionTimeout(); try { switch (this.type) { case StationCommandType.Collect: { if (opcCommandType == OPCCommandType.Cancle) //已经在调度被标记放弃了,干要紧的任务 { return; } timeoutObj.Do = ExcuteCollect; bool bo = timeoutObj.DoWithTimeout(new TimeSpan(0, 0, 0, Config.scadaConfig.commandTimeoutSeconds)); if (bo) { TraceManagerForOPC.AppendWarning("站点定时采集任务执行超时"); GC.Collect(); } } break; case StationCommandType.Write: { timeoutObj.Do = ExcuteWrite; bool bo = timeoutObj.DoWithTimeout(new TimeSpan(0, 0, 0, Config.scadaConfig.commandTimeoutSeconds)); if (bo) { CommandManager.MakeTimeout("sensorID:" + requestCommand.sensorID + "执行写值命令超时", ref requestCommand); CommandManager.CompleteCommand(requestCommand); TraceManagerForCommand.AppendWarning(requestCommand.message); GC.Collect(); } } break; case StationCommandType.Reload: { timeoutObj.Do = ExcuteReload; bool bo = timeoutObj.DoWithTimeout(new TimeSpan(0, 0, 0, Config.scadaConfig.commandTimeoutSeconds)); if (bo) { CommandManager.MakeTimeout("执行重载站点数据命令超时", ref requestCommand); CommandManager.CompleteCommand(requestCommand); TraceManagerForCommand.AppendWarning(requestCommand.message); GC.Collect(); } } break; default: TraceManagerForOPC.AppendWarning("未知的站点OPC命令类型,无法执行"); return; } } catch (Exception e) { TraceManagerForOPC.AppendErrMsg("执行站点OPC任务失败,未知的任务类型:" + e.Message + "堆栈:" + e.StackTrace); } }