///////// protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (nestedFSM == null || nestedFSM.primeNode == null){ return Status.Failure; } if (status == Status.Resting){ CheckInstance(); } if (status == Status.Resting || nestedFSM.isPaused){ status = Status.Running; nestedFSM.StartGraph(agent, blackboard, OnFSMFinish); } if (!string.IsNullOrEmpty(successState) && nestedFSM.currentStateName == successState){ nestedFSM.Stop(); return Status.Success; } if (!string.IsNullOrEmpty(failureState) && nestedFSM.currentStateName == failureState){ nestedFSM.Stop(); return Status.Failure; } return status; }
public static new ReflectedFunctionWrapper Create(MethodInfo method, IBlackboard bb) { Type type = null; var argTypes = new List<Type>{method.ReturnType}; var parameters = method.GetParameters(); if (parameters.Length == 0) type = typeof(ReflectedFunction<>); if (parameters.Length == 1) type = typeof(ReflectedFunction<,>); if (parameters.Length == 2) type = typeof(ReflectedFunction<,,>); if (parameters.Length == 3) type = typeof(ReflectedFunction<,,,>); argTypes.AddRange( parameters.Select(p => p.ParameterType) ); var o = (ReflectedFunctionWrapper)Activator.CreateInstance( type.RTMakeGenericType(argTypes.ToArray()) ); o._targetMethod = new SerializedMethodInfo(method); BBParameter.SetBBFields(o, bb); var bbParams = o.GetVariables(); for (int i = 0; i < parameters.Length; i++){ var p = parameters[i]; if (p.IsOptional){ bbParams[i + 1].value = p.DefaultValue; //index 0 is return value } } return o; }
public static new ReflectedActionWrapper Create(MethodInfo method, IBlackboard bb) { if (method == null) return null; Type type = null; Type[] argTypes = null; var parameters = method.GetParameters(); if (parameters.Length == 0) type = typeof(ReflectedAction); if (parameters.Length == 1) type = typeof(ReflectedAction<>); if (parameters.Length == 2) type = typeof(ReflectedAction<,>); if (parameters.Length == 3) type = typeof(ReflectedAction<,,>); argTypes = parameters.Select(p => p.ParameterType).ToArray(); var o = (ReflectedActionWrapper)Activator.CreateInstance( argTypes.Length > 0? type.RTMakeGenericType(argTypes) : type ); o._targetMethod = new SerializedMethodInfo(method); BBParameter.SetBBFields(o, bb); var bbParams = o.GetVariables(); for (int i = 0; i < parameters.Length; i++){ var p = parameters[i]; if (p.IsOptional){ bbParams[i].value = p.DefaultValue; } } return o; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; if (list == null || list.Count == 0) return Status.Failure; for (int i = currentIndex; i < list.Count; i++){ current.value = list[i]; status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Success && terminationCondition == TerminationConditions.FirstSuccess) return Status.Success; if (status == Status.Failure && terminationCondition == TerminationConditions.FirstFailure) return Status.Failure; if (status == Status.Running){ currentIndex = i; return Status.Running; } if (currentIndex == list.Count-1 || currentIndex == maxIteration.value-1){ return status; } decoratedConnection.Reset(); currentIndex ++; } return Status.Running; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; switch(filterMode) { case FilterMode.CoolDown: if (currentTime > 0) return inactiveWhenLimited? Status.Resting : Status.Failure; status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Success || status == Status.Failure) StartCoroutine(Cooldown()); break; case FilterMode.LimitNumberOfTimes: if (executedCount >= maxCount.value) return inactiveWhenLimited? Status.Resting : Status.Failure; status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Success || status == Status.Failure) executedCount += 1; break; } return status; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { currentProbability = probability; for (var i = 0; i < outConnections.Count; i++){ if (failedIndeces.Contains(i)) continue; if (currentProbability > childWeights[i].value){ currentProbability -= childWeights[i].value; continue; } status = outConnections[i].Execute(agent, blackboard); if (status == Status.Success || status == Status.Running) return status; if (status == Status.Failure){ failedIndeces.Add(i); var newTotal = GetTotal(); for (var j = 0; j < failedIndeces.Count; j++){ newTotal -= childWeights[j].value; } probability = Random.Range(0, newTotal); return Status.Running; } } return Status.Failure; }
protected override Status OnExecute(Component agent, IBlackboard bb){ if (outConnections.Count == 0) return Error("There are no connections to the Multiple Choice Node!"); var finalOptions = new Dictionary<IStatement, int>(); for (var i = 0; i < availableChoices.Count; i++){ var condition = availableChoices[i].condition; if (condition == null || condition.CheckCondition(finalActor.transform, bb)){ var tempStatement = availableChoices[i].statement.BlackboardReplace(bb); finalOptions[tempStatement] = i; } } if (finalOptions.Count == 0){ Debug.Log("Multiple Choice Node has no available options. Dialogue Ends"); DLGTree.Stop(); return Status.Failure; } if (availableTime > 0) StartCoroutine(CountDown()); var optionsInfo = new MultipleChoiceRequestInfo(finalOptions, availableTime, OnOptionSelected); DialogueTree.RequestMultipleChoices( optionsInfo ); return Status.Running; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (outConnections.Count == 0) return Status.Failure; if (selectionMode == CaseSelectionMode.IndexBased){ current = intCase.value; if (outOfRangeMode == OutOfRangeMode.LoopIndex) current = Mathf.Abs(current) % outConnections.Count; } else { current = (int)System.Enum.Parse(enumCase.value.GetType(), enumCase.value.ToString()); } if (runningIndex != current) outConnections[runningIndex].Reset(); if (current < 0 || current >= outConnections.Count) return Status.Failure; status = outConnections[current].Execute(agent, blackboard); if (status == Status.Running) runningIndex = current; return status; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { for ( var i= 0; i < outConnections.Count; i++){ if (!dynamic && finishedConnections.Contains(outConnections[i])) continue; status = outConnections[i].Execute(agent, blackboard); if (status == Status.Failure && (policy == ParallelPolicy.FirstFailure || policy == ParallelPolicy.FirstSuccessOrFailure) ){ ResetRunning(); return Status.Failure; } if (status == Status.Success && (policy == ParallelPolicy.FirstSuccess || policy == ParallelPolicy.FirstSuccessOrFailure) ){ ResetRunning(); return Status.Success; } if (status != Status.Running && !finishedConnections.Contains(outConnections[i])) finishedConnections.Add(outConnections[i]); } if ( finishedConnections.Count != outConnections.Count ) return Status.Running; switch(policy) { case ParallelPolicy.FirstFailure: return Status.Success; case ParallelPolicy.FirstSuccess: return Status.Failure; } return Status.Running; }
///Tick the tree once for the provided agent and with the provided blackboard public Status Tick(Component agent, IBlackboard blackboard){ if (rootStatus != Status.Running) primeNode.Reset(); rootStatus = primeNode.Execute(agent, blackboard); return rootStatus; }
protected override Status OnExecute(Component agent, IBlackboard bb) { if (_targetNode == null) return Error("Target node of GOTO node is null"); DLGTree.EnterNode(_targetNode); return Status.Success; }
///Set the blackboard reference provided for all *public* BBParameter and List<BBParameter> fields on the target object provided. public static void SetBBFields(object o, IBlackboard bb){ ParseObject(o, (bbParam)=> { bbParam.bb = bb; if (bb != null){ bbParam.varRef = bb.GetVariable(bbParam.name); } }); }
public SendNotifications(IEnumerable<INotificationReceiver> receivers, bool isDownloadOnly, bool withSkipDatabaseUpdate, IUpdatePackage package, INowGetter nowGetter, IBlackboard blackboard) { _package = package; _receivers = receivers; _blackboard = blackboard; _nowGetter = nowGetter; _isDownloadOnly = isDownloadOnly; _withSkipDatabaseUpdate = withSkipDatabaseUpdate; }
///////// ///////// protected override Status OnExecute(Component agent, IBlackboard blackboard){ if (subTree == null || subTree.primeNode == null) return Status.Failure; if (status == Status.Resting) CheckInstance(); return subTree.Tick(agent, blackboard); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; status = decoratedConnection.Execute(agent, blackboard); if ( status == Status.Running ) return Status.Running; decoratedConnection.Reset(); return Status.Resting; }
public GetVersionInfo(string workFolder, IUpdatePackage package, string versionInfoFile, ISingleFile singleFile, IBlackboard blackboard) { _workFolder = workFolder; _package = package; _singleFile = singleFile; _blackboard = blackboard; _versionInfoFile = versionInfoFile; _fullPathToLocalFile = Path.Combine(_workFolder, Path.GetFileNameWithoutExtension(package.Access.GetFilenameOnly()), versionInfoFile); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; if (newAgent.value != null) agent = newAgent.value.transform; return decoratedConnection.Execute(agent, blackboard); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (string.IsNullOrEmpty(targetNodeTag)) return Status.Failure; if ( targetNode == null ) return Status.Failure; if (graph.primeNode != targetNode) graph.primeNode = targetNode; return Status.Success; }
public CommandBuilder(ISingleFile singleFile, IDirectory directory, ILogger logger, IRunExternalCommand runExternalCommand, IHtmlGetter htmlGetter, INowGetter nowGetter, IBlackboard blackboard) { _blackboard = blackboard; _singleFile = singleFile; _logger = logger; _directory = directory; _runExternalCommand = runExternalCommand; _htmlGetter = htmlGetter; _nowGetter = nowGetter; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { for ( var i= dynamic? 0 : lastRunningNodeIndex; i < outConnections.Count; i++){ status = outConnections[i].Execute(agent, blackboard); switch(status) { case Status.Running: if (dynamic && i < lastRunningNodeIndex) outConnections[lastRunningNodeIndex].Reset(); lastRunningNodeIndex = i; return Status.Running; case Status.Success: if (dynamic && i < lastRunningNodeIndex) outConnections[lastRunningNodeIndex].Reset(); return Status.Success; } } return Status.Failure; /* if (dynamic && status != Status.Success){ for (int i = 0; i < lastRunningNodeIndex; i++){ if (outConnections[i].Execute(agent, blackboard) == Status.Success){ outConnections[lastRunningNodeIndex].Reset(); return Status.Success; } } } if (lastRunningNodeIndex >= outConnections.Count) return Status.Failure; status = outConnections[lastRunningNodeIndex].Execute(agent, blackboard); if (status != Status.Failure) return status; lastRunningNodeIndex++; return OnExecute(agent, blackboard); */ }
protected override Status OnExecute(Component agent, IBlackboard bb){ if (outConnections.Count == 0) return Error("There are no connections on the Dialogue Condition Node"); for (var i = 0; i < outConnections.Count; i++){ if (conditions[i] == null || conditions[i].CheckCondition(finalActor.transform, graphBlackboard)){ DLGTree.Continue(i); return Status.Success; } } Debug.LogWarning("No condition is true. Dialogue Stops"); DLGTree.Stop(); return Status.Failure; }
///Replace the text of the statement found in brackets, with blackboard variables ToString public Statement BlackboardReplace(IBlackboard bb){ var s = text; var i = 0; while ( (i = s.IndexOf('[', i)) != -1){ var end = s.Substring(i + 1).IndexOf(']'); var varName = s.Substring(i + 1, end); var output = s.Substring(i, end + 2); object o = null; if (bb != null) o = bb.GetValue<object>(varName); s = s.Replace(output, o != null? o.ToString() : "*" + varName + "*"); i++; } return new Statement(s, audio, meta); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Running){ timer += Time.deltaTime; } if ( !(timer >= timeout.value) ) return status; timer = 0; decoratedConnection.Reset(); return Status.Failure; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; status = decoratedConnection.Execute(agent, blackboard); switch(status) { case Status.Success: return Status.Failure; case Status.Failure: return Status.Success; } return status; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (status == Status.Resting) orderedConnections = outConnections.OrderBy(c => priorities[outConnections.IndexOf(c)].value).Reverse().ToList(); for (var i = current; i < orderedConnections.Count; i++){ status = orderedConnections[i].Execute(agent, blackboard); if (status == Status.Success){ return Status.Success; } if (status == Status.Running){ current = i; return Status.Running; } } return Status.Failure; }
///Set the value of the Variable variable defined by its name. If a data by that name and type doesnt exist, a new data is added by that name public static Variable SetVariableValue(this IBlackboard blackboard, string varName, object value) { Variable variable; if (!blackboard.variables.TryGetValue(varName, out variable)) { Logger.Log(string.Format("No Variable of name '{0}' and type '{1}' exists on Blackboard '{2}'. Adding new instead...", varName, value != null ? value.GetType().FriendlyName() : "null", blackboard), LogTag.BLACKBOARD, blackboard); variable = blackboard.AddVariable(varName, value); return(variable); } try { variable.value = value; } catch { Logger.LogError(string.Format("Can't cast value '{0}' to blackboard variable of name '{1}' and type '{2}'", value != null ? value.ToString() : "null", varName, variable.varType.FriendlyName()), LogTag.BLACKBOARD, blackboard); return(null); } return(variable); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (condition == null || outConnections.Count < 2) { return(Status.Optional); } if (dynamic || status == Status.Resting) { var lastIndex = succeedIndex; succeedIndex = condition.CheckCondition(agent, blackboard) ? 0 : 1; if (succeedIndex != lastIndex) { outConnections[lastIndex].Reset(); } } return(outConnections[succeedIndex].Execute(agent, blackboard)); }
//Actions and Conditions call this before execution. Returns if the task was sucessfully initialized as well protected bool Set(Component newAgent, IBlackboard newBB) { //set blackboard with normal setter first blackboard = newBB; /// DIVERGENCE /// MORI /// emilio.saffi /// Xcode was catching EXE_BAD_ACCESS if (agentIsOverride) { newAgent = (Component)overrideAgent.value; } if (current != null && newAgent != null && current.gameObject == newAgent.gameObject) { return(isActive = true); } return(isActive = Initialize(newAgent, agentType)); /// DIVERGENCE /// MORI /// emilio.saffi /// Xcode was catching EXE_BAD_ACCESS }
//OnEnter... sealed protected override Status OnExecute(Component agent, IBlackboard bb) { if (status == Status.Resting || status == Status.Running) { status = Status.Running; for (int i = 0; i < outConnections.Count; i++) { if (((FSMConnection)outConnections[i]).condition != null) { ((FSMConnection)outConnections[i]).condition.Enable(agent, bb); } } OnEnter(); } return(status); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return(Status.Optional); } if (condition == null || condition.CheckCondition(agent, blackboard) == false) { return(decoratedConnection.Execute(agent, blackboard)); } if (decoratedConnection.status == Status.Running) { decoratedConnection.Reset(); } return(Status.Failure); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (string.IsNullOrEmpty(targetNodeTag)) { return(Status.Failure); } if (targetNode == null) { return(Status.Failure); } if (graph.primeNode != targetNode) { graph.primeNode = targetNode; } return(Status.Success); }
public NodeState Tick(int index, INodeBlob blob, IBlackboard bb) { var endIndex = blob.GetEndIndex(index); var childIndex = index + 1; for (var i = childIndex + 1 /* always reset directly child */; i < endIndex; i++) { if (blob.GetState(i) == NodeState.Running) { endIndex = i; break; } } var count = endIndex - childIndex; // count will be 0 if there's no child blob.ResetStates(childIndex, count); return(blob.TickChildren(index, bb).FirstOrDefault()); }
///---------------------------------------------------------------------------------------------- ///Gets the variable data value from the blackboard with provided name and type T. public static T GetVariableValue <T>(this IBlackboard blackboard, string varName) { Variable variable; if (!blackboard.variables.TryGetValue(varName, out variable)) { Logger.LogError(string.Format("No Variable of name '{0}' and type '{1}' exists on Blackboard '{2}'. Returning default T...", varName, typeof(T).FriendlyName(), blackboard), LogTag.BLACKBOARD, blackboard); return(default(T)); } if (variable is Variable <T> ) { return((variable as Variable <T>).value); } try { return((T)variable.value); } catch { Logger.LogError(string.Format("Can't cast value of variable with name '{0}' to type '{1}'", varName, typeof(T).FriendlyName()), LogTag.BLACKBOARD, blackboard); } return(default(T)); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return(Status.Resting); } status = decoratedConnection.Execute(agent, blackboard); switch (status) { case Status.Resting: return(Status.Running); case Status.Running: return(status); } switch (repeaterMode) { case RepeaterMode.RepeatTimes: //repeatTimes.value = Mathf.Max(repeatTimes.value, 1); if (currentIteration >= repeatTimes.value) { return(status); } currentIteration++; break; case RepeaterMode.RepeatUntil: if ((int)status == (int)repeatUntilStatus) { return(status); } break; } decoratedConnection.Reset(); return(Status.Running); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { for (var i = current; i < outConnections.Count; i++){ status = outConnections[i].Execute(agent, blackboard); if (status == Status.Running){ current = i; return Status.Running; } if (status == Status.Success){ SendToBack(i); return Status.Success; } } return Status.Failure; }
///Promotes the parameter to a variable on the target blackboard (overriden if parameter name is a path to a global bb). public Variable PromoteToVariable(IBlackboard targetBB) { if (string.IsNullOrEmpty(name)) { varRef = null; return(null); } var varName = name; var bbName = targetBB != null? targetBB.name : string.Empty; if (name.Contains("/")) { var split = name.Split('/'); bbName = split[0]; varName = split[1]; targetBB = GlobalBlackboard.Find(bbName); } if (targetBB == null) { varRef = null; Logger.LogError(string.Format("Parameter '{0}' failed to promote to a variable, because Blackboard named '{1}' could not be found.", varName, bbName), "Variable", this); return(null); } varRef = targetBB.AddVariable(varName, varType); if (varRef != null) { #if UNITY_EDITOR if (NodeCanvas.Editor.NCPrefs.logDynamicParametersInfo) { Logger.Log(string.Format("Parameter '{0}' (of type '{1}') promoted to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), bbName), "Variable", this); } #endif } else { Logger.LogError(string.Format("Parameter {0} (of type '{1}') failed to promote to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), bbName), "Variable", this); } return(varRef); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (outConnections.Count == 0) { return(Status.Optional); } if (status == Status.Resting || dynamic) { if (selectionMode == CaseSelectionMode.IndexBased) { current = intCase.value; if (outOfRangeMode == OutOfRangeMode.LoopIndex) { current = Mathf.Abs(current) % outConnections.Count; } } else { current = (int)enumCase.value; } if (runningIndex != current) { outConnections[runningIndex].Reset(); } if (current < 0 || current >= outConnections.Count) { return(Status.Failure); } } status = outConnections[current].Execute(agent, blackboard); if (status == Status.Running) { runningIndex = current; } return(status); }
//show variable data static void ShowDataGUI(Variable data, IBlackboard bb, UnityEngine.Object contextParent, GUILayoutOption[] layoutOptions) { //Bind info or value GUI control if (data.hasBinding) { var idx = data.propertyPath.LastIndexOf('.'); var typeName = data.propertyPath.Substring(0, idx); var memberName = data.propertyPath.Substring(idx + 1); GUI.color = new Color(0.8f, 0.8f, 1); GUILayout.Label(string.Format(".{0} ({1})", memberName, typeName.Split('.').Last()), layoutOptions); GUI.color = Color.white; } else { GUI.enabled = !data.isProtected; data.value = VariableField(data, contextParent, layoutOptions); GUI.enabled = true; GUI.backgroundColor = Color.white; } }
///Set GraphEditor inspected references public static void SetReferences(Graph newGraph, GraphOwner owner, IBlackboard blackboard) { if (current == null) { Debug.Log("GraphEditor is not open."); return; } willRepaint = true; fullDrawPass = true; rootGraph = newGraph; targetOwner = owner; if (rootGraph != null) { rootGraph.currentChildGraph = null; rootGraph.UpdateNodeIDs(true); rootGraph.UpdateReferences(owner, blackboard); } GraphEditorUtility.activeElement = null; current.Repaint(); }
//// protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (subGraph == null || subGraph.primeNode == null) { return(Status.Optional); } if (status == Status.Resting) { status = Status.Running; this.TryStartSubGraph(agent, OnDLGFinished); } if (status == Status.Running) { currentInstance.UpdateGraph(); } return(status); }
protected override Status OnExecute(Component agent, IBlackboard bb) { if (outConnections.Count == 0) { return(Error("There are no connections on the Dialogue Condition Node")); } for (var i = 0; i < outConnections.Count; i++) { if (conditions[i] == null || conditions[i].CheckCondition(finalActor.transform, graphBlackboard)) { DLGTree.Continue(i); return(Status.Success); } } //Debug.LogWarning("No condition is true. Dialogue Stops"); DLGTree.Stop(false); return(Status.Failure); }
protected override Status OnExecute(Component agent, IBlackboard bb) { if (outConnections.Count == 0) { return(Error("There are no connections on the Dialogue Condition Node")); } for (var i = 0; i < outConnections.Count; i++) { if (conditions[i] == null || conditions[i].CheckOnce(finalActor.transform, graphBlackboard)) { DLGTree.Continue(i); return(Status.Success); } } ParadoxNotion.Services.Logger.LogWarning("No condition is true. Dialogue Ends.", LogTag.EXECUTION, this); DLGTree.Stop(false); return(Status.Failure); }
public static IEnumerable <NodeState> TickChildren( this INodeBlob blob , int index , IBlackboard bb , Predicate <NodeState> breakCheck , Predicate <NodeState> tickCheck ) { foreach (var childIndex in blob.GetChildrenIndices(index)) { var prevState = blob.GetState(childIndex); var currentState = tickCheck(prevState) ? VirtualMachine.Tick(childIndex, blob, bb) : 0; yield return(currentState); if (breakCheck(currentState == 0 ? prevState : currentState)) { yield break; } } }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return(Status.Resting); } status = decoratedConnection.Execute(agent, blackboard); switch (status) { case Status.Success: return(Status.Failure); case Status.Failure: return(Status.Success); } return(status); }
///Replace the text of the statement found in brackets, with blackboard variables ToString and returns a Statement copy public Statement BlackboardReplace(IBlackboard bb) { var s = text; var i = 0; while ((i = s.IndexOf('[', i)) != -1) { var end = s.Substring(i + 1).IndexOf(']'); var input = s.Substring(i + 1, end); //what's in the brackets var output = s.Substring(i, end + 2); //what should be replaced (includes brackets) object o = null; if (bb != null) //referenced blackboard replace { var v = bb.GetVariable(input, typeof(object)); if (v != null) { o = v.value; } } if (input.Contains("/")) //global blackboard replace { var globalBB = GlobalBlackboard.Find(input.Split('/').First()); if (globalBB != null) { var v = globalBB.GetVariable(input.Split('/').Last(), typeof(object)); if (v != null) { o = v.value; } } } s = s.Replace(output, o != null? o.ToString() : output); i++; } return(new Statement(s, audio, meta)); }
///---------------------------------------------------------------------------------------------- protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (subGraph == null || subGraph.primeNode == null) { return(Status.Optional); } if (status == Status.Resting) { this.TryStartSubGraph(agent); } currentInstance.UpdateGraph(this.graph.deltaTime); if (currentInstance.repeat && currentInstance.rootStatus != Status.Running) { this.TryReadAndUnbindMappedVariables(); } return(currentInstance.rootStatus); }
///Replace the text of the statement found in brackets, with blackboard variables ToString public Statement BlackboardReplace(IBlackboard bb) { var s = text; var i = 0; while ((i = s.IndexOf('[', i)) != -1) { var end = s.Substring(i + 1).IndexOf(']'); var varName = s.Substring(i + 1, end); var output = s.Substring(i, end + 2); object o = null; if (bb != null) { o = bb.GetValue <object>(varName); } s = s.Replace(output, o != null? o.ToString() : "*" + varName + "*"); i++; } return(new Statement(s, audio, meta)); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { for (var i = current; i < outConnections.Count; i++) { status = outConnections[i].Execute(agent, blackboard); if (status == Status.Running) { current = i; return(Status.Running); } if (status == Status.Success) { SendToBack(i); return(Status.Success); } } return(Status.Failure); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (flowScript == null) { return(Status.Failure); } if (status == Status.Resting) { CheckInstance(); status = Status.Running; flowScript.StartGraph(agent, blackboard, false, OnFlowScriptFinished); } if (status == Status.Running) { flowScript.UpdateGraph(); } return(status); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { currentProbability = probability; for (var i = 0; i < outConnections.Count; i++) { if (currentProbability >= childWeights[i].value) { currentProbability -= childWeights[i].value; continue; } status = outConnections[i].Execute(agent, blackboard); if (status == Status.Running || status == Status.Success) { return(status); } } return(Status.Failure); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (outConnections.Count == 0) { return(Status.Failure); } if (selectionMode == CaseSelectionMode.IndexBased) { current = intCase.value; if (outOfRangeMode == OutOfRangeMode.LoopIndex) { current = Mathf.Abs(current) % outConnections.Count; } } else { //current = (int)System.Enum.Parse(enumCase.value.GetType(), enumCase.value.ToString()); current = (int)enumCase.value; } if (runningIndex != current) { outConnections[runningIndex].Reset(); } if (current < 0 || current >= outConnections.Count) { return(Status.Failure); } status = outConnections[current].Execute(agent, blackboard); if (status == Status.Running) { runningIndex = current; } return(status); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return(Status.Resting); } switch (filterMode) { case FilterMode.CoolDown: if (currentTime > 0) { return(inactiveWhenLimited? Status.Resting : Status.Failure); } status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Success || status == Status.Failure) { StartCoroutine(Cooldown()); } break; case FilterMode.LimitNumberOfTimes: if (executedCount >= maxCount.value) { return(inactiveWhenLimited? Status.Resting : Status.Failure); } status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Success || status == Status.Failure) { executedCount += 1; } break; } return(status); }
//OnEnter... sealed protected override Status OnExecute(Component agent, IBlackboard bb) { if (!_hasInit) { _hasInit = true; OnInit(); } if (status == Status.Resting) { status = Status.Running; for (int i = 0; i < outConnections.Count; i++) { ((FSMConnection)outConnections[i]).EnableCondition(agent, bb); } OnEnter(); } return(status); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return(Status.Resting); } status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Running) { timer += Time.deltaTime; } if (!(timer >= timeout.value)) { return(status); } timer = 0; decoratedConnection.Reset(); return(Status.Failure); }
public static NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard) { var flags = blob.TickChildren(index, blackboard) .Aggregate((NodeState)0, (childStateFlags, childState) => { childStateFlags |= childState; return(childStateFlags); }); if (flags.HasFlagFast(NodeState.Running)) { return(NodeState.Running); } if (flags.HasFlagFast(NodeState.Failure)) { return(NodeState.Failure); } if (flags.HasFlagFast(NodeState.Success)) { return(NodeState.Success); } return(0); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { //this part is so that Wait node can be used as leaf too if (condition != null) { if (status == Status.Resting) { condition.Enable(agent, blackboard); } return(condition.Check(agent, blackboard) ? Status.Success : Status.Running); } //----- return(Status.Optional); } if (condition == null) { return(decoratedConnection.Execute(agent, blackboard)); } if (status == Status.Resting) { condition.Enable(agent, blackboard); } if (accessed) { return(decoratedConnection.Execute(agent, blackboard)); } if (condition.Check(agent, blackboard)) { accessed = true; } return(accessed ? decoratedConnection.Execute(agent, blackboard) : Status.Running); }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Failure; if (agent != graphAgent) SetGuards(agent); for (var i = 0; i < AgentGuards(agent).Count; i++){ var guard = AgentGuards(agent)[i]; if (guard != this && guard.isGuarding && guard.token.value == this.token.value) return ifGuarded == GuardMode.ReturnFailure? Status.Failure : Status.Running; } status = decoratedConnection.Execute(agent, blackboard); if (status == Status.Running){ isGuarding = true; return Status.Running; } isGuarding = false; return status; }
//Construct public GraphSerializationData(Graph graph) { this.version = SerializationVersion; this.type = graph.GetType(); this.name = graph.name; this.comments = graph.graphComments; this.translation = graph.translation; this.nodes = graph.allNodes; this.canvasGroups = graph.canvasGroups; this.localBlackboard = graph.localBlackboard; var structConnections = new List<Connection>(); foreach (var node in nodes){ if (node is ISerializationCallbackReceiver) (node as ISerializationCallbackReceiver).OnBeforeSerialize(); foreach (var c in node.outConnections) structConnections.Add(c); } this.connections = structConnections; this.primeNode = graph.primeNode; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) return Status.Resting; status = decoratedConnection.Execute(agent, blackboard); switch(status) { case Status.Resting: return Status.Running; case Status.Running: return status; } switch(repeaterMode) { case RepeaterMode.RepeatTimes: //repeatTimes.value = Mathf.Max(repeatTimes.value, 1); if (currentIteration >= repeatTimes.value) return status; currentIteration ++; break; case RepeaterMode.RepeatUntil: if ((int)status == (int)repeatUntilStatus) return status; break; } decoratedConnection.Reset(); return Status.Running; }
protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (string.IsNullOrEmpty(targetNodeTag)) return Status.Failure; if ( targetNodes.Count == 0 ) return Status.Failure; if (toggleMode == ToggleMode.Enable){ foreach (var node in targetNodes) node.inConnections[0].isActive = true; } if (toggleMode == ToggleMode.Disable){ foreach (var node in targetNodes) node.inConnections[0].isActive = false; } if (toggleMode == ToggleMode.Toggle){ foreach (var node in targetNodes) node.inConnections[0].isActive = !node.inConnections[0].isActive; } return Status.Success; }