コード例 #1
0
        /// <summary>
        /// Adds the specified behavior.
        /// </summary>
        /// <param name="behavior">The behavior.</param>
        public void Add(IBehavior behavior)
        {
            // Try finding the entity behavior dictionary
            if (!_entityBehaviors.TryGetValue(behavior.Name, out var ebd))
            {
                ebd = new EntityBehaviorDictionary(behavior.Name);
                _entityBehaviors.Add(behavior.Name, ebd);
            }
            ebd.Add(behavior.GetType(), behavior);

            // Track lists
            foreach (var pair in _behaviorLists)
            {
                if (ebd.TryGetValue(pair.Key, out var b) && b == behavior)
                {
                    pair.Value.Add(b);
                }
            }
        }
コード例 #2
0
ファイル: BehaviorPool.cs プロジェクト: slicol/SpiceSharp
        /// <summary>
        /// Add a behavior to the collection
        /// </summary>
        /// <param name="creator">Name of the entity creating the behavior</param>
        /// <param name="behavior">Created behavior</param>
        public void Add(Identifier creator, Behavior behavior)
        {
            if (!_entityBehaviors.TryGetValue(creator, out var eb))
            {
                eb = new EntityBehaviorDictionary(creator);
                _entityBehaviors.Add(creator, eb);
            }
            eb.Register(behavior);

            // Store in the behavior list
            Type basetype = behavior.GetType().BaseType ?? throw new CircuitException("Invalid behavior");

            if (!_behaviors.TryGetValue(basetype, out var list))
            {
                list = new List <Behavior>();
                _behaviors.Add(basetype, list);
            }
            list.Add(behavior);
        }
コード例 #3
0
ファイル: BehaviorPool.cs プロジェクト: jeason1997/SpiceSharp
        /// <summary>
        /// Adds the specified behavior to the pool.
        /// </summary>
        /// <param name="type">The type of the requested behavior.</param>
        /// <param name="creator">The entity identifier to which the .</param>
        /// <param name="behavior">The behavior to be added.</param>
        /// <exception cref="SpiceSharp.CircuitException">Invalid behavior</exception>
        public void Add(Type type, string creator, IBehavior behavior)
        {
            // Create the list entry if necessary
            if (!_behaviors.TryGetValue(type, out var behaviorList))
            {
                behaviorList = new List <IBehavior>();
                _behaviors.Add(type, behaviorList);
            }

            // Find the entity behaviors
            if (!_entityBehaviors.TryGetValue(behavior.Name, out var ebd))
            {
                ebd = new EntityBehaviorDictionary(behavior.Name);
                _entityBehaviors.Add(behavior.Name, ebd);
            }

            // Add the behavior
            ebd.Add(behavior.GetType(), behavior);
            behaviorList.Add(behavior);
        }
コード例 #4
0
ファイル: BehaviorPool.cs プロジェクト: ewiebe1/SpiceSharp
 /// <summary>
 /// Tries to the get the entity behaviors by a specified identifier.
 /// </summary>
 /// <param name="name">The identifier.</param>
 /// <param name="ebd">The dictionary of entity behaviors.</param>
 /// <returns></returns>
 public bool TryGetBehaviors(string name, out EntityBehaviorDictionary ebd) =>
 _entityBehaviors.TryGetValue(name, out ebd);
コード例 #5
0
 /// <summary>
 /// Add entity behaviors
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="behaviors">Entity behaviors</param>
 public void Add(string name, EntityBehaviorDictionary behaviors) => _entityBehaviors.Add(name, behaviors);