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);
        }
Пример #2
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);
        }
        static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);

                    IVariableModel newVariable = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }
                }
            }

            return(previousState);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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));
 }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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();
        }
Пример #10
0
        static void CreateItemizedNode(State state, VSGraphModel graphModel, ref IPortModel outputPortModel)
        {
            ItemizeOptions currentItemizeOptions = state.Preferences.CurrentItemizeOptions;

            // automatically itemize, i.e. duplicate variables as they get connected
            if (outputPortModel.Connected && currentItemizeOptions != ItemizeOptions.Nothing)
            {
                var nodeToConnect = outputPortModel.NodeModel;
                var offset        = Vector2.up * k_NodeOffset;

                if (currentItemizeOptions.HasFlag(ItemizeOptions.Constants) &&
                    nodeToConnect is ConstantNodeModel constantModel)
                {
                    string newName = string.IsNullOrEmpty(constantModel.Title)
                        ? "Temporary"
                        : constantModel.Title + "Copy";
                    nodeToConnect = graphModel.CreateConstantNode(
                        newName,
                        constantModel.Type.GenerateTypeHandle(graphModel.Stencil),
                        constantModel.Position + offset
                        );
                    ((ConstantNodeModel)nodeToConnect).ObjectValue = constantModel.ObjectValue;
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.Variables) &&
                         nodeToConnect is VariableNodeModel variableModel)
                {
                    nodeToConnect = graphModel.CreateVariableNode(variableModel.DeclarationModel,
                                                                  variableModel.Position + offset);
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.Variables) &&
                         nodeToConnect is ThisNodeModel thisModel)
                {
                    nodeToConnect = graphModel.CreateNode <ThisNodeModel>("this", thisModel.Position + offset);
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.SystemConstants) &&
                         nodeToConnect is SystemConstantNodeModel sysConstModel)
                {
                    Action <SystemConstantNodeModel> preDefineSetup = m =>
                    {
                        m.ReturnType    = sysConstModel.ReturnType;
                        m.DeclaringType = sysConstModel.DeclaringType;
                        m.Identifier    = sysConstModel.Identifier;
                    };
                    nodeToConnect = graphModel.CreateNode(sysConstModel.Title, sysConstModel.Position + offset, SpawnFlags.Default, preDefineSetup);
                }

                outputPortModel = nodeToConnect.OutputsById[outputPortModel.UniqueId];
            }
        }
        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);
        }
Пример #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);
        }
Пример #13
0
        static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                bool needToGroup = action.GroupModel != null;
                List <INodeModel> nodesToGroup = needToGroup ? new List <INodeModel>(action.VariablesToCreate.Count) : null;

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel   vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);
                    IVariableModel newVariable  = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }

                    if (needToGroup)
                    {
                        nodesToGroup.Add(newVariable);
                    }
                }

                if (needToGroup)
                {
                    GroupNodeModel.Ungroup(nodesToGroup);

                    ((GroupNodeModel)action.GroupModel).AddNodes(nodesToGroup);
                }
            }

            return(previousState);
        }
        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);
        }
 public static void CreateVariablesFromGameObjects(VSGraphModel graph, ScriptingGraphAuthoring authoringComponent, IEnumerable <GameObject> gameObjects, Vector2 position, bool actionSmartObjects)
 {
     foreach (var obj in gameObjects)
     {
         var decl = graph.CreateGraphVariableDeclaration(obj.name, TypeHandle.GameObject, true);
         decl.MakeObjectReference();
         ScriptingGraphAuthoring scriptingGraphAuthoring = null;
         if (actionSmartObjects && (scriptingGraphAuthoring = obj.GetComponent <ScriptingGraphAuthoring>()))
         {
             decl.MakeSmartObject();
         }
         var variableNode = graph.CreateVariableNode(decl, position);
         if (scriptingGraphAuthoring != null)
         {
             var path = AssetDatabase.GetAssetPath(scriptingGraphAuthoring.ScriptingGraph);
             var referencedAssetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(path);
             ((SmartObjectReferenceNodeModel)variableNode).GraphReference = referencedAssetModel;
         }
         ScriptingGraphAuthoringEditor.BindInput(authoringComponent, decl, obj);
         position += new Vector2(20, 25);
     }
 }
Пример #16
0
        public static List <NodeModel> SpawnAllNodeModelsInGraph(VSGraphModel graphModel)
        {
            List <NodeModel>          spawnedNodes = new List <NodeModel>();
            Stencil                   stencil      = graphModel.Stencil;
            StackModel                stack;
            FunctionModel             funcModel;
            OnUpdateEntitiesNodeModel onUpdateModel;

            //--Floating Nodes--

            //Stack-Derived NodeModels
            spawnedNodes.Add(stack         = graphModel.CreateNode <StackModel>("StackModel"));
            spawnedNodes.Add(funcModel     = graphModel.CreateNode <FunctionModel>("FunctionModel"));
            spawnedNodes.Add(onUpdateModel = graphModel.CreateNode <OnUpdateEntitiesNodeModel>("OnUpdateEntitiesNodeModel"));

            var methodInfo = TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true);

            spawnedNodes.Add(graphModel.CreateEventFunction(methodInfo, Vector2.zero));
            spawnedNodes.Add(graphModel.CreateNode <OnEndEntitiesNodeModel>("OnEndEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <OnEventNodeModel>("OnEventNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <OnStartEntitiesNodeModel>("OnStartEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <PostUpdate>("PostUpdate"));
            spawnedNodes.Add(graphModel.CreateNode <PreUpdate>("PreUpdate"));
            spawnedNodes.Add(graphModel.CreateNode <KeyDownEventModel>("KeyDownEventModel"));
            spawnedNodes.Add(graphModel.CreateNode <CountEntitiesNodeModel>("CountEntitiesNodeModel"));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(ForEachHeaderModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(WhileHeaderModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(ForAllEntitiesStackModel), Vector2.zero));
            spawnedNodes.Add(graphModel.CreateLoopStack(typeof(CoroutineStackModel), Vector2.zero));

            //Constant-typed NodeModels
            spawnedNodes.Add(graphModel.CreateNode <BooleanConstantNodeModel>("BooleanConstantNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <ColorConstantModel>("ColorConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <CurveConstantNodeModel>("CurveConstantNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <DoubleConstantModel>("DoubleConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <EnumConstantNodeModel>("EnumConstantNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <FloatConstantModel>("FloatConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <GetPropertyGroupNodeModel>("GetPropertyGroupNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <InputConstantModel>("InputConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <IntConstantModel>("IntConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <LayerConstantModel>("LayerConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <LayerMaskConstantModel>("LayerMaskConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <ObjectConstantModel>("ObjectConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <QuaternionConstantModel>("QuaternionConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <StringConstantModel>("StringConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <TagConstantModel>("TagConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <Vector2ConstantModel>("Vector2ConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <Vector3ConstantModel>("Vector3ConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <Vector4ConstantModel>("Vector4ConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <ConstantSceneAssetNodeModel>("ConstantSceneAssetNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <Float2ConstantModel>("Float2ConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <Float3ConstantModel>("Float3ConstantModel"));
            spawnedNodes.Add(graphModel.CreateNode <Float4ConstantModel>("Float4ConstantModel"));

            //Misc
            void DefineSystemConstant(SystemConstantNodeModel m)
            {
                m.ReturnType    = typeof(float).GenerateTypeHandle(stencil);
                m.DeclaringType = typeof(Mathf).GenerateTypeHandle(stencil);
                m.Identifier    = "PI";
            }

            spawnedNodes.Add(graphModel.CreateNode <SystemConstantNodeModel>("SystemConstantNodeModel", Vector2.zero, SpawnFlags.Default, DefineSystemConstant));
            spawnedNodes.Add(graphModel.CreateNode <GetInputNodeModel>("GetInputNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <GetOrCreateComponentNodeModel>("GetOrCreateComponentNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <GetSingletonNodeModel>("GetSingletonNodeModel"));
            spawnedNodes.Add(graphModel.CreateNode <ThisNodeModel>("ThisNodeModel"));
            VariableDeclarationModel decl = graphModel.CreateGraphVariableDeclaration("MyVariableName", typeof(int).GenerateTypeHandle(graphModel.Stencil), true);

            spawnedNodes.Add((NodeModel)graphModel.CreateVariableNode(decl, Vector2.zero));
            spawnedNodes.Add(graphModel.CreateNode <MacroRefNodeModel>("MacroRefNodeModel"));
            spawnedNodes.Add(graphModel.CreateInlineExpressionNode("2+2", Vector2.zero));
            spawnedNodes.Add(graphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero));
            spawnedNodes.Add(graphModel.CreateUnaryOperatorNode(UnaryOperatorKind.PostIncrement, Vector2.zero));

            //--Stack-Contained Nodes--
            spawnedNodes.Add(stack.CreateStackedNode <AddComponentNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <DestroyEntityNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <ForAllEntitiesNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <ForEachNodeModel>());
            spawnedNodes.Add(stack.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true)));
            spawnedNodes.Add(stack.CreateFunctionRefCallNode(funcModel));
            spawnedNodes.Add(stack.CreateStackedNode <InstantiateNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <CreateEntityNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <IfConditionNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <LogNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <RemoveComponentNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <SetComponentNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <SetPositionNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <SetRotationNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <WhileNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <SetPropertyGroupNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <SetVariableNodeModel>());
            spawnedNodes.Add(stack.CreateStackedNode <CoroutineNodeModel>());
            spawnedNodes.Add(funcModel.CreateStackedNode <ReturnNodeModel>());

            TypeHandle eventTypeHandle = typeof(DummyEvent).GenerateTypeHandle(stencil);

            spawnedNodes.Add(onUpdateModel.CreateStackedNode <SendEventNodeModel>("SendEventNodeModel", 0, SpawnFlags.Default, n => n.EventType = eventTypeHandle));

            return(spawnedNodes);
        }