Beispiel #1
0
        public void InitBasicGraph(VSGraphModel graph)
        {
            Stencil stencil = graph.Stencil;

            AssetDatabase.SaveAssets();

            var method = graph.CreateFunction("method", Vector2.left * 200);

            method.CreateFunctionVariableDeclaration("l", typeof(int).GenerateTypeHandle(stencil));
            method.CreateFunctionParameterDeclaration("a", typeof(int).GenerateTypeHandle(stencil));

            var log = method.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true));
            var abs = graph.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Mathf), "Abs", true), new Vector2(-350, 100));

            graph.CreateEdge(log.GetParameterPorts().First(), abs.OutputPort);

            var xDecl  = graph.CreateGraphVariableDeclaration("x", typeof(float).GenerateTypeHandle(stencil), true);
            var xUsage = graph.CreateVariableNode(xDecl, new Vector2(-450, 100));

            graph.CreateEdge(abs.GetParameterPorts().First(), xUsage.OutputPort);

            var stack001 = graph.CreateStack(string.Empty, new Vector2(-200, 300));

            stack001.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), "Log", true));

            var method2 = graph.CreateFunction("method2", Vector2.left * 800);

            method2.CreateFunctionRefCallNode(method);
        }
        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);
        }
        static State MergeStack(State previousState, MergeStackAction action)
        {
            VSGraphModel graphModel  = (VSGraphModel)previousState.CurrentGraphModel;
            var          stackModelA = (StackBaseModel)action.StackModelA;
            var          stackModelB = (StackBaseModel)action.StackModelB;

            Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Move stacked nodes");
            // Move all nodes from stackB to stackA
            stackModelA.MoveStackedNodes(stackModelB.NodeModels.ToList(), -1, false);

            // Move output connections of stackB to stackA
            var previousEdgeConnections = graphModel.GetEdgesConnections(stackModelB.OutputPorts.First()).ToList();

            foreach (var edge in previousEdgeConnections)
            {
                graphModel.CreateEdge(edge.InputPortModel, stackModelA.OutputPorts.First());
            }

            // Delete stackB
            graphModel.DeleteNode(stackModelB, GraphModel.DeleteConnections.True);

            previousState.MarkForUpdate(UpdateFlags.GraphTopology);

            return(previousState);
        }
        static State SplitStack(State previousState, SplitStackAction action)
        {
            VSGraphModel graphModel = (VSGraphModel)previousState.CurrentGraphModel;

            Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Move stacked nodes");

            if (action.SplitIndex > 0 && action.SplitIndex < action.StackModel.NodeModels.Count())
            {
                // Get the list of nodes to move to another stack.
                var nodeModels = action.StackModel.NodeModels.Skip(action.SplitIndex).ToList();
                if (nodeModels.Any())
                {
                    // Get old stack (stack A)
                    var stackA = action.StackModel;

                    // Create new stack (stack B).
                    var stackB = graphModel.CreateStack(((NodeModel)stackA).Title + "_split", stackA.Position + Vector2.up * 300);

                    // Move the list of nodes to this new stack.
                    stackB.MoveStackedNodes(nodeModels, 0);

                    // if the stack had a condition node or anything providing the actual port models, we need to move
                    // the nodes BEFORE fetching the port models, as stack.portModels will actually return the condition
                    // port models
                    var stackAOutputPortModel = stackA.OutputPorts.First();
                    var stackBInputPortModel  = stackB.InputPorts.First();
                    var stackBOutputPortModel = stackB.OutputPorts.First();

                    // Connect the edges that were connected to the old stack to the new one.
                    var previousEdgeConnections = graphModel.GetEdgesConnections(stackAOutputPortModel).ToList();
                    foreach (var edge in previousEdgeConnections)
                    {
                        graphModel.CreateEdge(edge.InputPortModel, stackBOutputPortModel);
                        graphModel.DeleteEdge(edge);
                    }

                    // Connect the new stack with the old one.
                    IEdgeModel newEdge = graphModel.CreateEdge(stackBInputPortModel, stackAOutputPortModel);

                    graphModel.LastChanges.ChangedElements.Add(stackA);
                    graphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                }
            }

            return(previousState);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public void InitBasicGraph(VSGraphModel graphModel)
        {
            var query         = graphModel.CreateQueryFromGameObject(GameObject);
            var groupInstance = graphModel.CreateVariableNode(query, m_Position);
            var node          = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", m_Position + k_GroupOffset);

            graphModel.CreateEdge(node.InstancePort, groupInstance.OutputPort);
        }
        static void CreateUpdateAndLogEntity(VSGraphModel graphModel, IVariableModel variable)
        {
            // update entities
            var update = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

            graphModel.CreateEdge(update.InstancePort, variable.OutputPort);

            // Create entity from update
            var entity = graphModel.CreateVariableNode(
                update.FunctionParameterModels.Single(
                    p => p.DataType == typeof(Entity).GenerateTypeHandle(graphModel.Stencil)),
                Vector2.zero);

            // Log the entity
            var log = update.CreateFunctionCallNode(typeof(Debug).GetMethod("Log", new[] { typeof(object) }), 0);

            graphModel.CreateEdge(log.GetParameterPorts().First(), entity.OutputPort);
        }
Beispiel #8
0
        static OnUpdateEntitiesNodeModel CreateOnUpdateAndConnectGroup(VSGraphModel graphModel, IVariableDeclarationModel group)
        {
            var groupInstance    = graphModel.CreateVariableNode(group, Vector2.zero);
            var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

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

            return(onUpdateEntities);
        }
Beispiel #9
0
        static OnUpdateEntitiesNodeModel CreateOnUpdateAndConnectQuery(VSGraphModel graphModel, IVariableDeclarationModel query)
        {
            var queryInstance    = graphModel.CreateVariableNode(query, Vector2.zero);
            var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

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

            return(onUpdateEntities);
        }
Beispiel #10
0
        static void AddSharedComponentIfCriteriaMatch(VSGraphModel graphModel, FunctionModel onUpdateEntities)
        {
            var entityInstance = graphModel.CreateVariableNode(
                onUpdateEntities.FunctionParameterModels.Single(
                    p => p.DataType == typeof(Entity).GenerateTypeHandle(graphModel.Stencil)
                    ),
                Vector2.zero);
            var addComponent = onUpdateEntities.CreateStackedNode <AddComponentNodeModel>("add");

            addComponent.ComponentType = typeof(DummySharedComponent).GenerateTypeHandle(graphModel.Stencil);
            graphModel.CreateEdge(addComponent.EntityPort, entityInstance.OutputPort);
            addComponent.DefineNode();
        }
        static AddComponentNodeModel CreateAddComponentInGraph(
            VSGraphModel graphModel,
            IVariableDeclarationModel group,
            Type componentToAdd)
        {
            var groupInstance    = graphModel.CreateVariableNode(group, Vector2.zero);
            var onUpdateEntities = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("update", Vector2.zero);

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

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

            var addComponent = onUpdateEntities.CreateStackedNode <AddComponentNodeModel>("add");

            addComponent.ComponentType = componentToAdd.GenerateTypeHandle(graphModel.Stencil);

            graphModel.CreateEdge(addComponent.EntityPort, entityInstance.OutputPort);

            return(addComponent);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        static State CreateLogNode(State previousState, CreateLogNodeAction action)
        {
            VSGraphModel graphModel   = (VSGraphModel)previousState.CurrentGraphModel;
            var          stackModel   = (StackBaseModel)action.StackModel;
            var          functionNode = stackModel.CreateStackedNode <LogNodeModel>(LogNodeModel.NodeTitle);

            functionNode.LogType = action.LogType;

            IConstantNodeModel constantNode = graphModel.CreateConstantNode(
                "",
                typeof(string).GenerateTypeHandle(graphModel.Stencil),
                functionNode.Position - k_StackedTestNodesTokenOffset);

            ((ConstantNodeModel <string>)constantNode).value = $"{graphModel.NodeModels.Count}";
            graphModel.CreateEdge(functionNode.InputPort, constantNode.OutputPort);

            return(previousState);
        }
        static State CreateLogNode(State previousState, CreateLogNodeAction action)
        {
            VSGraphModel graphModel   = (VSGraphModel)previousState.CurrentGraphModel;
            var          stackModel   = (StackBaseModel)action.StackModel;
            var          functionNode = stackModel.CreateStackedNode <LogNodeModel>(LogNodeModel.NodeTitle);

            functionNode.LogType = action.LogType;

            IConstantNodeModel constantNode = graphModel.CreateConstantNode(
                "",
                typeof(int).GenerateTypeHandle(graphModel.Stencil),
                stackModel.Position - k_StackedTestNodesTokenOffset);

            ((ConstantNodeModel <int>)constantNode).value = graphModel.NodeModels.Count;
            var edge = graphModel.CreateEdge(functionNode.InputPort, constantNode.OutputPort);

            graphModel.LastChanges.ModelsToAutoAlign.Add(edge);

            return(previousState);
        }