/** * Spawns the child task. This method creates a new HierarchicalContext, * sets its parent to the context of the ExecutionHierarchicalContextManager, and spawns * the child task using this HierarchicalContext. * * @see jbt.execution.core.ExecutionTask#internalSpawn() */ protected override void InternalSpawn() { var newContext = new HierarchicalContext(); newContext.SetParent(Context); _child = ((ModelDecorator)ModelTask).getChild().CreateExecutor( Executor, this); _child.AddTaskListener(this); _child.Spawn(newContext); }
public void Indexer_pulls_variables_from_parent_when_they_dont_exist_in_the_current_context() { var parentContext = new HierarchicalContext(); parentContext.SetVariable("Hello", true); var childContext = new HierarchicalContext(); childContext.SetParent(parentContext); var context = (IContext)childContext; Assert.IsTrue((bool)context["Hello"]); }
// return all enemies in turn public override IList <IContext> AllContexts(Logging loggingSetting) { var masterContext = new ContextDictionary(); var inventoryContents = m_inventory.CalculateInventoryContents(); foreach (var ammo in inventoryContents) { masterContext.SetContext(ammo.Name, ammo.GetCount()); } var allEnemies = GameObject.FindGameObjectsWithTag(m_enemyTagName); var allContexts = new IContext[allEnemies.Length]; for (int enemyIndex = 0; enemyIndex < allEnemies.Length; ++enemyIndex) { var enemy = allEnemies[enemyIndex]; var context = new ContextDictionary(); float targetDistance = Vector3.Distance(transform.position, enemy.transform.position); if (loggingSetting == Logging.Enabled) { Debug.Log("considering enemy " + enemy.name + " at distance " + targetDistance); } context.SetContext(m_enemyGOContextName, enemy); context.SetContext(m_enemyDistanceContextName, targetDistance); var parentedContext = new HierarchicalContext(context, masterContext); allContexts[enemyIndex] = parentedContext; } return(allContexts); }