/// <summary> /// Overrides the child node's result /// </summary> /// <param name="result">The result to override the child node's result</param> public BehaviourResultOverrider(bool result) : base("ResultOverrider", NodeType.DECORATOR) { m_result = result; OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); }
/// <summary> /// Runs the child node with the given probability chance between 0 and 1 /// </summary> /// <param name="probability">Between 0 and 1</param> public BehaviourRandom(float probability) : base("Random", NodeType.DECORATOR) { m_probability = probability; OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); }
/// <summary> /// Inverts the child node result. /// </summary> /// <param name="child">The child node</param> public BehaviourInverter(BehaviourNode child) : base("Inverter", NodeType.DECORATOR) { AddChild(child); OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); }
private void Init() { OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); _actionResult = ActionResult.PROGRESS; }
public BehaviourSequenceSelectBase(string name, bool isRandom) : base(name, NodeType.COMPOSITE) { IsRandom = isRandom; OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); }
/// <summary> /// The root node of a tree /// </summary> /// <param name="name"></param> public BehaviourRootNode(string name = "Root") : base(name, NodeType.DECORATOR) { OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); }
public void Init(float seconds, float randomVariance) { this.WaitSeconds = seconds; this.randomVariance = randomVariance; OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); }
public BehaviourRepeatUntil(Func <bool> isConditionMetFunc) : base(NODE_NAME, NodeType.DECORATOR) { m_isConditionMetFunc = isConditionMetFunc; OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); }
/// <summary> /// Repeated runs it's child node /// </summary> /// <param name="totalLoops">The amount of times the child node is looped. If -1 it will loop indefinately unless stopped manually.</param> public BehaviourRepeater(int totalLoops = -1, bool stopOnChildFail = true) : base(NODE_NAME, NodeType.DECORATOR) { TotalLoops = totalLoops; StopOnChildFail = stopOnChildFail; OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); }
//private bool m_initParent = false; public BehaviourObserver(string name, BehaviourNode decoratee, AbortRule abortRule) : base(name, NodeType.DECORATOR) { OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); m_abortRule = abortRule; m_isObserving = false; AddChild(decoratee); }
/// <summary> /// Run child nodes in parallel /// </summary> /// <param name="successStopCondition"> /// How many children should return success before parallel stops with success /// </param> /// <param name="failureStopCondition"> /// How many children should return failure before parallel stops with failure /// </param> public BehaviourParallel(StopCondition successStopCondition, StopCondition failureStopCondition) : base("Parallel", NodeType.COMPOSITE) { m_successStopCondition = successStopCondition; m_failureStopCondition = failureStopCondition; OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); }
/// <summary> /// Remove all BehaviourNode related Event listeners /// </summary> public void RemoveAllListeners() { OnStarted.RemoveAllListeners(); OnStartedSilent.RemoveAllListeners(); OnStopping.RemoveAllListeners(); OnStoppingSilent.RemoveAllListeners(); OnStopped.RemoveAllListeners(); OnStoppedSilent.RemoveAllListeners(); }
private void Init(System.Action serviceAction) { OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); m_serviceAction = serviceAction; #if UNITY_EDITOR DebugTools.GUIlabel = "every tick"; #endif }
public BehaviourBinarySelector(Func <bool> isConditionMetFunc, BehaviourNode trueNode, BehaviourNode falseNode) : base("Binary Selector", NodeType.COMPOSITE) { AddChild(trueNode); AddChild(falseNode); TrueNode.OnStopped.AddListener(TrueActionOnStopped_Listener); FalseNode.OnStopped.AddListener(FalseActionOnStopped_Listener); _isConditionMetFunc = isConditionMetFunc; OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); }
public void StopExecutors() { _log.Info("Stopping Executors"); if (OnStopping != null) { foreach (Action handler in OnStopping.GetInvocationList()) { handler(); } } _log.Info("Stopped"); }
/// <summary> /// Delay execution of the child node until the condition is true /// </summary> /// <param name="isConditionMetFunc">The function used to check the condition</param> /// <param name="checkInterval">The interval at which the condition is checked</param> /// <param name="randomVariance">The interval variance</param> public BehaviourWaitForCondition(Func <bool> isConditionMetFunc, float checkInterval, float randomVariance) : base("WaitForCondition", NodeType.DECORATOR) { OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppedSilent.AddListener(OnStoppedSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); m_isConditionMetFunc = isConditionMetFunc; m_checkInterval = checkInterval; m_checkVariance = randomVariance; // this.Label = "" + (checkInterval - randomVariance) + "..." + (checkInterval + randomVariance) + "s"; }
/// <summary> /// Initiates the stopping process /// </summary> /// <returns>If it successfully initiated the stopping process</returns> public bool RequestStopNode(bool silent = false) { if (this.State == NodeState.ACTIVE) { this.State = NodeState.STOPPING; if (!silent) { OnStopping.Invoke(); } else { OnStoppingSilent.Invoke(); } return(true); } return(false); }
private void Init(float limit, float?randomVariation = null, bool waitOnFailure = false) { OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); m_limit = limit; if (randomVariation != null) { m_randomVariation = randomVariation.Value; } else { m_randomVariation = limit * 0.05f; } m_waitOnFailure = waitOnFailure; }
private void Init(float limit, float?randomVariation, bool waitForChildButFailOnLimitReached) { OnStarted.AddListener(OnStarted_Listener); OnStartedSilent.AddListener(OnStartedSilent_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); m_limit = limit; if (randomVariation != null) { m_randomVariation = randomVariation.Value; } else { m_randomVariation = m_limit * 0.05f; } m_waitForChildButFailOnLimitReached = waitForChildButFailOnLimitReached; }
private void Init(float cooldownTime, float?randomVariation = null, bool startAfterChild = false, bool resetOnFailiure = false, bool failOnCooldown = false) { OnStarted.AddListener(OnStarted_Listener); OnStopping.AddListener(OnStopping_Listener); OnStoppingSilent.AddListener(OnStoppingSilent_Listener); OnChildNodeStopped.AddListener(OnChildNodeStopped_Listener); OnChildNodeStoppedSilent.AddListener(OnChildNodeStoppedSilent_Listener); m_startAfterChild = false; m_cooldownTime = cooldownTime; m_resetOnFailiure = false; if (randomVariation != null) { m_randomVariation = randomVariation.Value; } else { m_randomVariation = cooldownTime * 0.1f; } }
/// <summary> /// 停止NodeServer /// </summary> public Task StopAsync() { if (server == null) { logger.LogDebug("Server instance is not start."); return(Task.CompletedTask); } OnStopping?.Invoke(new NodeServerStopEventArg(config.Host, config.Port, RouteManager.GetAllRoutes())); return(server.CloseAsync().ContinueWith(task => { if (task.Exception != null) { logger.LogError(task.Exception, $"Server closing has error. Host={config.Host}, Port={config.Port}, ExceptionMessage={task.Exception.InnerException.Message}, ExceptionStackTrace={task.Exception.InnerException.StackTrace}"); return; } logger.LogInformation("Server closed"); OnStopped?.Invoke(new NodeServerStopEventArg(config.Host, config.Port, RouteManager.GetAllRoutes())); })); }
public void Stop() { if (IsStopping || !IsStarted) { return; } IsStopping = true; OnStopping?.Invoke(); OnContextStopping?.Invoke(this); IsStopping = false; IsStarted = false; OnStopped?.Invoke(); OnContextStopped?.Invoke(this); DisposeModules(); DisposeExtensions(); }
public void Stop() { _isActive = false; OnStopping?.Invoke(this, EventArgs.Empty); }
private void CallOnStopping() { tokenSource.Cancel(); OnStopping.Invoke(); }
public BehaviourWaitUntilStopped(bool waitResult) : base("WaitUntilStopped", NodeType.TASK) { m_waitResult = waitResult; OnStopping.AddListener(OnStopping_Listener); }
private protected void __OnStopping(T server) => OnStopping?.Invoke(server);
private void ChangeState(ListenerState newState) { // Check that only allowed state changes are made switch (State) { case ListenerState.uninitialized: if (!(newState == ListenerState.initializing || newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Uninitialized->" + newState.ToString()); } break; case ListenerState.initializing: if (!(newState == ListenerState.initialized || newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Initializing->" + newState.ToString()); } break; case ListenerState.initialized: if (!(newState == ListenerState.starting || newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Initialized->" + newState.ToString()); } break; case ListenerState.starting: if (!(newState == ListenerState.started || newState == ListenerState.stopping || newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Starting->" + newState.ToString()); } break; case ListenerState.started: if (!(newState == ListenerState.stopping || newState == ListenerState.faulted || newState == ListenerState.starting)) { throw new Exception("Invalid state change. Started->" + newState.ToString()); } break; case ListenerState.stopping: if (!(newState == ListenerState.stopped || newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Stopping->" + newState.ToString()); } break; case ListenerState.stopped: if (!(newState == ListenerState.faulted)) { throw new Exception("Invalid state change. Stopped->" + newState.ToString()); } break; default: throw new Exception("Invalid state change"); } // Raise event switch (newState) { case ListenerState.initializing: if (OnInitializing != null) { OnInitializing.Invoke(); } break; case ListenerState.initialized: if (OnInitialized != null) { OnInitialized.Invoke(); } break; case ListenerState.starting: if (OnStarting != null) { OnStarting.Invoke(); } break; case ListenerState.started: if (OnStarted != null) { OnStarted.Invoke(); } break; case ListenerState.stopping: if (OnStopping != null) { OnStopping.Invoke(); } break; case ListenerState.stopped: if (OnStopped != null) { OnStopped.Invoke(); } break; case ListenerState.faulted: if (OnFaulted != null) { OnFaulted.Invoke(); } break; } State = newState; }
public void Stop() { OnStopping?.Invoke(this, new EventArgs()); }
public void Execute(OnStopping pipelineEvent) { _events.OnStopping(this, new PipelineEventEventArgs(pipelineEvent)); }