Esempio n. 1
0
        /// <summary>
        ///     Adds a SpatialOS component to the EntityTemplate with write permissions specified.
        /// </summary>
        /// <param name="snapshot">The component snapshot to add.</param>
        /// <param name="writeAccess">
        ///     The worker attribute that should be granted write access over the given component.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///     Thrown if the EntityTemplate already contains a component snapshot with the same component ID.
        /// </exception>
        /// <remarks>
        ///     EntityACL is handled automatically by the EntityTemplate, so a EntityACL snapshot will be ignored.
        /// </remarks>
        public void AddComponent(ISpatialComponentSnapshot snapshot, string writeAccess)
        {
            AddComponent(snapshot);

            if (snapshot.ComponentId != EntityAclComponentId)
            {
                acl.SetComponentWriteAccess(snapshot.ComponentId, writeAccess);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Adds a SpatialOS component to the Entity Template.
        /// </summary>
        /// <param name="snapshot">The component snapshot to add.</param>
        /// <exception cref="InvalidOperationException">
        ///     Thrown if the EntityTemplate already contains a component snapshot with the same component ID.
        /// </exception>
        /// <remarks>
        ///     EntityACL is handled automatically by the EntityTemplate, so a EntityACL snapshot will be ignored.
        /// </remarks>
        public void AddComponent(ISpatialComponentSnapshot snapshot)
        {
            if (snapshot.ComponentId == EntityAclComponentId)
            {
                // ACL handled automatically.
                return;
            }

            if (entityData.ContainsKey(snapshot.ComponentId))
            {
                throw new InvalidOperationException(
                          "Cannot add multiple components of the same type to the same entity. " +
                          $"Attempted to add componentId: {snapshot.ComponentId} more than once.");
            }

            entityData.Add(snapshot.ComponentId, snapshot);
        }
Esempio n. 3
0
 /// <summary>
 ///     Sets a component snapshot in the EntityTemplate.
 /// </summary>
 /// <param name="snapshot">The component snapshot that will be inserted into the EntityTemplate.</param>
 /// <remarks>
 ///     This will override the component snapshot in the EntityTemplate if one already exists.
 /// </remarks>
 public void SetComponent(ISpatialComponentSnapshot snapshot)
 {
     entityData[snapshot.ComponentId] = snapshot;
 }
Esempio n. 4
0
 /// <summary>Gets the component with the associated component ID.</summary>
 /// <param name="componentId">The ID of the component to get.</param>
 /// <param name="component">
 ///     When this method returns, contains the component, if the component is found; otherwise null. This parameter is passed uninitialized.
 /// </param>
 /// <returns>
 ///     True if this contains a component with the associated component ID; otherwise, false.
 /// </returns>
 public bool TryGetComponent(uint componentId, out ISpatialComponentSnapshot component)
 {
     return(entityData.TryGetValue(componentId, out component));
 }