/// <summary>
 /// Method invoked when an extension is removed from the parent agent
 /// </summary>
 /// <param name="extension">Removed extension</param>
 private void ParentAgentOnExtensionRemoved(ScenarioAgentExtension extension)
 {
     if (extension is AgentBehaviour behaviourExtension)
     {
         behaviourExtension.BehaviourChanged -= ParentAgentOnBehaviourChanged;
     }
 }
Example #2
0
 /// <summary>
 /// Gets an agent's extension or adds a new one and returns it
 /// </summary>
 /// <param name="type">Extension type to get</param>
 /// <param name="defaultValue">Value that will be added if there is no extension available</param>
 /// <returns>Agent's extension of the given type</returns>
 public ScenarioAgentExtension GetOrAddExtension(Type type, ScenarioAgentExtension defaultValue = null)
 {
     if (Extensions.TryGetValue(type, out var extension))
     {
         return(extension);
     }
     if (defaultValue == null)
     {
         defaultValue = Activator.CreateInstance(type) as ScenarioAgentExtension;
     }
     if (defaultValue == null)
     {
         return(null);
     }
     Extensions.Add(type, defaultValue);
     defaultValue.Initialize(this);
     ExtensionAdded?.Invoke(defaultValue);
     return(defaultValue);
 }