// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { GameObject prefab = behaviorTreeExecutor.GetGameObjectVariable(prefabID); if (prefab == null) { return(Result.Failure); } GameObject spawnedObject; if (spawnAsChild) { spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform); } else { spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform.TransformPoint(prefab.transform.position), prefab.transform.rotation); } if (storeInVariable) { TypedVariable <GameObject> gameObjectVariableOverride = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == spawnedObjectID); if (gameObjectVariableOverride == null) { UnityEngine.Debug.LogWarning("Object ID " + spawnedObjectID + " not found in variable overrides of " + behaviorTreeExecutor.name); } else { gameObjectVariableOverride.value = spawnedObject; } } return(Result.Success); }
/// <summary> /// Convert a newer variable or an existing variable. /// Keeps the current value of this variable. /// </summary> /// <param name="proc">process object</param> /// <param name="converter">converter object</param> /// <param name="varName">name of the variable</param> /// <param name="desiredDataType">data type to convert</param> /// <returns>the conversion string result</returns> public static string ConvertVariableType(IProcessInstance proc, ICodeConverter converter, string varName, EnumDataType desiredDataType) { // store the result in the scope with the varName parameter if (proc.CurrentScope.Exists(varName)) { string result = String.Empty; // get the variable infos IData myVar = proc.CurrentScope.GetVariable(varName); // specific prefix is used with desired data type if (myVar.TypeExists(desiredDataType)) { // if the desired data type is not the current type if (myVar.DataType != desiredDataType) { TypedVariable tv = new TypedVariable(myVar.Name, myVar.Prefix, myVar.DataType, desiredDataType); result = tv.MoveType(converter, proc.CurrentScope); } } else { TypedVariable tv = new TypedVariable(myVar.Name, myVar.Prefix, myVar.DataType, desiredDataType); result = tv.MoveType(converter, proc.CurrentScope); } return(result); } else { throw new ArgumentException("La variable '" + varName + "' n'existe pas dans le scope"); } }
private string ReadString(TypedVariable stringContainer, ulong stringLength) { // stringContainer.Data.Size actually lies - we should use Process bitness instead. var pointerValue = _helper.ReadValue(stringContainer.Data.Offset, (uint)_metaData.PointerSize); var stringPointer = _metaData.Is64BitProcess ? BitConverter.ToUInt64(pointerValue, 0) : BitConverter.ToUInt32(pointerValue, 0); var actualString = _helper.ReadString(stringPointer, (uint)stringLength); return(actualString); }
// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { TypedVariable <GameObject> objectVariable = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == objectID); if (objectVariable == null) { return(Result.Failure); } GameObject objectToApplyForceTo = objectVariable.value; if (objectToApplyForceTo == null) { UnityEngine.Debug.LogError("No object to apply a force to", behaviorTreeExecutor); return(Result.Failure); } Rigidbody rigidbody = objectToApplyForceTo.GetComponent <Rigidbody>(); if (rigidbody == null) { UnityEngine.Debug.LogError("Provided prefab object of " + name + " in behavior tree of " + behaviorTreeExecutor.name + " has no rigidbody."); return(Result.Failure); } switch (relativeObject) { default: case RelativeObjectOption.None: rigidbody.AddForce(force, forceMode); break; case RelativeObjectOption.Self: rigidbody.AddForce( behaviorTreeExecutor.transform.TransformVector(force), forceMode); break; case RelativeObjectOption.Other: rigidbody.AddForce( behaviorTreeExecutor.GetGameObjectVariable(otherObjectID).transform.TransformVector(force), forceMode); break; } return(Result.Success); }
private static void CreateListMenuItems <T>(List <TypedVariable <T> > originalList, List <TypedVariable <T> > targetList, GenericMenu instanceOverrideMenu) { foreach (var variable in originalList) { TypedVariable <T> typedVariableInstance = TypedVariable <T> .CopyData(variable); GUIContent text = new GUIContent(typedVariableInstance.name + " ( " + typedVariableInstance.value + " )"); if (targetList.Exists(y => y.ID == variable.ID)) { instanceOverrideMenu.AddDisabledItem(text, false); } else { instanceOverrideMenu.AddItem(text, false, () => targetList.Add(new TypedVariable <T>(variable.id) { name = variable.name })); } } }
private static Dictionary <string, TypedVariable> GetChildFields(TypedVariable variable, int enumValue) { int counter = -1; var actualFields = new Dictionary <string, TypedVariable>(); foreach (var pair in variable.Fields) { if (pair.Key.StartsWith(_enumFieldName, StringComparison.OrdinalIgnoreCase)) { counter++; continue; } if (counter == enumValue) { actualFields.Add(pair.Key, pair.Value); } } return(actualFields); }
public static void IsolatedFunction(ICompilateurInstance comp, IProcessInstance proc, ICodeConverter converter, IsolatedFunctionDelegate d) { if (converter.CurrentFunction.IsStaticControlFlow) { Dictionary <string, IParameter> varNames, leftNames; Action <KeyValuePair <string, IParameter> > action; TypedVariable tv; IFunction prec = converter.CurrentFunction; IFunction thisFunc = new Function(); thisFunc.IndentSize = prec.IndentSize; thisFunc.IsVisible = true; thisFunc.StrictName = "inner_" + comp.Unique.ComputeNewString(); thisFunc.PropagateControlFlow(prec); // ajoute la fonction dans la liste converter.ImplementedFunctions.Add(thisFunc); // change la fonction courante converter.SetCurrentFunction(thisFunc); d(); // retourne à la fonction précédente pour traiter le changement de type converter.SetCurrentFunction(prec); // supprime la fonction de la liste converter.ImplementedFunctions.Remove(thisFunc); leftNames = new Dictionary <string, IParameter>(); // élimine les variables passées en paramètre qui n'ont pas changé de type thisFunc.Parameters.ForEach(new Action <IParameter>(delegate(IParameter par) { if (!leftNames.ContainsKey(par.VariableName) && par.Order != EnumParameterOrder.E_NEW) { leftNames.Add(par.VariableName, par); } })); // enregistre le nom distinct des variables passées en paramètre qui soient mutable et initiale varNames = new Dictionary <string, IParameter>(); thisFunc.Parameters.ForEach(new Action <IParameter>(delegate(IParameter par) { if (!varNames.ContainsKey(par.VariableName) && leftNames.ContainsKey(par.VariableName) && par.IsMutableParameter && par.Order == EnumParameterOrder.E_NEW) { varNames.Add(par.VariableName, par); } })); // modifie toutes les variables en SimpleType action = new Action <KeyValuePair <string, IParameter> >(delegate(KeyValuePair <string, IParameter> kv) { Regex reg = new Regex(@"\$\[([^:]*):([a-z]+_" + kv.Key + @")\]"); thisFunc.Source = reg.Replace(thisFunc.Source, new MatchEvaluator(delegate(Match m) { string type = m.Groups[1].Value; string name = m.Groups[2].Value; int pos = name.IndexOf('_'); string result = String.Empty; if (pos != -1) { result = "$[" + type + ":st_" + name.Substring(pos + 1) + "]"; } else { result = "$[" + type + ":st_" + name + "]"; } return(result); })); tv = new TypedVariable(kv.Value.VariableName, kv.Value.FormalParameter, kv.Value.DataType, EnumDataType.E_SIMPLETYPE); tv.MoveType(converter, proc.CurrentScope); }); foreach (KeyValuePair <string, IParameter> kv in varNames.Except(leftNames)) { action(kv); } // copie de l'implémentation de cette fonction dans la fonction en cours prec.Source += thisFunc.Source; // copies des variables locales de cette fonction dans la fonction en cours thisFunc.LocalVariables.ForEach(new Action <IStructure>(delegate(IStructure loc) { if (!converter.CurrentFunction.LocalVariables.Exists(new Predicate <IStructure>(delegate(IStructure cur) { return(cur.PrefixedFieldName == loc.PrefixedFieldName); }))) { converter.CurrentFunction.LocalVariables.Add(loc); } })); // mettre à jour les paramètres foreach (KeyValuePair <string, IParameter> kv in varNames.Except(leftNames)) { List <IParameter> pars = thisFunc.Parameters.FindAll(new Predicate <IParameter>(delegate(IParameter par) { return(par.VariableName == kv.Key); })); if (pars.Count > 1) { pars.ForEach(new Action <IParameter>(delegate(IParameter update) { if (update.Order == EnumParameterOrder.E_LAST) { tv = new TypedVariable(update.VariableName, update.FormalParameter, EnumDataType.E_SIMPLETYPE, update.DataType); tv.MoveType(converter, proc.CurrentScope); } })); } else if (pars.Count == 1) { tv = new TypedVariable(pars[0].VariableName, pars[0].FormalParameter, EnumDataType.E_SIMPLETYPE, pars[0].DataType); tv.MoveType(converter, proc.CurrentScope); } } } else { d(); } }