コード例 #1
0
        /*
         * Implementation
         */

        private EntityRef createEntityRef(int entityId)
        {
            if (entityId == NULL_ID)
            {
                return(EntityRef.NULL);
            }
            BaseEntityRef existing = entityCache[entityId];

            if (existing != null)
            {
                return(existing);
            }
            BaseEntityRef newRef = refStrategy.createRefFor(entityId, this);

            entityCache[entityId] = newRef;
            return(newRef);
        }
コード例 #2
0
        private EntityRef createEntity(IEnumerable <Component> components)
        {
            int entityId = createEntity();

            Prefab prefab = null;

            foreach (Component component in components)
            {
                if (component is EntityInfoComponent)
                {
                    EntityInfoComponent comp = (EntityInfoComponent)component;
                    prefab = prefabManager.getPrefab(comp.parentPrefab);
                    break;
                }
            }

            IEnumerable <Component> finalComponents;

            if (eventSystem != null)
            {
                BeforeEntityCreated @event  = new BeforeEntityCreated(prefab, components);
                BaseEntityRef       tempRef = refStrategy.createRefFor(entityId, this);
                eventSystem.send(tempRef, @event);
                tempRef.invalidate();
                finalComponents = @event.ResultComponents;
            }
            else
            {
                finalComponents = components;
            }

            foreach (Component c in finalComponents)
            {
                store.put(entityId, c);
            }
            return(createEntityRef(entityId));
        }