예제 #1
0
        public static void BlueprintComponentsField(
            Blueprint blueprint,
            IAttributeTable configuration,
            InspectorTypeTable inspectorTypeTable,
            IBlueprintManager blueprintManager)
        {
            // Compute maximum label width.
            float maxLabelWidth = 0;

            foreach (var componentType in blueprint.GetAllComponentTypes())
            {
                var inspectorType = inspectorTypeTable[componentType];
                foreach (var componentProperty in inspectorType.Properties)
                {
                    var textDimensions = GUI.skin.label.CalcSize(new GUIContent(componentProperty.Name));
                    maxLabelWidth = MathUtils.Max(textDimensions.x, maxLabelWidth);
                }
            }
            EditorGUIUtility.labelWidth = maxLabelWidth;

            foreach (var componentType in blueprint.GetAllComponentTypes())
            {
                var inspectorType = inspectorTypeTable[componentType];

                // Draw inspector.
                AttributeTableField(inspectorType, configuration, inspectorTypeTable, blueprintManager);
            }
        }
예제 #2
0
        /// <summary>
        ///   Initializes the specified entity, adding components matching the
        ///   passed blueprint and initializing these with the data stored in
        ///   the blueprint and the specified configuration. Configuration
        ///   data is preferred over blueprint data.
        /// </summary>
        /// <param name="entityId">Id of the entity to initialize.</param>
        /// <param name="blueprint"> Blueprint describing the entity to create. </param>
        /// <param name="configuration"> Data for initializing the entity. </param>
        /// <param name="additionalComponents">Components to add to the entity, in addition to the ones specified by the blueprint.</param>
        public void InitEntity(
            int entityId,
            Blueprint blueprint,
            IAttributeTable configuration,
            IEnumerable <Type> additionalComponents)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException("blueprint", "Blueprint is null.");
            }

            // Setup attribute table.
            HierarchicalAttributeTable attributeTable = new HierarchicalAttributeTable();

            if (configuration != null)
            {
                attributeTable.AddParent(configuration);
            }

            // Add attribute tables of all ancestors.
            IAttributeTable blueprintAttributeTable = blueprint.GetAttributeTable();

            if (blueprintAttributeTable != null)
            {
                attributeTable.AddParent(blueprintAttributeTable);
            }

            // Build list of components to add.
            IEnumerable <Type> blueprintComponentTypes = blueprint.GetAllComponentTypes();
            IEnumerable <Type> componentTypes          = additionalComponents != null
                ? blueprintComponentTypes.Union(additionalComponents)
                : blueprintComponentTypes;

            // Add components.
            foreach (Type type in componentTypes)
            {
                this.AddComponent(type, entityId, attributeTable);
            }

            // Raise event.
            this.OnEntityInitialized(entityId);
        }