コード例 #1
0
        public static EntityComponentData Parse(string component)
        {
            EntityComponentData data = new EntityComponentData();

            data.name      = component.Split(':')[0];
            data.threshold = float.Parse(component.Split(':')[1]);

            return(data);
        }
コード例 #2
0
        public void UnBindData()
        {
            this.data = null;

            AttributeBox box = this.holder.owner.data.attributeBox;

            if (componentAttributeFormulas.ContainsKey(type))
            {
                componentAttributeFormulas[type].Value(box);
            }
        }
コード例 #3
0
        public void BindData(EntityComponentData data)
        {
            this.data = data;

            AttributeBox box = this.holder.owner.data.attributeBox;

            if (componentAttributeFormulas.ContainsKey(type))
            {
                componentAttributeFormulas[type].Key(box);
            }
        }
コード例 #4
0
        /// <summary>
        ///   Adds the matching Unity component to the game object that represents
        ///   the entity with the passed id.
        /// </summary>
        /// <param name="e"> Game event that has occurred. </param>
        private void OnComponentAdded(GameEvent e)
        {
            Profiler.BeginSample("Component added");

            EntityComponentData eventArgs = (EntityComponentData)e.EventData;
            int entityId = eventArgs.EntityId;
            IEntityComponent component    = eventArgs.Component;
            GameObject       entityObject = this.entities[entityId];

            // Check if a behaviour has to be attached which visualizes the logic state.
            foreach (LogicToVisualMapping logicToVisualMapping in
                     this.logicVisualMappings.Where(mapping => mapping.LogicType == component.GetType()))
            {
                // NOTE: The component may already exist because we recycle existing entity objects and the old components
                // just get removed after the current update loop (see http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html).
                entityObject.AddComponent(logicToVisualMapping.VisualType);
            }

            Profiler.EndSample();
        }
コード例 #5
0
        private void OnComponentRemoved(GameEvent e)
        {
            EntityComponentData eventArgs = (EntityComponentData)e.EventData;
            int entityId = eventArgs.EntityId;
            IEntityComponent component    = eventArgs.Component;
            GameObject       entityObject = this.entities[entityId];

            // Check if a behaviour has to be removed which visualizes the logic state.
            foreach (LogicToVisualMapping logicToVisualMapping in this.logicVisualMappings)
            {
                if (component.GetType() != logicToVisualMapping.LogicType)
                {
                    continue;
                }

                Component visualComponent = entityObject.GetComponent(logicToVisualMapping.VisualType);
                if (visualComponent != null)
                {
                    Destroy(visualComponent);
                }
                break;
            }
        }
コード例 #6
0
        /// <summary>
        ///   Called when a component has been removed.
        /// </summary>
        /// <param name="e"> Event that has occurred within the framework. </param>
        private void OnComponentRemoved(GameEvent e)
        {
            EntityComponentData data = (EntityComponentData)e.EventData;

            this.testPassed = data.EntityId == this.testEntityId && this.entityComponent.Equals(data.Component);
        }