void PrepareGraph(VSGraphModel graphModel)
        {
            var entityTypeHandle = typeof(Entity).GenerateTypeHandle(graphModel.Stencil);

            // Component creation
            var scale = typeof(Scale).GenerateTypeHandle(Stencil);
            var group = graphModel.CreateComponentQuery("g");

            group.AddComponent(graphModel.Stencil, scale, ComponentDefinitionFlags.None);


            // On update
            var groupInstance = graphModel.CreateVariableNode(group, Vector2.zero);

            m_OnUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);
            graphModel.CreateEdge(m_OnUpdateEntities.InstancePort, groupInstance.OutputPort);

            m_CreateEntityModel = m_OnUpdateEntities.CreateStackedNode <CreateEntityNodeModel>("instantiate");

            // Variable containing the new entity
            m_OnUpdateEntities.CreateFunctionVariableDeclaration("newEntity", entityTypeHandle);
            m_NewEntityVariable = graphModel.CreateVariableNode(
                m_OnUpdateEntities.FunctionParameterModels.Single(p => p.DataType == entityTypeHandle),
                Vector2.zero);

            m_FloatConstantNode       = (FloatConstantModel)graphModel.CreateConstantNode("float", TypeHandle.Float, Vector2.zero);
            m_FloatConstantNode.value = 10f;

            graphModel.CreateEdge(m_CreateEntityModel.InstancePort, m_NewEntityVariable.OutputPort);
        }
Ejemplo n.º 2
0
        static State CreateComponentQuery(State previousState, CreateComponentQueryAction action)
        {
            VSGraphModel graphModel = GetCurrentGraphModel(previousState);

            Undo.RegisterCompleteObjectUndo(graphModel, "Create Component Query");
            graphModel.CreateComponentQuery(action.QueryName);
            return(previousState);
        }
Ejemplo n.º 3
0
        public void InitBasicGraph(VSGraphModel graphModel)
        {
            var query         = graphModel.CreateComponentQuery("myQuery");
            var node          = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("On Update Entities", Vector2.zero);
            var queryInstance = graphModel.CreateVariableNode(query, new Vector2(-145, 8));

            graphModel.CreateEdge(node.InstancePort, queryInstance.OutputPort);
        }
Ejemplo n.º 4
0
 protected IVariableModel SetupQuery(VSGraphModel graph, string name, IEnumerable <Type> components, out ComponentQueryDeclarationModel query)
 {
     query = graph.CreateComponentQuery(name);
     foreach (var component in components)
     {
         query.AddComponent(Stencil, component.GenerateTypeHandle(Stencil), ComponentDefinitionFlags.None);
     }
     return(graph.CreateVariableNode(query, Vector2.zero));
 }
Ejemplo n.º 5
0
        public static ComponentQueryDeclarationModel CreateQueryFromGameObject(this VSGraphModel graphModel, GameObject gameObject)
        {
            EcsStencil stencil = graphModel.Stencil as EcsStencil;

            string queryName = gameObject.name + " Query";

            List <TypeHandle> componentTypes = stencil.GetEcsComponentsForGameObject(gameObject);

            AddConvertToEntityComponentIfNeeded(gameObject);

            return(graphModel.CreateComponentQuery(queryName, componentTypes));
        }
Ejemplo n.º 6
0
        static ComponentQueryDeclarationModel CreateComponentQuery(VSGraphModel graphModel, params Type[] types)
        {
            var group = graphModel.CreateComponentQuery("g");

            foreach (var type in types)
            {
                var handle = type.GenerateTypeHandle(graphModel.Stencil);
                group.AddComponent(graphModel.Stencil, handle, ComponentDefinitionFlags.None);
            }

            return(group);
        }
Ejemplo n.º 7
0
        static ComponentQueryDeclarationModel CreateComponentGroup(this VSGraphModel graphModel, string queryName, IEnumerable <TypeHandle> componentTypes)
        {
            Stencil stencil = graphModel.Stencil;

            string uniqueName = graphModel.GetUniqueName(queryName);

            ComponentQueryDeclarationModel field = graphModel.CreateComponentQuery(uniqueName);

            if (field != null)
            {
                foreach (TypeHandle typeHandle in componentTypes)
                {
                    field.AddComponent(stencil, typeHandle, ComponentDefinitionFlags.None);
                }

                if (componentTypes.Any())
                {
                    field.ExpandOnCreateUI = true;
                }
            }

            return(field);
        }
Ejemplo n.º 8
0
        static void CreateRemoveComponentInGraph(VSGraphModel graphModel, Type componentToRemove)
        {
            var component = componentToRemove.GenerateTypeHandle(graphModel.Stencil);
            var query     = graphModel.CreateComponentQuery("g");

            query.AddComponent(graphModel.Stencil, component, ComponentDefinitionFlags.None);

            var queryInstance    = graphModel.CreateVariableNode(query, Vector2.zero);
            var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

            graphModel.CreateEdge(onUpdateEntities.InstancePort, queryInstance.OutputPort);

            var entityInstance = graphModel.CreateVariableNode(
                onUpdateEntities.FunctionParameterModels.Single(
                    p => p.DataType == typeof(Entity).GenerateTypeHandle(graphModel.Stencil)
                    ),
                Vector2.zero);

            var removeComponent = onUpdateEntities.CreateStackedNode <RemoveComponentNodeModel>("remove");

            removeComponent.ComponentType = component;

            graphModel.CreateEdge(removeComponent.EntityPort, entityInstance.OutputPort);
        }